class SetRelationships(unittest.TestCase): def setUp(self): self.cmaj = PcSet('047') self.caug = PcSet('048') self.cscale = PcSet('024579B') self.blackkeys = self.cscale.complement() self.c7 = PcSet('047A') def test_is_complement(self): self.assert_(is_complement(self.cscale, self.blackkeys)) def test_is_prime_complement(self): mixedup = self.blackkeys.TnI(3) self.failIf(is_complement(self.cscale, mixedup)) self.assert_(is_prime_complement(self.cscale, mixedup)) def test_subset_of(self): self.assert_(subset_of(self.cscale, self.cmaj)) def test_prime_subset_of(self): self.failIf(subset_of(self.cscale, self.blackkeys)) self.assert_(prime_subset_of(self.cscale, self.blackkeys)) def test_not_prime_subset(self): self.failIf(prime_subset_of(self.cscale, self.caug)) def test_fit_in_1(self): result = fit_in(self.cscale, self.cmaj) self.assertEqual(result.Tn, [0, 5, 7]) self.assertEqual(result.TnI, [4, 9, 11]) def test_harmonize_1(self): result = harmonize(self.cscale, self.cmaj) self.assertEqual(result.Tn, [0, 5, 7]) self.assertEqual(result.TnI, [4, 9, 11]) def test_fit_in_2(self): result = fit_in(self.cscale, self.c7) self.assertEqual(result.Tn, [7]) self.assertEqual(result.TnI, [9]) def test_harmonize_2(self): result = harmonize(self.cscale, self.c7) self.assertEqual(result.Tn, [5]) self.assertEqual(result.TnI, [9]) # added Opset.__str__() in 2.0.0b3 def test_OpSet_string_1(self): result = fit_in(self.cscale, self.c7) self.assertEqual(str(result), 'T(7) T(9)I') def test_OpSet_string_2(self): result = harmonize(self.cscale, self.c7) self.assertEqual(str(result), 'T(5) T(9)I') def test_OpSet_string_3(self): # An augmented triad can't fit in the major scale. result = fit_in(self.cscale, self.caug) self.assertEqual(str(result), 'None')
class SetOperations(unittest.TestCase): def setUp(self): self.amaj = PcSet('9B12468') self.empty = PcSet([]) self.chromatic = PcSet(range(12)) self.g7 = PcSet('7B25') # complement def test_complement(self): """ Tests the principle that the union of the original set and its complement should be the chromatic set. """ fsm5 = self.amaj.complement() self.assertEqual(len(fsm5) + len(self.amaj), 12) chromatic = PcSet(list(self.amaj) + list(fsm5)) self.assertEqual(len(chromatic), 12) def test_complement_chromatic(self): empty = self.chromatic.complement() self.assertEqual(list(empty), []) def test_complement_empty_set(self): chromatic = self.empty.complement() self.assertEqual(list(chromatic), list(range(12))) # reverse def test_reverse(self): n = list(self.amaj) r = list(self.amaj.reverse()) size = len(n) self.assertEqual(size, len(r)) for x in range(size): self.assertEqual(n[x], r[size - 1 - x]) def test_reverse_empty(self): r = self.empty.reverse() self.assertEqual(list(r), []) # sort def test_sort(self): csphryg = self.amaj.sort() self.assertEqual(str(csphryg), '124689B') def test_sort_empty(self): es = self.empty.sort() self.assertEqual(list(es), []) # shift def test_shift(self): arotations = [] for x in range(len(self.amaj)): arotations.append(self.amaj.shift(x)) lastelements = [] for pcs in arotations: lastnote = list(pcs).pop() lastelements.append(lastnote) lastelements.reverse() self.assertEqual(list(self.amaj), lastelements) def test_shift_empty(self): es = self.empty.shift(3) self.assertEqual(list(es), []) # zero def test_zero(self): cmaj = self.amaj.zero() self.assertEqual(str(cmaj), '024579B') def test_zero_empty(self): es = self.empty.zero() self.assertEqual(list(es), []) # normal def test_normal(self): g7n = self.g7.normal() self.assertEqual(list(g7n), [11, 2, 5, 7]) def test_normal_empty(self): es = self.empty.normal() self.assertEqual(list(es), []) # reduced def test_reduced(self): amajchord = PcSet([9, 1, 4]) self.assertEqual(list(amajchord.reduced()), [0, 4, 7]) # prime def test_prime_1(self): maj = self.amaj.prime() self.assertEqual(str(maj), '013568A') def test_prime_2(self): m7b5 = self.g7.prime() self.assertEqual(str(m7b5), '0258') def test_prime_empty(self): es = self.empty.prime() self.assertEqual(list(es), [])