/** * Test case for the method printMeasures() which prints the all the measures currently in * Tablature. This method is tested by first switching the output stream to a file and then * asserting that the contents of the file are equal to the expected value. */ @Test public void testPrintMeasures() { try { PrintStream log = new PrintStream(new File("test files/tablature/printMeasures.txt")); System.setOut(log); String g = "||*-----<5>-----------<7>----------------------------*||"; test.addLineToLastMeasure(g); test.addLineToLastMeasure(g); test.addLineToLastMeasure(g); test.addLineToLastMeasure(g); test.addLineToLastMeasure(g); test.addLineToLastMeasure(g); test.printMeasures(); Scanner input = new Scanner(new File("test files/tablature/printMeasures.txt")); assertEquals(input.nextLine(), "Single"); assertEquals(input.nextLine(), g); assertEquals(input.nextLine(), g); assertEquals(input.nextLine(), g); assertEquals(input.nextLine(), g); assertEquals(input.nextLine(), g); assertEquals(input.nextLine(), g); input.close(); } catch (FileNotFoundException e) { } }
/** * Test case for the method addLineToLastMeasure(String g) which adds a string/line to the current * instance of tablature's last measure. This method is tested by asserting that each added line * to equal to the string in the last position of the tablature's measure */ @Test public void testAddLineToLastMeasure() { assertEquals(test.size(), 0); String g = "||*-----<5>-----------<7>----------------------------*||"; test.addLineToLastMeasure(g); assertEquals(test.getMeasures().get(0).getLines().get(0), g); g = "||*-----<5>-----------<1>----------------------------*||"; test.addLineToLastMeasure(g); assertEquals(test.getMeasures().get(0).getLines().get(1), g); g = "||*-----<5>-----------<3>----------------------------*||"; test.addLineToLastMeasure(g); assertEquals(test.getMeasures().get(0).getLines().get(2), g); g = "||*-----<5>-----------<9>----------------------------*||"; test.addLineToLastMeasure(g); assertEquals(test.getMeasures().get(0).getLines().get(3), g); g = "||*-----<5>-----------<5>----------------------------*||"; test.addLineToLastMeasure(g); assertEquals(test.getMeasures().get(0).getLines().get(4), g); g = "||*-----<5>-----------<6>----------------------------*||"; test.addLineToLastMeasure(g); assertEquals(test.getMeasures().get(0).getLines().get(5), g); g = "||*-----<5>-----------<8>----------------------------*||"; test.addLineToLastMeasure(g); assertEquals(test.getMeasures().get(1).getLines().get(0), g); }
/** * Test case for the size() method which returns the current number of measures in Tablature. This * method is tested by adding one measure to the tablature and then asserting the size is equal to * 1. Another measure is then added and the current size is asserted to be 2 */ @Test public void testSize() { assertEquals(test.size(), 0); String g = "||*-----<5>-----------<7>----------------------------*||"; test.addLineToLastMeasure(g); test.addLineToLastMeasure(g); test.addLineToLastMeasure(g); test.addLineToLastMeasure(g); test.addLineToLastMeasure(g); assertEquals(test.size(), 1); test.addLineToLastMeasure(g); test.addLineToLastMeasure(g); assertEquals(test.size(), 2); }
/** * Test case for the method getMeasures() which returns an arrayList of all the measures currently * in Tablature. This method is tested by iterating through the returned arrayList and asserting * that each element in the arrayList is equal to the expected value. */ @Test public void testGetMeasures() { String g = "||*-----<5>-----------<7>----------------------------*||"; test.addLineToLastMeasure(g); g = "||*-----<4>-----------<10>----------------------------*||"; test.addLineToLastMeasure(g); g = "||*-----<3>-----------<0>----------------------------*||"; test.addLineToLastMeasure(g); assertEquals( test.getMeasures().get(0).getLines().get(0), "||*-----<5>-----------<7>----------------------------*||"); assertEquals( test.getMeasures().get(0).getLines().get(1), "||*-----<4>-----------<10>----------------------------*||"); assertEquals( test.getMeasures().get(0).getLines().get(2), "||*-----<3>-----------<0>----------------------------*||"); }