Skip to content

Commit

Permalink
- Add unit-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maezawa-akira committed Apr 10, 2018
1 parent f6de572 commit d7ef6ee
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/test_pretty_midi.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,20 +406,45 @@ def test_get_piano_roll_and_get_chroma():
inst.notes.append(pretty_midi.Note(pitch=45, velocity=100, start=0.1,
end=0.2))

inst = pretty_midi.Instrument(0)
pm.instruments.append(inst)
inst.control_changes.append(pretty_midi.ControlChange(number=64,
value=65,
time=0.38))
inst.control_changes.append(pretty_midi.ControlChange(number=64,
value=63,
time=0.5))
inst.notes.append(pretty_midi.Note(pitch=50, velocity=50, start=0.35,
end=0.4))
inst.notes.append(pretty_midi.Note(pitch=55, velocity=100, start=0.1,
end=0.42))

expected_piano_roll = np.zeros((128, 50))
expected_piano_roll[40, 5:35] = 100
expected_piano_roll[40, 35:45] = 150
expected_piano_roll[40, 45:] = 50
expected_piano_roll[45, 10:20] = 100
expected_piano_roll[50, 35:40] = 50
expected_piano_roll[55, 10:42] = 100
assert np.allclose(pm.get_piano_roll(), expected_piano_roll)

expected_piano_roll[50, 35:50] = 50
expected_piano_roll[55, 10:50] = 100
assert np.allclose(pm.get_piano_roll(use_pedal=True), expected_piano_roll)

expected_chroma = np.zeros((12, 50))
expected_chroma[4, 5:35] = 100
expected_chroma[4, 35:45] = 150
expected_chroma[4, 45:] = 50
expected_chroma[9, 10:20] = 100
expected_chroma[2, 35:40] = 50
expected_chroma[7, 10:42] = 100
assert np.allclose(pm.get_chroma(), expected_chroma)

expected_chroma[2, 35:50] = 50
expected_chroma[7, 10:50] = 100
assert np.allclose(pm.get_chroma(use_pedal=True), expected_chroma)


def test_synthesize():
pm = pretty_midi.PrettyMIDI()
Expand Down

0 comments on commit d7ef6ee

Please sign in to comment.