Пример #1
0
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])
Пример #2
0
class SetAnalysis(unittest.TestCase):
    def setUp(self):
        self.amaj = PcSet('9B12468')
        self.empty = PcSet([])

    # ivec

    def test_ivec_ait1(self):
        ait1 = PcSet('0146')
        self.assertEqual(ait1.ivec(), [1] * 6)

    def test_ivec_ait2(self):
        ait2 = PcSet('0137')
        self.assertEqual(ait2.ivec(), [1] * 6)

    def test_ivec_empty(self):
        self.assertEqual(self.empty.ivec(), [0] * 6)

    # cvec

    def test_cvec(self):
        """
        Tests the fundamental definition of cvec: that a given value at
        index n will be the number of common tones for the operation TnI.
        """
        cvec = self.amaj.cvec()
        for n in range(12):
            original = set(self.amaj)
            transformed = set(self.amaj.invert().transpose(n))
            common_tones = len(original & transformed)
            self.assertEqual(common_tones, cvec[n])

    def test_cvec_empty(self):
        self.assertEqual(self.empty.cvec(), [0] * 12)
Пример #3
0
class FundamentalMethods(unittest.TestCase):
    def setUp(self):
        self.pcs = PcSet('0146')

    # These also test the __iter__ method, indirectly

    def test_inverse(self):
        """
        Test the principle that, for a given pcset, the sum of the
        corresponding elements in the original and the inverse will
        always be 0 (in mod 12 arithmetic).
        """
        inv = self.pcs.invert()
        self.assertEqual(len(self.pcs), len(inv))
        for n, i in zip(self.pcs, inv):
            self.assertEqual((n + i) % 12, 0)

    def test_transpose(self):
        """
        Tests the principle that, for a given pcset, the difference
        between the corresponding element in the original and the
        transposed version will always be equal to the transposition
        amount (in mod 12 arithmetic).
        """
        for x in range(12):
            trx = self.pcs.transpose(x)
            self.assertEqual(len(self.pcs), len(trx))
            for n, t in zip(self.pcs, trx):
                self.assertEqual((t - n) % 12, x % 12)

    def test_transpose_float(self):
        trf = self.pcs.transpose(3.6)
        for n, t in zip(self.pcs, trf):
            self.assertEqual((t - n) % 12, 3)

    def test_transpose_empty(self):
        es = PcSet([])
        self.assertEqual(list(es.transpose(3)), [])