Beispiel #1
0
class TestCallBack(unittest.TestCase):
    def setUp(self):
        self.staff = Staff()
        self.staff.addMeasure(Measure(16))
        self.calls = []
        def myCallBack(position):
            self.calls.append((position.measureIndex,
                               position.noteTime,
                               position.drumIndex))
        self.staff.setCallBack(myCallBack)

    def testAddNoteCallBack(self):
        np = NotePosition(measureIndex = 0, noteTime = 0, drumIndex = 0)
        self.staff.addNote(np, "x")
        self.assertEqual(len(self.calls), 1)
        self.assertEqual(self.calls[0], (0, 0, 0))
        self.staff.addNote(np, "x")
        self.assertEqual(len(self.calls), 1)
        self.staff.addNote(np, "o")
        self.assertEqual(len(self.calls), 2)
        self.assertEqual(self.calls[1], (0, 0, 0))

    def testDeleteNoteCallBack(self):
        np = NotePosition(measureIndex = 0, noteTime = 0, drumIndex = 0)
        self.staff.deleteNote(np)
        self.assertEqual(len(self.calls), 0)
        self.staff.addNote(np, "x")
        self.assertEqual(len(self.calls), 1)
        self.assertEqual(self.calls[0], (0, 0, 0))
        self.staff.deleteNote(np)
        self.assertEqual(len(self.calls), 2)
        self.assertEqual(self.calls[1], (0, 0, 0))

    def testToggleNoteCallBack(self):
        np = NotePosition(measureIndex = 0, noteTime = 0, drumIndex = 0)
        self.staff.toggleNote(np, "x")
        self.assertEqual(len(self.calls), 1)
        self.assertEqual(self.calls[0], (0, 0, 0))
        self.staff.toggleNote(np, "x")
        self.assertEqual(len(self.calls), 2)
        self.assertEqual(self.calls[1], (0, 0, 0))
        self.staff.toggleNote(np, "x")
        self.assertEqual(len(self.calls), 3)
        self.assertEqual(self.calls[2], (0, 0, 0))
        self.staff.toggleNote(np, "o")
        self.assertEqual(len(self.calls), 4)
        self.assertEqual(self.calls[2], (0, 0, 0))

    def testClearCallBack(self):
        self.staff.clearCallBack()
        self.staff.addNote(NotePosition(measureIndex = 0,
                                        noteTime = 0,
                                        drumIndex = 0), "x")
        self.assertEqual(len(self.calls), 0)

    def testAddMeasureCallBack(self):
        np = NotePosition(measureIndex = 1, noteTime = 0, drumIndex = 0)
        self.staff.addMeasure(Measure(16))
        self.staff.addNote(np, "x")
        self.assertEqual(len(self.calls), 1)
        self.assertEqual(self.calls[0], (1, 0, 0))

    def testDeleteMeasureCallBack(self):
        self.staff.addMeasure(Measure(16))
        self.staff.addMeasure(Measure(16))
        np = NotePosition(measureIndex = 1,
                          noteTime = 0,
                          drumIndex = 0)
        self.staff.addNote(np, "x")
        self.staff.deleteMeasure(NotePosition(measureIndex = 0))
        self.staff.deleteNote(NotePosition(measureIndex = 0,
                                           noteTime = 0,
                                           drumIndex = 0))
        self.staff.addNote(np, "x")
        self.assertEqual(len(self.calls), 3)
        self.assertEqual(self.calls[0], (1, 0, 0))
        self.assertEqual(self.calls[1], (0, 0, 0))
        self.assertEqual(self.calls[2], (1, 0, 0))

    def testInsertMeasureCallBack(self):
        np0 = NotePosition(measureIndex = 0,
                          noteTime = 0,
                          drumIndex = 0)
        np1 = NotePosition(measureIndex = 1,
                          noteTime = 0,
                          drumIndex = 0)
        self.staff.addNote(np0, "x")
        self.staff.insertMeasure(np0, Measure(8))
        self.staff.addNote(np0, "x")
        self.staff.deleteNote(np1)
        self.assertEqual(len(self.calls), 3)
        self.assertEqual(self.calls[0], (0, 0, 0))
        self.assertEqual(self.calls[1], (0, 0, 0))
        self.assertEqual(self.calls[2], (1, 0, 0))
