def test_degree(self):
        self.assertEqual(PartialPerm([1, 4, 2], [2, 3, 4], 6).degree(), 6)
        self.assertEqual(
            PartialPerm([7, 26, 3, 5], [23, 13, 19, 11], 29).degree(), 29)

        with self.assertRaises(TypeError):
            PartialPerm([1, 2], [0, 1], 3).degree(8.5)
    def test_rank(self):
        self.assertEqual(PartialPerm([1, 4, 2], [2, 3, 4], 6).rank(), 3)
        self.assertEqual(
            PartialPerm([1, 2, 4, 6, 7, 23], [0, 5, 2, 4, 6, 7], 26).rank(), 6)

        with self.assertRaises(TypeError):
            PartialPerm([1, 2], [0, 1], 3).rank(2)
 def test_right(self):
     ReportGuard(False)
     x = PartialPerm(range(16))
     o = RightAction(type(x), type(x))
     o.add_seed(x)
     o.add_generator(
         PartialPerm(
             [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
             [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0],
             16,
         ))
     o.add_generator(
         PartialPerm(
             [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
             [1, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
             16,
         ))
     o.add_generator(
         PartialPerm(
             [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
             [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],
             16,
         ))
     o.add_generator(
         PartialPerm(
             [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],
             [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
             16,
         ))
     self.assertEqual(o.size(), 65536)
     self.assertEqual(o.digraph().nr_scc(), 17)
Exemple #4
0
 def test_init(self):
     PartialPerm([1, 0, 2], [2, 0, 1], 3)
     PartialPerm([1, 0], [0, 1], 5)
     PartialPerm([0, 3, 4, 5, 8, 20, 23373],
                 [1, 2, 34, 23423, 233, 432, 26], 26260)
     # Check for CPPYY issue workaround
     PartialPerm([])
     PartialPerm([0, 1])
    def test_domain(self):
        self.assertEqual(set(PartialPerm([1, 4, 2], [2, 3, 4], 6).domain()),
                         set([1, 4, 2]))
        self.assertEqual(
            set(PartialPerm([7, 26, 3, 5], [23, 13, 19, 11], 29).domain()),
            set([7, 26, 3, 5]))

        with self.assertRaises(TypeError):
            PartialPerm([1, 2], [0, 1], 3).domain('a')
    def test_range(self):
        self.assertEqual(set(PartialPerm([1, 4, 2], [2, 3, 4], 6).range()),
                         set([2, 3, 4]))
        self.assertEqual(
            set(PartialPerm([7, 26, 3, 5], [23, 13, 19, 11], 29).range()),
            set([23, 13, 19, 11]))

        with self.assertRaises(TypeError):
            PartialPerm([1, 2], [0, 1], 3).range([3])
    def test_mul(self):
        (self.assertEqual(
            BooleanMat([[True, False], [False, True]]) *
            BooleanMat([[False, False], [False, True]]),
            BooleanMat([[False, False], [False, True]])))
        self.assertEqual(
            BooleanMat([[False]]) * BooleanMat([[True]]),
            BooleanMat([[False]]))
        (self.assertEqual(
            BooleanMat([[False, True, True], [True, True, False],
                        [False, False, False]]) *
            BooleanMat([[False, True, False], [True, False, False],
                        [False, False, True]]),
            BooleanMat([[True, False, True], [True, True, False],
                        [False, False, False]])))

        with self.assertRaises(TypeError):
            BooleanMat([[True, True], [False, False]]) * Transformation([1, 1])
        with self.assertRaises(TypeError):
            BooleanMat([[False, True, True], [True, True, False],
                        [False, False, False]]) * PartialPerm([0, 1], [1, 2],
                                                              3)
        with self.assertRaises(TypeError):
            BooleanMat([[True]]) * [[True]]
        with self.assertRaises(TypeError):
            BooleanMat([[True, False], [False, True]]) * Bipartition(
                [1, 2], [-1], [-2])

        with self.assertRaises(ValueError):
            (BooleanMat([[False, True, True], [True, True, False],
                         [False, False, False]]) *
             BooleanMat([[True, False], [False, True]]))
    def test_richcmp(self):
        self.assertEqual(BooleanMat([[True, False], [False, True]]),
                         BooleanMat([[True, False], [False, True]]))
        self.assertFalse(
            BooleanMat([[True, False], [False, True]]) != BooleanMat(
                [[True, False], [False, True]]))
        self.assertFalse(
            BooleanMat([[True, False], [False, True]]) == BooleanMat(
                [[False, False], [False, True]]))
        self.assertLess(BooleanMat([[False]]), BooleanMat([[True]]))
        self.assertFalse(
            BooleanMat([[False, True, True], [True, True, False],
                        [False, False, False]]) < BooleanMat([[
                            False, True, False
                        ], [True, False, False], [False, False, True]]))
        self.assertLessEqual(BooleanMat([[False]]), BooleanMat([[False]]))
        self.assertGreater(BooleanMat([[True, False], [False, True]]),
                           BooleanMat([[True, False], [False, False]]))
        self.assertFalse(
            BooleanMat([[True, False], [False, True]]) > BooleanMat(
                [[True, False], [False, True]]))
        self.assertGreaterEqual(BooleanMat([[False]]), BooleanMat([[False]]))

        with self.assertRaises(TypeError):
            (Bipartition([1, -2], [-1, 2]) >= BooleanMat([False, False],
                                                         [True, False]))
        with self.assertRaises(TypeError):
            BooleanMat([False, False], [True, False]) < Transformation([0, 1])
        with self.assertRaises(TypeError):
            (BooleanMat([True, False], [False, True]) == PartialPerm([0], [1],
                                                                     2))
    def test_richcmp(self):
        self.assertEqual(Bipartition([3, -4, -1], [2, -3], [4, -2], [1]),
                         Bipartition([4, -2], [3, -4, -1], [1], [2, -3]))
        self.assertFalse(
            Bipartition([3, -4, -1], [2, -3], [4, -2], [1]) != Bipartition(
                [4, -2], [3, -4, -1], [1], [2, -3]))
        self.assertLessEqual(Bipartition([1, -1, 3], [-3, 2, -2]),
                             Bipartition([1, -1], [2, 3, -2], [-3]))
        self.assertLess(Bipartition([1, -1], [2, -2]),
                        Bipartition([1, -2], [2, -1]))
        self.assertLessEqual(Bipartition([1, -1], [2, -2]),
                             Bipartition([1, -2], [2, -1]))
        self.assertGreaterEqual(Bipartition([1, -1, 3], [-3, 2, -2]),
                                Bipartition([1, -2], [2, -1]))
        self.assertFalse(
            Bipartition([1, -1, 3], [-3, 2, -2]) > Bipartition(
                [1, -1], [2, 3, -2], [-3]))

        with self.assertRaises(TypeError):
            (PartialPerm([1, 2], [2, 1], 3) == Bipartition([1, -1], [2, 3, -2],
                                                           [-3]))
        with self.assertRaises(TypeError):
            Bipartition([1, -1], [2, -2]) < Transformation([0, 1])
        with self.assertRaises(TypeError):
            Bipartition([1, -1], [2, -2]) != Transformation([0, 1])
    def test_richcmp(self):
        self.assertEqual(PBR([[1, -1], [-2, -1, 2]], [[2], [-2]]),
                         PBR([[1, -1], [-2, -1, 2]], [[2], [-2]]))
        self.assertEqual(PBR([[1, -1], [-2, -1, 2]], [[2], [-2]]),
                         PBR([[1, -1], [-2, -1, 2]], [[2], [-2]]))
        self.assertNotEqual(
            PBR([[1, -1], [-2, -1, 2]], [[2], [-2]]),
            PBR([[1, 2], [-2, 1, 2], [3, -3]], [[2, 1], [-2, 2, 1], [1, -1]]))
        self.assertTrue(
            PBR([[1], [1, 2, -1]], [[1], [2, -1, 1]]) < PBR([[1], [2]],
                                                            [[-1], [-2]]))
        self.assertTrue(
            PBR([[1, -1, 3], [-2, -1, 2], [3, -2]], [[2], [-2], [1, -1, 2]]) >
            PBR([[1, -1], [-2, -1, 2]], [[2], [-2]]))
        self.assertTrue(
            PBR([[1, -1, 3], [-2, -1, 2], [3, -2]], [[2], [-2], [1, -1, 2]]) >=
            PBR([[1, -1], [-2, -1, 2]], [[2], [-2]]))
        self.assertTrue(
            PBR([[1, -1], [-2, -1, 2]], [[2], [-2]]) <= PBR(
                [[1, -1], [-2, -1, 2]], [[2], [-2]]))

        with self.assertRaises(TypeError):
            (PBR([[1, -1, 3], [-2, -1, 2], [3, -2]],
                 [[2], [-2], [1, -1, 2]]) == Bipartition([1, -1], [2, 3, -2],
                                                         [-3]))
        with self.assertRaises(TypeError):
            PBR([[1, -1], [-2, -1]], [[1], [-2, -1]]) < Transformation([0, 1])
        with self.assertRaises(TypeError):
            (PBR([[1, -1], [-2, -1]], [[1], [-2, -1]]) != PartialPerm(
                [0, 1], [1, 0], 2))
        with self.assertRaises(TypeError):
            PBR([[1, -1]], [[1]]) < 3
Exemple #11
0
 def test_mul(self):
     (self.assertEqual(
         PartialPerm([0, 1], [0, 1], 2) * PartialPerm([0, 1], [0, 1], 2),
         PartialPerm([0, 1], [0, 1], 2),
     ))
     (self.assertEqual(
         PartialPerm([1, 2, 4, 6, 7, 23], [0, 5, 2, 4, 6, 7], 26) *
         PartialPerm([2, 4, 3, 5, 0, 19], [7, 8, 2, 3, 23, 0], 26),
         PartialPerm([1, 2, 4, 6], [23, 3, 7, 8], 26),
     ))
     (self.assertEqual(
         PartialPerm([0, 3, 7, 2], [5, 7, 1, 3], 8) *
         PartialPerm([4, 7, 3, 6], [5, 0, 3, 2], 8),
         PartialPerm([2, 3], [3, 0], 8),
     ))
Exemple #12
0
    def test_init(self):
        FroidurePin(Transformation([1, 0, 1]), Transformation([0, 0, 0]))

        with self.assertRaises(KeyError):
            FroidurePin()

        with self.assertRaises(ValueError):
            FroidurePin(PartialPerm([1, 2], [0, 1], 3), Transformation([0, 1]))

        with self.assertRaises(TypeError):
            FroidurePin({2, 3})
 def test_repr(self):
     self.assertEqual(
         eval(PartialPerm([0, 3, 4, 2], [2, 4, 1, 3], 5).__repr__()),
         PartialPerm([0, 3, 4, 2], [2, 4, 1, 3], 5))
     self.assertEqual(eval(PartialPerm([1, 4, 2], [2, 3, 4], 6).__repr__()),
                      PartialPerm([1, 4, 2], [2, 3, 4], 6))
     self.assertEqual(eval(PartialPerm([1, 2, 3], [2, 1, 0], 5).__repr__()),
                      PartialPerm([1, 2, 3], [2, 1, 0], 5))
Exemple #14
0
        def test_init(self):
            ReportGuard(False)
            S = Konieczny(Transformation([1, 0, 1]), Transformation([0, 0, 0]))
            self.assertEqual(S.size(), 4)
            self.assertEqual(S.number_of_generators(), 2)

            with self.assertRaises(KeyError):
                Konieczny()

            with self.assertRaises(ValueError):
                Konieczny(PartialPerm([1, 2], [0, 1], 3),
                          Transformation([0, 1]))

            with self.assertRaises(TypeError):
                Konieczny({2, 3})
 def test_identity(self):
     self.assertEqual(
         PartialPerm([0, 1], [1, 0], 2).identity(),
         PartialPerm([0, 1], [0, 1], 2))
     self.assertEqual(
         PartialPerm([1, 2, 4, 6, 7, 3], [0, 5, 2, 4, 6, 7], 8).identity(),
         PartialPerm([0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], 8))
     self.assertEqual(
         PartialPerm([0, 3, 4, 2], [2, 4, 1, 3], 5).identity(),
         PartialPerm([0, 1, 2, 3, 4], [0, 1, 2, 3, 4], 5))
    def test_mul(self):
        (self.assertEqual(
            Transformation([1, 3, 2, 1]) * Transformation([0, 3, 2, 2]),
            Transformation([3, 2, 2, 3])))
        self.assertEqual(
            Transformation([2, 2, 2]) * Transformation([1, 0, 1]),
            Transformation([1, 1, 1]))
        (self.assertEqual(
            Transformation([0, 1, 2, 3, 4, 5]) *
            Transformation([3, 2, 2, 3, 1, 4]),
            Transformation([3, 2, 2, 3, 1, 4])))

        with self.assertRaises(TypeError):
            Transformation([0, 2, 1]) * PartialPerm([0, 1], [1, 2], 3)
        with self.assertRaises(TypeError):
            Transformation([0, 2, 1]) * Bipartition([1, -1], [2, 3, -3], [-2])
        with self.assertRaises(TypeError):
            Transformation([0, 1, 2, 3, 4, 5]) * 8

        with self.assertRaises(ValueError):
            Transformation([0, 2, 1]) * Transformation([1, 2, 3, 0])
    def test_mul(self):
        (self.assertEqual(
            Bipartition([1, -1, 2, -2]) * Bipartition([1, -1, 2, -2]),
            Bipartition([1, 2, -1, -2])))
        (self.assertEqual(
            Bipartition([1, 2], [-1], [-2]) * Bipartition([1, -1], [2, -2]),
            Bipartition([1, 2], [-1], [-2])))
        (self.assertEqual(
            Bipartition([1, -1], [2, 3, -2], [-3]) *
            Bipartition([1, 3, 2, -3], [-2], [-1]),
            Bipartition([1, 2, 3, -3], [-1], [-2])))

        with self.assertRaises(TypeError):
            (Bipartition([1, -1], [2, 3, -3], [-2]) *
             PartialPerm([0, 1], [1, 2], 3))
        with self.assertRaises(TypeError):
            Transformation([0, 2, 1]) * Bipartition([1, -1], [2, 3, -3], [-2])
        with self.assertRaises(TypeError):
            Bipartition([1, -1], [2, 3, -3], [-2]) * 26

        with self.assertRaises(ValueError):
            (Bipartition([1, -1], [2, 3, -3], [-2]) *
             Bipartition([1, -1, 2, -2]))
    def test_mul(self):
        (self.assertEqual(
            PartialPerm([0, 1], [0, 1], 2) * PartialPerm([0, 1], [0, 1], 2),
            PartialPerm([0, 1], [0, 1], 2)))
        (self.assertEqual(
            PartialPerm([1, 2, 4, 6, 7, 23], [0, 5, 2, 4, 6, 7], 26) *
            PartialPerm([2, 4, 3, 5, 0, 19], [7, 8, 2, 3, 23, 0], 26),
            PartialPerm([1, 2, 4, 6], [23, 3, 7, 8], 26)))
        (self.assertEqual(
            PartialPerm([0, 3, 7, 2], [5, 7, 1, 3], 8) *
            PartialPerm([4, 7, 3, 6], [5, 0, 3, 2], 8),
            PartialPerm([2, 3], [3, 0], 8)))

        with self.assertRaises(TypeError):
            PartialPerm([0, 1], [0, 1], 2) * Transformation([0, 1])
        with self.assertRaises(TypeError):
            PartialPerm([0, 1], [0, 1], 2) * Bipartition([-2, 1], [-1, 2])

        with self.assertRaises(ValueError):
            PartialPerm([1, 2], [0, 1], 3) * PartialPerm([1, 2], [0, 1], 4)
Exemple #19
0
 def test_richcmp(self):
     self.assertEqual(PartialPerm([1, 2, 3], [2, 1, 0], 5),
                      PartialPerm([1, 2, 3], [2, 1, 0], 5))
     self.assertFalse(
         PartialPerm([1, 2, 3], [2, 1, 0], 5) != PartialPerm([1, 2, 3],
                                                             [2, 1, 0], 5))
     self.assertFalse(
         PartialPerm([1, 2, 4], [2, 1, 0], 5) == PartialPerm([1, 2, 3],
                                                             [2, 3, 0], 5))
     self.assertNotEqual(PartialPerm([1, 2, 4], [2, 1, 0], 5),
                         PartialPerm([1, 2, 3], [2, 3, 0], 5))
     self.assertFalse(
         PartialPerm([1, 2, 4], [2, 1, 0], 5) < PartialPerm([1, 2, 3],
                                                            [2, 3, 0], 5))
     self.assertLess(PartialPerm([1, 2], [0, 1], 3),
                     PartialPerm([2, 0], [0, 1], 3))
     self.assertFalse(
         PartialPerm([1, 2], [0, 1], 3) > PartialPerm([2, 0], [0, 1], 3))
     self.assertGreater(PartialPerm([1, 2], [1, 2], 3),
                        PartialPerm([1, 2], [0, 1], 3))
     self.assertGreaterEqual(PartialPerm([1, 2], [1, 2], 3),
                             PartialPerm([1, 2], [0, 1], 3))
     self.assertLessEqual(PartialPerm([1, 2, 3], [2, 1, 0], 5),
                          PartialPerm([1, 2, 3], [2, 1, 0], 5))
 def test_init_dom_ran(self):
     X = PartialPerm([0, 1, 3], [0, 2, 4], 5)**2
     X._init_dom_ran()
     self.assertTrue(X._range is not None)
     self.assertTrue(X._domain is not None)
 def test_init(self):
     PartialPerm([1, 0, 2], [2, 0, 1], 3)
     PartialPerm([1, 0], [0, 1], 5)
     PartialPerm([0, 3, 4, 5, 8, 20, 23373],
                 [1, 2, 34, 23423, 233, 432, 26], 26260)
    def test_init_fail(self):
        with self.assertRaises(TypeError):
            PartialPerm([1, 3], [0, 1], 3)
        with self.assertRaises(TypeError):
            PartialPerm([1, 2], [3, 2], 3)
        with self.assertRaises(TypeError):
            PartialPerm([-2, 2], [0, 1], 3)
        with self.assertRaises(TypeError):
            PartialPerm([1, 2], [-1, 2], 3)
        with self.assertRaises(TypeError):
            PartialPerm([1, 2], [2, 2], 3)
        with self.assertRaises(TypeError):
            PartialPerm([1, 1], [0, 2], 3)
        with self.assertRaises(TypeError):
            PartialPerm([], [], -1)
        with self.assertRaises(TypeError):
            PartialPerm([1, 2], [0, 1, 2], 3)

        with self.assertRaises(TypeError):
            PartialPerm([1, 2], [0, 'i'], 3)
        with self.assertRaises(TypeError):
            PartialPerm([1, [0]], [1, 2], 3)
        with self.assertRaises(TypeError):
            PartialPerm([0, 1], [2, 3], [4])
        with self.assertRaises(TypeError):
            PartialPerm([0, 1], [2, 3], 4.3)
 def test_dealloc(self):
     t = PartialPerm([0, 1], [1, 0], 2)
     del t
     with self.assertRaises(NameError):
         t
    def test_richcmp(self):
        self.assertEqual(PartialPerm([1, 2, 3], [2, 1, 0], 5),
                         PartialPerm([1, 2, 3], [2, 1, 0], 5))
        self.assertFalse(
            PartialPerm([1, 2, 3], [2, 1, 0], 5) != PartialPerm([1, 2, 3],
                                                                [2, 1, 0], 5))
        self.assertFalse(
            PartialPerm([1, 2, 4], [2, 1, 0], 5) == PartialPerm([1, 2, 3],
                                                                [2, 3, 0], 5))
        self.assertNotEqual(PartialPerm([1, 2, 4], [2, 1, 0], 5),
                            PartialPerm([1, 2, 3], [2, 3, 0], 5))
        self.assertFalse(
            PartialPerm([1, 2, 4], [2, 1, 0], 5) < PartialPerm([1, 2, 3],
                                                               [2, 3, 0], 5))
        self.assertLess(PartialPerm([1, 2], [0, 1], 3),
                        PartialPerm([2, 0], [0, 1], 3))
        self.assertFalse(
            PartialPerm([1, 2], [0, 1], 3) > PartialPerm([2, 0], [0, 1], 3))
        self.assertGreater(PartialPerm([1, 2], [1, 2], 3),
                           PartialPerm([1, 2], [0, 1], 3))
        self.assertGreaterEqual(PartialPerm([1, 2], [1, 2], 3),
                                PartialPerm([1, 2], [0, 1], 3))
        self.assertLessEqual(PartialPerm([1, 2, 3], [2, 1, 0], 5),
                             PartialPerm([1, 2, 3], [2, 1, 0], 5))

        with self.assertRaises(TypeError):
            (PartialPerm([1, 2], [2, 1], 3) == Bipartition([1, -1], [2, 3, -2],
                                                           [-3]))
        with self.assertRaises(TypeError):
            PartialPerm([0, 1], [0, 1], 2) < Transformation([0, 1])
        with self.assertRaises(TypeError):
            PartialPerm([0, 1], [0, 1], 2) != Transformation([0, 1])
    def test_pow(self):
        self.assertEqual(
            PartialPerm([0, 1], [0, 1], 2)**20, PartialPerm([0, 1], [0, 1], 2))
        self.assertEqual(
            PartialPerm([1, 2, 4, 6, 7, 23], [0, 5, 2, 4, 6, 7], 26)**5,
            PartialPerm([23], [5], 26))
        self.assertEqual(
            PartialPerm([0, 3, 7, 2], [5, 7, 1, 3], 8)**10,
            PartialPerm([], [], 8))
        self.assertEqual(
            PartialPerm([1, 2, 4, 6, 7, 23], [0, 5, 2, 4, 6, 7], 26)**0,
            PartialPerm([], [], 26).identity())

        with self.assertRaises(ValueError):
            PartialPerm([1, 2], [0, 1], 3)**-1
        with self.assertRaises(TypeError):
            PartialPerm([0, 1], [0, 1], 2)**1.5
        with self.assertRaises(TypeError):
            PartialPerm([1, 4, 2], [2, 3, 4], 6)**'a'