示例#1
0
    def test_equality(self):
        p = Permutation.from_list([1, 0, 2])
        q = Permutation.from_cycle((0, 1), 3)
        self.assertEqual(p, q)
        self.assertTrue(p == q)

        q = Permutation.from_cycle((0, 1), 2)
        self.assertNotEqual(p, q)
        self.assertTrue(p != q)
示例#2
0
    def test_action(self):
        X = [0, 1, 2, 3, 4, 5]
        p = Permutation(6)
        p.act_on(X)
        self.assertEqual(X, [0, 1, 2, 3, 4, 5])

        p = Permutation.from_cycle((3, 0), 4)
        p.act_on(X)
        self.assertEqual(X, [3, 1, 2, 0, 4, 5])

        X = [0, 1, 2, 3, 4, 5]
        p = Permutation.from_cycle((1, 2, 3), 6)
        p.act_on(X)
        self.assertEqual(X, [0, 3, 1, 2, 4, 5])
示例#3
0
    def test_exceptions_from_construction_from_cycle(self):
        with self.assertRaises(ValueError):
            Permutation.from_cycle((0, 1), 1)

        with self.assertRaises(ValueError):
            Permutation.from_cycle((4, ), 4)

        with self.assertRaises(ValueError):
            Permutation.from_cycle((1, 2, 3, 1, 4), 5)
示例#4
0
    def test_construction_from_cycle(self):
        # mapping from (cycle, dim) -> list representation
        tests = {
            ((), 1): [0],
            ((0, ), 1): [0],
            ((1, ), 4): [0, 1, 2, 3],
            ((1, 2), 4): [0, 2, 1, 3],
            ((0, 3), 4): [3, 1, 2, 0],
            ((0, 1, 2), 4): [1, 2, 0, 3],
            ((0, 3, 1), 4): [3, 0, 2, 1]
        }

        for test, result in tests.items():
            p = Permutation.from_cycle(test[0], test[1])
            self.assertEqual(p, Permutation.from_list(result))
示例#5
0
 def test_hash(self):
     p = Permutation.from_list([1, 0, 2])
     q = Permutation.from_cycle((0, 1), 3)
     self.assertEqual(p, q)
     self.assertEqual(hash(p), hash(q))