def test_associativity(self): x = Permutation.from_string('(0, 1)(2, 3)', 4) y = Permutation.from_string('(1, 2)', 4) z = Permutation.from_string('(0, 3)', 4) l = (x * y) * z r = x * (y * z) n = x * y * z self.assertEqual(l, r) self.assertEqual(l, n) self.assertEqual(r, n)
def test_construction_from_invalid_string(self): tests = [('(,)', 4), ('( ,)', 4), ('( ', 4), ('( ,', 4), ('(1, )', 4), ('(0,,1)', 4), ('(0, ,1)', 4), ('(0, ,1)', 4), ('0, 1, 2)', 3), ('(0, 1(2, 3)', 4), ('(0, 1,(2, 3)', 4), ('1 (0, 1)(2, 3) ', 4), (' 1 (0, 1 ) ( 2, 3) ', 4), (' (0, 1 ) ( 2, 3 ', 4), (' (0, 1 ) ( 2, 3', 4), (' (0, 1 ) ( 2, 3,', 4)] for test in tests: with self.subTest(test=test[0]): with self.assertRaises(ValueError): cycles_string = test[0] dim = test[1] Permutation.from_string(cycles_string, dim)
def test_construction_from_string(self): tests = { ('()', 4): [0, 1, 2, 3], ('( )', 4): [0, 1, 2, 3], ('(0)', 4): [0, 1, 2, 3], ('(0 )', 4): [0, 1, 2, 3], ('( 0)', 4): [0, 1, 2, 3], ('(0, 1, 2)', 3): [1, 2, 0], ('(0, 1)(2, 3)', 4): [1, 0, 3, 2], (' (0, 1)(2, 3) ', 4): [1, 0, 3, 2], (' (0, 1 ) ( 2, 3) ', 4): [1, 0, 3, 2] } for test, expected in tests.items(): with self.subTest(test=test): cycles_string = test[0] dim = test[1] self.assertEqual(Permutation.from_string(cycles_string, dim), Permutation.from_list(expected))