def testinsertNegative(self): a = PCSet(self.l, multiset=True) b = PSet(self.l, multiset=True) a.insert(-2, 2) b.insert(-3, 12) self.assertEqual(a.pitches, [1, 4, 23, 2, 5, -9]) self.assertEqual(b.pitches, [1, 4, 12, 23, 5, -9])
def testinsertAfter(self): a = PCSet(self.l) b = PSet(self.l) a.insert(100, 1) b.insert(100, 0) self.assertEqual(a.pitches, self.l + [1]) self.assertEqual(b.pitches, self.l + [0])
def testinsertEnd(self): a = PCSet(self.l) b = PSet(self.l) a.insert(6, 10) b.insert(6, 99) self.assertEqual(a.pitches, self.l + [10]) self.assertEqual(b.pitches, self.l + [99])
def testinsertMiddle(self): a = PCSet(self.l) b = PSet(self.l) a.insert(3, 15) b.insert(4, 8) self.assertEqual(a.pitches, [1, 4, 23, 15, 5, -9]) self.assertEqual(b.pitches, [1, 4, 23, 5, 8, -9])
def testinsertBegin(self): a = PCSet(self.l) b = PSet(self.l) a.insert(0, 10) b.insert(0, 11) self.assertEqual(a.pitches, [10] + self.l) self.assertEqual(b.pitches, [11] + self.l)
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]')
def check_each_tto(mod): a = PCSet(0, 3, mod=mod) ttos = list(a.each_tto()) index = 0 for m in (1, -1, 5, mod - 5): for n in range(0, mod): self.assertEqual(ttos[index], (n, m)) index += 1
def testEach_card(self): card = 2 mod = 13 a = PCSet(list(range(0, card)), mod=mod) aggregate = PCSet(list(range(0, mod)), mod=mod) for each, each_static in zip(a.each_card(), PCSet.each_card_in_mod(card, mod)): self.assertEqual(each.cardinality, card) self.assertEqual(each.mod(), mod) self.assertEqual(each._pc_set.issubset(aggregate), True)
class PrimeTestCase(TestCase): def setUp(self): self.l = [0, 1, 2, 3, 4, 6] self.set_ints = [0, 4095, 392, 661, 583, 203, 2741, 584, 394, 858] self.sets = [PCSet(utils.fromint(each)) for each in self.set_ints] self.pcset = PCSet(self.l) self.t_rots = list(self.pcset._t_rotations()) self.i_rots = list(self.pcset._i_rotations()) self.m_rots = list(self.pcset._m_rotations()) self.mi_rots = list(self.pcset._mi_rotations())
def testForteSet(self): a = PCSet() fnames = [each.forte for each in self.sets] new_sets = [] for fname in fnames: a.clear() a = PCSet.forte_name(fname) new_sets.append(a.copy()) new_fnames = [each.forte for each in new_sets] self.assertEqual(fnames, new_fnames)
class TnTmInPlace(TestCase): """operations that change a PCSet/PSet in place via TnTm""" def setUp(self): self.l = [0, -15, 20, 4, 2, 0] self.a = PCSet(self.l, multiset=True) self.b = self.a.copy() self.c = self.a.copy() def testT(self): a = self.a b = self.b a.t(5) b.t(-2) self.assertEqual(a.pitches, [5, -10, 25, 9, 7, 5]) self.assertEqual(b.pitches, [-2, -17, 18, 2, 0, -2]) def testI(self): a = self.a b = self.b c = self.c a.i() b.i() c.i(3) self.assertEqual(a.pitches, [0, 15, -20, -4, -2, 0]) self.assertEqual(a, b.pcs) self.assertEqual(b.pitches, a.pitches) self.assertEqual(c.pitches, [3, 18, -17, -1, 1, 3]) def testM(self): a = self.a b = self.b a.m() b.m(3) self.assertEqual(a._unique_pcs, [0, 4, 8, 9, 10]) self.assertEqual(b._unique_pcs, [0, 1, 3, 7, 11]) def testMi(self): a = self.a b = self.b c = self.c a.mi() b.m() b.i() c.mi(5) self.assertEqual(a._unique_pcs, [0, 2, 3, 4, 8]) self.assertEqual(a, b) self.assertEqual(c._unique_pcs, [1, 5, 7, 8, 9]) def testTm(self): a = self.a b = a.copy() c = b.copy() a.t_m(0, 1) b.t_m(1, 5) c.t_m(5, -1) self.assertEqual(a._unique_pcs, [0, 2, 4, 8, 9]) self.assertEqual(b._unique_pcs, [1, 5, 9, 10, 11]) self.assertEqual(c._unique_pcs, [1, 3, 5, 8, 9])
def testEach_n(self): self.pcset.mod(12) self.assertEqual(list(self.pcset.each_n()), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) self.pcset.mod(6) self.assertEqual(list(self.pcset.each_n()),[0, 1, 2, 3, 4, 5]) self.assertEqual(list(self.pcset.each_n()), list(PCSet.each_n_in_mod(6)))
class SupersetsTest(TestCase): def setUp(self): self.l = [0, 1, 2, 3, 5, 6, 8, 10, 11] self.pcset = PCSet(self.l) def testSupersets(self): supers = [sup for sup in self.pcset.supersets()] self.assertEqual(supers, [ [0, 1, 2, 3, 4, 5, 6, 8, 10, 11], [0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [0, 1, 2, 3, 5, 6, 7, 8, 10, 11], [0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [0, 1, 2, 3, 5, 6, 8, 9, 10, 11], [0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] ]) def testSuperPrimes(self): superprimes = [superprime for superprime in self.pcset.superprimes()] self.assertEqual(superprimes, [ [0, 1, 2, 3, 4, 5, 6, 7, 8, 10], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [0, 1, 2, 3, 4, 5, 7, 8, 9, 10], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [0, 1, 2, 3, 4, 5, 6, 7, 9, 10], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] ])
def testEach_set(self): self.pcset.mod(12) each_set = list(self.pcset.each_set()) self.assertEqual(each_set[0:6], [[], [0], [1], [0, 1], [2], [0, 2]]) self.assertEqual(each_set[-1], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) self.assertEqual(each_set, list(PCSet.each_set_in_mod(12))) for index, each in enumerate(each_set): self.assertEqual(utils.setint(each), index) self.pcset.mod(4) each_set = list(self.pcset.each_set()) self.assertEqual(each_set[0:3], [[], [0], [1]]) self.assertEqual(each_set[-1], [0, 1, 2, 3])
class SubsetsTest(TestCase): def setUp(self): self.l = [0, 3, 4] self.pcset = PCSet(self.l) def testSubsets(self): subs = [sub for sub in self.pcset.subsets()] self.assertEqual(subs, [ [3, 4], [4], [], [3], [], [0, 4], [4], [], [0], [], [0, 3], [3], [], [0], [] ]) self.assertTrue(isinstance(subs[0], PCSet)) def testSubPrimes(self): subprimes = [subprime for subprime in self.pcset.subprimes()] self.assertEqual(subprimes, [ [0, 1], [0], [], [0], [], [0, 4], [0], [], [0], [], [0, 3], [0], [], [0], [] ])
def testEach_prime_in_card_mod(self): trichords = [ [0, 1, 2], [0, 1, 3], [0, 1, 4], [0, 1, 5], [0, 1, 6], [0, 2, 4], [0, 2, 5], [0, 2, 6], [0, 2, 7], [0, 3, 6], [0, 3, 7], [0, 4, 8], ] for each in PCSet.each_prime_in_card_mod(3, 13): self.assertEqual(each.mod(), 13) trichords.remove(each) self.assertEqual(trichords, [])
class VarEqualsTnTm(TestCase): """operations that return a PCSet or PSet""" def setUp(self): self.l = [0, 2, 5, 20, -1] self.pcset = PCSet(self.l) self.pset = PSet(self.l) def testTranspose(self): a = self.pcset._transpose(5) self.assertEqual(a.pitches, [5, 7, 10, 25, 4]) self.assertEqual(a.uo_pcs, [1, 4, 5, 7, 10]) self.assertEqual(a.__class__, PCSet) b = self.pset._transpose(5) self.assertEqual(b.pitches, [5, 7, 10, 25, 4]) self.assertEqual(b.__class__, PSet) def testInvert(self): a = self.pcset._invert() self.assertEqual(a.pitches, [0, -2, -5, -20, 1]) self.assertEqual(a.uo_pcs, [0, 1, 4, 7, 10]) self.assertEqual(a.__class__, PCSet) b = self.pset._invert(3) self.assertEqual(b.pitches, [3, 1, -2, -17, 4]) self.assertEqual(b.__class__, PSet) def testTranspose_multiply(self): a = self.pcset._transpose_multiply(1, 11) b = self.pset._transpose_multiply(5, 5) c = self.pset._transpose_multiply(0, 5) d = self.pcset._transpose_multiply(1, 1) self.assertEqual(a, a._transpose_multiply(0, 1)) self.assertEqual(a.pcs, [1, 11, 8, 5, 2]) self.assertEqual(b.pcs, [5, 3, 6, 9, 0]) self.assertEqual(c.pcs, self.pcset._transpose_multiply()) self.assertEqual(d, self.pcset._transpose(1))
def testNewFromInt(self): """Using fromint staticmethod to create new PCSets""" a = PCSet.fromint(5) self.assertEqual(a, [0, 2]) b = PCSet.fromint(630, 7) self.assertEqual(b, [1, 2, 4, 5, 6])
def testEachPrime(self): a = PCSet() for prime in a.each_prime(): self.assertEqual(prime.prime, prime._unique_pcs)
def setUp(self): self.l = [0, 3, 4] self.pcset = PCSet(self.l)
def testEach_set_in_mod(self): for each in PCSet.each_set_in_mod(10): self.assertEqual(each.mod(), 10) self.assertEqual(each, list(range(0, 10)))
def setUp(self): self.l = [0, 1, 2, 3, 5, 6, 8, 10, 11] self.pcset = PCSet(self.l)
def setUp(self): self.pcset = PCSet()
class EachTest(TestCase): """Methods that provide each n in the modulus or each set in the modulus""" def setUp(self): self.pcset = PCSet() def testEach_n(self): self.pcset.mod(12) self.assertEqual(list(self.pcset.each_n()), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) self.pcset.mod(6) self.assertEqual(list(self.pcset.each_n()),[0, 1, 2, 3, 4, 5]) self.assertEqual(list(self.pcset.each_n()), list(PCSet.each_n_in_mod(6))) def testEach_set(self): self.pcset.mod(12) each_set = list(self.pcset.each_set()) self.assertEqual(each_set[0:6], [[], [0], [1], [0, 1], [2], [0, 2]]) self.assertEqual(each_set[-1], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) self.assertEqual(each_set, list(PCSet.each_set_in_mod(12))) for index, each in enumerate(each_set): self.assertEqual(utils.setint(each), index) self.pcset.mod(4) each_set = list(self.pcset.each_set()) self.assertEqual(each_set[0:3], [[], [0], [1]]) self.assertEqual(each_set[-1], [0, 1, 2, 3]) def testEach_set_in_mod(self): for each in PCSet.each_set_in_mod(10): self.assertEqual(each.mod(), 10) self.assertEqual(each, list(range(0, 10))) def testEach_tto(self): def check_each_tto(mod): a = PCSet(0, 3, mod=mod) ttos = list(a.each_tto()) index = 0 for m in (1, -1, 5, mod - 5): for n in range(0, mod): self.assertEqual(ttos[index], (n, m)) index += 1 check_each_tto(12) check_each_tto(7) check_each_tto(15) def testEach_card(self): card = 2 mod = 13 a = PCSet(list(range(0, card)), mod=mod) aggregate = PCSet(list(range(0, mod)), mod=mod) for each, each_static in zip(a.each_card(), PCSet.each_card_in_mod(card, mod)): self.assertEqual(each.cardinality, card) self.assertEqual(each.mod(), mod) self.assertEqual(each._pc_set.issubset(aggregate), True) def testEach_prime_in_card_mod(self): trichords = [ [0, 1, 2], [0, 1, 3], [0, 1, 4], [0, 1, 5], [0, 1, 6], [0, 2, 4], [0, 2, 5], [0, 2, 6], [0, 2, 7], [0, 3, 6], [0, 3, 7], [0, 4, 8], ] for each in PCSet.each_prime_in_card_mod(3, 13): self.assertEqual(each.mod(), 13) trichords.remove(each) self.assertEqual(trichords, [])
def setUp(self): self.a = PCSet([0, 2, 5, 7]) self.b = PCSet([5, 7, 8]) self.c = PCSet([1, 3, 4])
class PCSetPropertyTest(TestCase): def setUp(self): self.a = PCSet([0, 2, 5, 7]) self.b = PCSet([5, 7, 8]) self.c = PCSet([1, 3, 4]) def testUnion(self): self.assertEqual(self.a + self.c, self.a.union(self.c)) def testDifference(self): self.assertEqual(self.a - self.b, self.a.difference(self.b)) def testSymmetricDifference(self): self.assertEqual(self.a.symmetric_difference(self.b), PCSet([0, 2, 8])) def testIntersection(self): self.assertEqual(PCSet([5, 7]), self.a.intersection(self.b)) def testSymDiffIntersectionUnion(self): sym_diff = self.a.symmetric_difference(self.b) intersection = self.a.intersection(self.b) self.assertEqual(sym_diff + intersection, self.a.union(self.b)) def testIsSubset(self): self.assertTrue(self.a.issubset([0,2,5,7,8,9])) self.assertFalse(self.a.issubset([0, 2])) def testIsSuperset(self): self.assertTrue(self.a.issuperset([5,7])) self.assertFalse(self.a.issuperset(self.c)) def testIsDisjoint(self): self.assertTrue(self.a.isdisjoint(self.a.literal_compliment)) self.assertTrue(self.a.isdisjoint(self.c)) self.assertFalse(self.a.isdisjoint(self.b))
def setUp(self): self.l = [0, 2, 5, 20, -1] self.pcset = PCSet(self.l) self.pset = PSet(self.l)
def testDS(self): self.assertEqual([tri.ds for tri in PCSet.each_prime_in_card_mod(3, 12)], [ 2, 1, 1, 1, 1, 2, 1, 1, 2, 2, 1, 6 ])
def setUp(self): self.l = [0, -15, 20, 4, 2, 0] self.a = PCSet(self.l, multiset=True) self.b = self.a.copy() self.c = self.a.copy()
def testMVector(self): for each in PCSet.each_prime_in_card_mod(3, 12): m_vector = each.m_vector(2) m_vector = [vect[1] for vect in m_vector] self.assertEqual(each.icv[1:], m_vector)