Esempio n. 1
0
class ReprTest(TestCase):
    """PCSet and PSet repr's vary based on ordered and multiset settings"""

    def setUp(self):
        self.l = [0, 1, -7, 16, 1, 0]
        self.pcset = PCSet(self.l)
        self.pset = PSet(self.l)

    def testreprO(self):
        self.pcset.ordered(True)
        self.pset.ordered(True)
        self.pcset.multiset(False)
        self.pset.multiset(False)
        self.assertEqual(self.pcset.__repr__(), '[0, 1, 5, 4]')
        self.assertEqual(self.pset.__repr__(), '[0, 1, -7, 16]')

    def testreprO_Multi(self):
        pcset = PCSet(self.l, ordered=True, multiset=True)
        pset = PSet(self.l, ordered=True, multiset=True)
        self.assertEqual(pcset.__repr__(), '[0, 1, 5, 4, 1, 0]')
        self.assertEqual(pset.__repr__(), '[0, 1, -7, 16, 1, 0]')

    def testreprUO(self):        
        self.pcset.ordered(False)
        self.pset.ordered(False)
        self.pcset.multiset(False)
        self.pset.multiset(False)
        self.assertEqual(self.pcset.__repr__(), '[0, 1, 4, 5]')
        self.assertEqual(self.pset.__repr__(), '[-7, 0, 1, 16]')

    def testreprUO_Multi(self):
        pcset = PCSet(self.l, ordered=False, multiset=True)
        pset = PSet(self.l, ordered=False, multiset=True)
        self.assertEqual(pcset.__repr__(), '[0, 0, 1, 1, 4, 5]')
        self.assertEqual(pset.__repr__(), '[-7, 0, 0, 1, 1, 16]')
Esempio n. 2
0
class SettingsTest(TestCase):
    """PCSet and PSet instances have various methods to change settings"""

    def setUp(self):
        self.l = [0, 4, 9, 11]
        self.pcset = PCSet(self.l)
        self.pset = PSet(self.l)

    def testMod(self):
        self.pcset.mod(7)
        self.pset.mod(13)
        self.assertEqual(self.pcset._mod, 7)
        self.assertEqual(self.pset._mod, 13)

    def testModInvalid(self):
        for n in [0, 32]:
            self.assertRaises(self.pcset.InvalidModulus, self.pcset.mod, n)

    def testCanon(self):
        a = self.pcset
        b = self.pset
        a.canon(True, False, False)
        b.canon(False, True, True)        
        self.assertTrue(
            a._canon_t == True and a._canon_i == False and a._canon_m == False
        )
        self.assertTrue(
            b._canon_t == False and b._canon_i == True and b._canon_m == True
        )

    def testDefault_m(self):
        self.pcset.default_m(7)
        self.assertEqual(self.pcset._default_m, 7)

    def testOrdered(self):
        self.pcset.ordered(True)
        self.pset.ordered(True)
        self.assertTrue(
            self.pcset._ordered == True and self.pset._ordered == True
        )
        self.pcset.ordered(False)
        self.pset.ordered(False)
        self.assertTrue(
            self.pcset._ordered == False and self.pset._ordered == False
        )

    def testMultiset(self):
        self.pcset.multiset(True)
        self.pset.multiset(True)
        self.assertTrue(
            self.pcset._multiset == True and self.pset._multiset == True
        )
        self.pcset.multiset(False)
        self.pset.multiset(False)
        self.assertTrue(
            self.pcset._multiset == False and self.pset._multiset == False
        )
Esempio n. 3
0
    def testcopySettings(self):
        def verify(current):
            self.assertEqual(current.__class__, PCSet)
            self.assertTrue(current._ordered == False and current._multiset == False)
            self.assertEqual(current._mod, 7)
            self.assertTrue(current._canon_t, True)
            self.assertEqual(current._canon_i, False)
            self.assertEqual(current._canon_m, True)
            self.assertEqual(current.pitches, self.l)

        a = PCSet(self.l)
        a.mod(7)
        a.ordered(False)
        a.multiset(False)
        a.canon(True, False, True)
        a2 = a.copy()
        verify(a2)    
        b = PSet(self.l)
        self.assertEqual(b.__class__, PSet)
        b = a.copy()
        verify(b)