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)))
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])
class Similarity(unittest.TestCase): def setUp(self): self.a = PcSet('9047B2') self.b = PcSet('047B25') self.c = self.b.TnI(9) self.d = PcSet('9048AB') self.forte42 = PcSet([0, 1, 2, 4]) self.forte413 = PcSet([0, 1, 3, 6]) self.forte43 = PcSet([0, 1, 3, 4]) self.forte510 = PcSet([0, 1, 3, 4, 6]) self.forte5Z12 = PcSet([0, 1, 3, 5, 6]) self.forte5Z36 = PcSet([0, 1, 2, 4, 7]) def test_Rp_yes(self): self.assert_(Rp(self.a, self.b)) def test_Rp_no(self): self.failIf(Rp(self.a, self.c)) def test_Rp_prime_yes(self): self.assert_(Rp_prime(self.a, self.c)) def test_Rp_path(self): result = Rp_path(self.a, self.c) self.assertEqual(result.Tn, [5, 10]) self.assertEqual(result.TnI, [4, 9]) def test_Rp_prime_no(self): self.failIf(Rp_prime(self.a, self.d)) def test_R0_yes(self): self.assert_(R0(self.forte42, self.forte413)) def test_R0_no(self): self.failIf(R0(self.forte42, self.forte43)) def test_R1_yes(self): self.assert_(R1(self.forte42, self.forte43)) def test_R1_no(self): self.failIf(R1(self.forte42, self.forte413)) def test_R2_yes(self): self.assert_(R2(self.forte510, self.forte5Z12)) def test_R2_no_actually_R0(self): self.failIf(R2(self.forte42, self.forte413)) def test_R2_no_actually_R1(self): self.failIf(R2(self.forte42, self.forte43)) def test_Zpair_yes(self): self.assert_(Zpair(self.forte5Z12, self.forte5Z36)) def test_Zpair_no(self): self.failIf(Zpair(self.forte5Z12, self.forte510))
def test_common(self): """ Very similar to the test applied to cvec in test_pcset.py: finds the common tone vector, then makes sure the common tones are actually there for each value of TnI. """ c = PcSet('024579B') cvec = c.cvec() for n in range(12): self.assertEqual(len(common(c, c.TnI(n))), cvec[n])