Beispiel #2
0
class TestCallBack(unittest.TestCase):
    def setUp(self):
        self.staff = Staff()
        self.staff.addMeasure(Measure(16))
        self.calls = []

        def myCallBack(position):
            self.calls.append(
                (position.measureIndex, position.noteTime, position.drumIndex))

        self.staff.setCallBack(myCallBack)

    def testAddNoteCallBack(self):
        np = NotePosition(measureIndex=0, noteTime=0, drumIndex=0)
        self.staff.addNote(np, "x")
        self.assertEqual(len(self.calls), 1)
        self.assertEqual(self.calls[0], (0, 0, 0))
        self.staff.addNote(np, "x")
        self.assertEqual(len(self.calls), 1)
        self.staff.addNote(np, "o")
        self.assertEqual(len(self.calls), 2)
        self.assertEqual(self.calls[1], (0, 0, 0))

    def testDeleteNoteCallBack(self):
        np = NotePosition(measureIndex=0, noteTime=0, drumIndex=0)
        self.staff.deleteNote(np)
        self.assertEqual(len(self.calls), 0)
        self.staff.addNote(np, "x")
        self.assertEqual(len(self.calls), 1)
        self.assertEqual(self.calls[0], (0, 0, 0))
        self.staff.deleteNote(np)
        self.assertEqual(len(self.calls), 2)
        self.assertEqual(self.calls[1], (0, 0, 0))

    def testToggleNoteCallBack(self):
        np = NotePosition(measureIndex=0, noteTime=0, drumIndex=0)
        self.staff.toggleNote(np, "x")
        self.assertEqual(len(self.calls), 1)
        self.assertEqual(self.calls[0], (0, 0, 0))
        self.staff.toggleNote(np, "x")
        self.assertEqual(len(self.calls), 2)
        self.assertEqual(self.calls[1], (0, 0, 0))
        self.staff.toggleNote(np, "x")
        self.assertEqual(len(self.calls), 3)
        self.assertEqual(self.calls[2], (0, 0, 0))
        self.staff.toggleNote(np, "o")
        self.assertEqual(len(self.calls), 4)
        self.assertEqual(self.calls[2], (0, 0, 0))

    def testClearCallBack(self):
        self.staff.clearCallBack()
        self.staff.addNote(
            NotePosition(measureIndex=0, noteTime=0, drumIndex=0), "x")
        self.assertEqual(len(self.calls), 0)

    def testAddMeasureCallBack(self):
        np = NotePosition(measureIndex=1, noteTime=0, drumIndex=0)
        self.staff.addMeasure(Measure(16))
        self.staff.addNote(np, "x")
        self.assertEqual(len(self.calls), 1)
        self.assertEqual(self.calls[0], (1, 0, 0))

    def testDeleteMeasureCallBack(self):
        self.staff.addMeasure(Measure(16))
        self.staff.addMeasure(Measure(16))
        np = NotePosition(measureIndex=1, noteTime=0, drumIndex=0)
        self.staff.addNote(np, "x")
        self.staff.deleteMeasure(NotePosition(measureIndex=0))
        self.staff.deleteNote(
            NotePosition(measureIndex=0, noteTime=0, drumIndex=0))
        self.staff.addNote(np, "x")
        self.assertEqual(len(self.calls), 3)
        self.assertEqual(self.calls[0], (1, 0, 0))
        self.assertEqual(self.calls[1], (0, 0, 0))
        self.assertEqual(self.calls[2], (1, 0, 0))

    def testInsertMeasureCallBack(self):
        np0 = NotePosition(measureIndex=0, noteTime=0, drumIndex=0)
        np1 = NotePosition(measureIndex=1, noteTime=0, drumIndex=0)
        self.staff.addNote(np0, "x")
        self.staff.insertMeasure(np0, Measure(8))
        self.staff.addNote(np0, "x")
        self.staff.deleteNote(np1)
        self.assertEqual(len(self.calls), 3)
        self.assertEqual(self.calls[0], (0, 0, 0))
        self.assertEqual(self.calls[1], (0, 0, 0))
        self.assertEqual(self.calls[2], (1, 0, 0))
