def setUp(self): """ create basic permutations to call """ self.id = Perm([]) self.perm1 = Perm(((1, 2, 3), ))
def test_init_perm(self): """ test that it just copies the permutation object """ p = Perm(((1, 2, 3), )) q = Perm(p) self.assertEqual(p.cycles, q.cycles) self.assertEqual(q.list, p.list) self.assertFalse(p is q) self.assertFalse(p.list is q.list)
def test_inv(self): p = Perm((1, 2, 3)) pi = p.inv() l = ['a', 4, {'tree': 3}] self.assertEqual((p * pi).list, [0]) self.assertEqual(l, (p * pi)(l))
def test_init_cycle(self): """ test creating a permutaiton with a cycle """ l = [0, 1, 3, 2] cycle = ((3, 4), ) p = Perm(cycle) self.assertEqual(p.list, l) self.assertEqual(p.cycles, cycle)
def test_power_valid(self): p = Perm((1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) self.assertEqual(p * p * p * p, p**4)
def test_order_empty(self): self.assertEqual(1, Perm([]).Order())
def test_order(self): p = Perm(((1, 2, 3), (4, 5), (6, 7, 8, 9, 10))) self.assertEqual(p.Order(), 30)
def test_mul_error(self): p1 = Perm((1, 2)) self.assertEqual(NotImplemented, p1.__mul__('hello'))
def test_mul(self): p1 = Perm(((1, 2), )) p2 = Perm(((1, 2, 3), )) p3 = Perm(((2, 3), )) self.assertEqual(p1 * p2, p3)
def test_eq_2perms_neq(self): p2 = Perm([1, 3, 2]) self.assertNotEqual(self.p1, p2)
def test_eq_2perms_eq(self): p2 = Perm(((2, 1), )) self.assertEqual(self.p1, p2)
def setUp(self): self.p1 = Perm(((1, 2), ))