// musicPlayEmptyTest(): empty music @Test public void musicPlayEmptyTest() { SequencePlayer player; try { player = new SequencePlayer(140, 12); Music empty = new Parallel(new Rest(0), new Merge(new Rest(0), new Rest(0))); empty.play(player, 0); assertEquals("Meta event: END_OF_TRACK Tick: 0\n", player.toString()); } catch (MidiUnavailableException | InvalidMidiDataException e) { e.printStackTrace(); } }
// mergePlayEmptyTest(): m1 and/or m2 empty @Test public void mergePlayEmptyTest() { Merge a = new Merge(new Rest(0), new Rest(0)); try { SequencePlayer player = new SequencePlayer(140, 12); a.play(player, 0); assertEquals("Meta event: END_OF_TRACK Tick: 0\n", player.toString()); } catch (MidiUnavailableException mue) { mue.printStackTrace(); } catch (InvalidMidiDataException imde) { imde.printStackTrace(); } }
// musicPlaySingleNoteTest(): single note @Test public void musicPlaySingleNoteTest() { SequencePlayer player; try { player = new SequencePlayer(140, 12); Music a = new Note(1, new Pitch('A')); a.play(player, 0); assertEquals( "Event: NOTE_ON Pitch: 69 Tick: 0\n" + "Event: NOTE_OFF Pitch: 69 Tick: 12\n" + "Meta event: END_OF_TRACK Tick: 12\n", player.toString()); } catch (MidiUnavailableException | InvalidMidiDataException e) { e.printStackTrace(); } }
// parallelPlayEqualsTest(): m1 = m2 @Test public void parallelPlayEqualsTest() { Parallel a = new Parallel(new Note(1, new Pitch('C')), new Note(1, new Pitch('C'))); try { SequencePlayer player = new SequencePlayer(140, 12); a.play(player, 0); assertEquals( "Event: NOTE_ON Pitch: 60 Tick: 0\n" + "Event: NOTE_ON Pitch: 60 Tick: 0\n" + "Event: NOTE_OFF Pitch: 60 Tick: 12\n" + "Event: NOTE_OFF Pitch: 60 Tick: 12\n" + "Meta event: END_OF_TRACK Tick: 12\n", player.toString()); } catch (MidiUnavailableException mue) { mue.printStackTrace(); } catch (InvalidMidiDataException imde) { imde.printStackTrace(); } }
// chordPlayDifferentDurationsTest(): m1.duration != m2.duration @Test public void chordPlayDifferentDurationsTest() { Chord a = new Chord(new Note(1, new Pitch('D')), new Note(2, new Pitch('C'))); try { SequencePlayer player = new SequencePlayer(140, 12); a.play(player, 0); assertEquals( "Event: NOTE_ON Pitch: 62 Tick: 0\n" + "Event: NOTE_ON Pitch: 60 Tick: 0\n" + "Event: NOTE_OFF Pitch: 62 Tick: 12\n" + "Event: NOTE_OFF Pitch: 60 Tick: 24\n" + "Meta event: END_OF_TRACK Tick: 24\n", player.toString()); } catch (MidiUnavailableException mue) { mue.printStackTrace(); } catch (InvalidMidiDataException imde) { imde.printStackTrace(); } }
// notePlayTest(): covers all partitions @Test public void notePlayTest() { Note shortNote = new Note(.5, new Pitch('A')); Note highNote = new Note(20, new Pitch('A')).transpose(20); try { SequencePlayer player = new SequencePlayer(140, 12); shortNote.play(player, 0); highNote.play(player, .5); assertEquals( "Event: NOTE_ON Pitch: 69 Tick: 0\n" + "Event: NOTE_OFF Pitch: 69 Tick: 6\n" + "Event: NOTE_ON Pitch: 89 Tick: 6\n" + "Event: NOTE_OFF Pitch: 89 Tick: 246\n" + "Meta event: END_OF_TRACK Tick: 246\n", player.toString()); } catch (MidiUnavailableException mue) { mue.printStackTrace(); } catch (InvalidMidiDataException imde) { imde.printStackTrace(); } }