Beispiel #3
0
class TestNoteControl(unittest.TestCase):
    def setUp(self):
        self.staff = Staff()
        self.staff.addMeasure(Measure(16))
        self.staff.addMeasure(Measure(16))
        self.staff.addMeasure(Measure(16))
        self.staff.addMeasure(Measure(16))

    def testAddNote(self):
        np = NotePosition(measureIndex = 0, noteTime = 0, drumIndex = 0)
        self.staff.addNote(np, "o")
        measure = self.staff[np.measureIndex]
        self.assertEqual(measure.getNote(np), "o")

    def testAddNote_BadTime(self):
        self.assertRaises(BadTimeError, self.staff.addNote,
                          NotePosition(measureIndex = -1,
                                       noteTime = 0, drumIndex = 0), "x")
        self.assertRaises(BadTimeError, self.staff.addNote,
                          NotePosition(measureIndex = 4,
                                       noteTime = 0, drumIndex = 0), "x")
        self.assertRaises(BadTimeError, self.staff.addNote,
                          NotePosition(measureIndex = 0,
                                       noteTime = -1, drumIndex = 0), "x")
        self.assertRaises(BadTimeError, self.staff.addNote,
                          NotePosition(measureIndex = 0,
                                       noteTime = 20, drumIndex = 0), "x")

    def testDeleteNote(self):
        np = NotePosition(measureIndex = 0, noteTime = 0, drumIndex = 0)
        self.staff.addNote(np, "o")
        self.staff.deleteNote(np)
        measure = self.staff[np.measureIndex]
        self.assertEqual(measure.getNote(np), EMPTY_NOTE)

    def testDeleteNote_BadTime(self):
        self.assertRaises(BadTimeError, self.staff.deleteNote,
                          NotePosition(measureIndex = -1,
                                       noteTime = 0, drumIndex = 0))
        self.assertRaises(BadTimeError, self.staff.deleteNote,
                          NotePosition(measureIndex = 20,
                                       noteTime = 0, drumIndex = 0))
        self.assertRaises(BadTimeError, self.staff.deleteNote,
                          NotePosition(measureIndex = 0,
                                       noteTime = -1, drumIndex = 0))
        self.assertRaises(BadTimeError, self.staff.deleteNote,
                          NotePosition(measureIndex = 0,
                                       noteTime = 20, drumIndex = 0))

    def testToggleNote(self):
        np = NotePosition(measureIndex = 0, noteTime = 0, drumIndex = 0)
        self.staff.toggleNote(np, "o")
        measure = self.staff[np.measureIndex]
        self.assertEqual(measure.getNote(np), "o")
        self.staff.toggleNote(np, "o")
        self.assertEqual(measure.getNote(np), EMPTY_NOTE)

    def testToggleNote_BadTime(self):
        self.assertRaises(BadTimeError, self.staff.toggleNote,
                          NotePosition(measureIndex = -1,
                                       noteTime = 0, drumIndex = 0), "x")
        self.assertRaises(BadTimeError, self.staff.toggleNote,
                          NotePosition(measureIndex = 20,
                                       noteTime = 0, drumIndex = 0), "x")
        self.assertRaises(BadTimeError, self.staff.toggleNote,
                          NotePosition(measureIndex = 0,
                                       noteTime = -1, drumIndex = 0), "x")
        self.assertRaises(BadTimeError, self.staff.toggleNote,
                          NotePosition(measureIndex = 0,
                                       noteTime = 20, drumIndex = 0), "x")
Beispiel #4
0
class TestNoteControl(unittest.TestCase):
    def setUp(self):
        self.staff = Staff()
        self.staff.addMeasure(Measure(16))
        self.staff.addMeasure(Measure(16))
        self.staff.addMeasure(Measure(16))
        self.staff.addMeasure(Measure(16))

    def testAddNote(self):
        np = NotePosition(measureIndex=0, noteTime=0, drumIndex=0)
        self.staff.addNote(np, "o")
        measure = self.staff[np.measureIndex]
        self.assertEqual(measure.getNote(np), "o")

    def testAddNote_BadTime(self):
        self.assertRaises(
            BadTimeError, self.staff.addNote,
            NotePosition(measureIndex=-1, noteTime=0, drumIndex=0), "x")
        self.assertRaises(
            BadTimeError, self.staff.addNote,
            NotePosition(measureIndex=4, noteTime=0, drumIndex=0), "x")
        self.assertRaises(
            BadTimeError, self.staff.addNote,
            NotePosition(measureIndex=0, noteTime=-1, drumIndex=0), "x")
        self.assertRaises(
            BadTimeError, self.staff.addNote,
            NotePosition(measureIndex=0, noteTime=20, drumIndex=0), "x")

    def testDeleteNote(self):
        np = NotePosition(measureIndex=0, noteTime=0, drumIndex=0)
        self.staff.addNote(np, "o")
        self.staff.deleteNote(np)
        measure = self.staff[np.measureIndex]
        self.assertEqual(measure.getNote(np), EMPTY_NOTE)

    def testDeleteNote_BadTime(self):
        self.assertRaises(
            BadTimeError, self.staff.deleteNote,
            NotePosition(measureIndex=-1, noteTime=0, drumIndex=0))
        self.assertRaises(
            BadTimeError, self.staff.deleteNote,
            NotePosition(measureIndex=20, noteTime=0, drumIndex=0))
        self.assertRaises(
            BadTimeError, self.staff.deleteNote,
            NotePosition(measureIndex=0, noteTime=-1, drumIndex=0))
        self.assertRaises(
            BadTimeError, self.staff.deleteNote,
            NotePosition(measureIndex=0, noteTime=20, drumIndex=0))

    def testToggleNote(self):
        np = NotePosition(measureIndex=0, noteTime=0, drumIndex=0)
        self.staff.toggleNote(np, "o")
        measure = self.staff[np.measureIndex]
        self.assertEqual(measure.getNote(np), "o")
        self.staff.toggleNote(np, "o")
        self.assertEqual(measure.getNote(np), EMPTY_NOTE)

    def testToggleNote_BadTime(self):
        self.assertRaises(
            BadTimeError, self.staff.toggleNote,
            NotePosition(measureIndex=-1, noteTime=0, drumIndex=0), "x")
        self.assertRaises(
            BadTimeError, self.staff.toggleNote,
            NotePosition(measureIndex=20, noteTime=0, drumIndex=0), "x")
        self.assertRaises(
            BadTimeError, self.staff.toggleNote,
            NotePosition(measureIndex=0, noteTime=-1, drumIndex=0), "x")
        self.assertRaises(
            BadTimeError, self.staff.toggleNote,
            NotePosition(measureIndex=0, noteTime=20, drumIndex=0), "x")