def test_init_type(self): """ Try creating chords with a particular type and check (a) that they successfully create a chord and (b) that the chord has the right type. """ for ctype in Chord.TYPE_SYMBOLS.values(): c = Chord("C", type=ctype) self.assertEqual(c.type, ctype)
def test_interval(self): """ Try getting the interval between two chords and check it comes out as expected. """ # Some randomly chosen tests tests = [(0, "C", "C", True), (2, "F", "G", False), (4, "D", "F#", False), (6, "B", "F", True), (8, "F", "Db", False), (10, "Ab", "F#", False)] for interval, lower, upper, invertible in tests: c0 = Chord(lower) c1 = Chord(upper) self.assertEqual(interval, Chord.interval(c0, c1)) # Try inverting the interval and check it's only the same in the # cases where the interval is its own inverse if invertible: self.assertEqual(interval, Chord.interval(c1, c0)) else: self.assertNotEqual(interval, Chord.interval(c1, c0))
def test_from_numerals(self): """ Try creating chords using all possbile numerals and check the numeral and root get set correctly. """ for numeral, root, trg_num in self.ALLOWED_NUMERALS: # Try creating a Chord with each numeral c = Chord(numeral) # Check it has the right numeral self.assertEqual(trg_num, c.root_numeral) # and the right root number self.assertEqual(root, c.root)
def test_set_root(self): """ Try setting the root or numeral after a chord is created and check that both values get correctly set. """ c = Chord(self.ALLOWED_NUMERALS[0][0]) for numeral, root, trg_num in self.ALLOWED_NUMERALS: # Try setting the root and check root and numeral are correct c.root = root self.assertEqual(root, c.root) self.assertEqual(trg_num, c.root_numeral) for numeral, root, trg_num in self.ALLOWED_NUMERALS: # Try setting the numeral and check root and numeral are correct c.root_numeral = numeral self.assertEqual(root, c.root) self.assertEqual(trg_num, c.root_numeral)