class TransformationRelationships(unittest.TestCase): def setUp(self): self.cmaj = PcSet('047') self.amaj = PcSet('914') self.cmin = PcSet('037') self.caug = PcSet('048') # symmetry 3 self.cscale = PcSet('024579B') # symmetry 1 self.c7b5 = PcSet('046A') # symmetry 2 self.dim = PcSet('0369') # symmetry 4 def fulltest(self, a, b, expected_Tn, expected_TnI): result = op_path(a, b) self.assertEqual(result.Tn, expected_Tn) self.assertEqual(result.TnI, expected_TnI) def test_op_path_none(self): self.fulltest(self.cmaj, self.caug, [], []) def test_op_path_Tn(self): self.fulltest(self.cmaj, self.amaj, [9], []) def test_op_path_TnI(self): self.fulltest(self.cmaj, self.cmin, [], [7]) def test_symmetry(self): trials = [self.cmaj, self.cscale, self.c7b5, self.caug, self.dim] for x in range(5): self.assertEqual(symmetry(trials[x]), x) def test_op_path_symmetry1(self): bscale = self.cscale.T(11) self.fulltest(self.cscale, bscale, [11], [3]) def test_op_path_symmetry2(self): d7b5 = self.c7b5.T(2) self.fulltest(self.c7b5, d7b5, [2, 8], [0, 6]) def test_op_path_symmetry3(self): baug = self.caug.T(11) self.fulltest(self.caug, baug, [3, 7, 11], [3, 7, 11]) def test_op_path_symmetry4(self): self.fulltest(self.dim, self.dim.T(1), [1, 4, 7, 10], [1, 4, 7, 10]) def test_rel_Tn(self): self.assert_(rel_Tn(self.cmaj, self.amaj)) def test_rel_TnI(self): self.assert_(rel_TnI(self.cmaj, self.cmin))
class ShorthandMethods(unittest.TestCase): def setUp(self): self.pcs = PcSet('0146') def test_T(self): a = self.pcs.T(3) b = self.pcs.transpose(3) self.assertEqual(list(a), list(b)) def test_I(self): a = self.pcs.I() b = self.pcs.invert() self.assertEqual(list(a), list(b)) def test_TnI(self): a = self.pcs.TnI(3) b = self.pcs.invert().transpose(3) self.assertEqual(list(a), list(b)) def test_Ixy(self): """ Tests the principle that the two specified pitches should transform into each other. """ n = list(self.pcs) a = list(self.pcs.Ixy(1, 4)) b = list(self.pcs.invert().transpose(5)) self.assertEqual(a, b) self.assertEqual(a[1], n[2]) self.assertEqual(a[2], n[1])
def test_union(self): """ Tests union by constructing the chromatic scale from 8 transposed major chords. (Cmaj -> Fmaj -> ... -> Bmaj) """ maj = PcSet('047') circle = [maj.T(n * 5) for n in range(8)] chromo = reduce(union, circle) self.assertEqual(set(chromo), set(range(12)))
def setUp(self): # Obvious: # The linear ascending chromatic scale. self.obvious = ToneRow(range(12)) # Obscure: # An example of using a simple pcset as a generator # for a tonerow . . . one day there will be a function # like this, but for now, we hack . . . . a = PcSet('015') self.obscure = ToneRow( str(a) + str(a.TnI(7)) + str(a.T(10)) + str(a.TnI(9)))
def test_major_scale_reproduction(self): majorscale = PcSet('024579B') for n in range(12): answer = PROPER_SCALE_FORMS[n].strip() self.assertEqual(notes(majorscale.T(n)), answer)