def test_richcmp(self):
        self.assertEqual(Transformation([1, 2, 2, 0]),
                         Transformation([1, 2, 2, 0]))
        self.assertFalse(
            Transformation([1, 2, 2, 0]) == Transformation([1, 2, 1, 3]))
        self.assertNotEqual(Transformation([1, 2, 2, 0]),
                            Transformation([1, 2, 1, 3]))
        self.assertFalse(Transformation([2, 2, 1]) < Transformation([0, 1, 2]))
        self.assertGreater(Transformation([2, 2, 1]), Transformation([0, 1,
                                                                      2]))
        self.assertLessEqual(Transformation([2, 2, 1]),
                             Transformation([2, 2, 2]))
        self.assertLessEqual(Transformation([2, 2, 2]),
                             Transformation([2, 2, 2]))
        self.assertGreaterEqual(Transformation([2, 2, 2]),
                                Transformation([2, 2, 0]))
        self.assertGreaterEqual(Transformation([3, 2, 3, 0]),
                                Transformation([3, 2, 0, 1]))

        with self.assertRaises(TypeError):
            Transformation([2, 2, 0]) == 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_dealloc(self):
     A = Bipartition([1, -1, 2, -2])
     B = Bipartition([-7, -6, -5, -4], [3, 2, 1], [-3, -2, -1, 4, 5, 6, 7])
     del A, B
     with self.assertRaises(NameError):
         A
     with self.assertRaises(NameError):
         B
 def test_generator(self):
     self.assertEqual(list(Bipartition([1, 2], [-2, -1])), [0, 0, 1, 1])
     self.assertEqual(list(Bipartition([-1, -2], [2, -3], [1, 3])),
                      [0, 1, 0, 2, 2, 1])
     self.assertEqual(
         list(
             Bipartition([-7, -6, -5, -4], [3, 2, 1],
                         [-3, -2, -1, 4, 5, 6, 7])),
         [0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2])
 def test_init_fail(self):
     with self.assertRaises(ValueError):
         Bipartition([1, -1, 2])
     with self.assertRaises(ValueError):
         Bipartition([1, 2, 3], [-3, -2])
     with self.assertRaises(TypeError):
         Bipartition([0, 1, 2], [-1, -2])
     with self.assertRaises(TypeError):
         Bipartition([1, 2, 3], (-1, -2, -3))
     with self.assertRaises(TypeError):
         Bipartition(1, 2, -1, -2)
    def test_blocks1(self):
        self.assertEqual(
            Bipartition([1, 2], [-2, -1]).blocks(), [[1, 2], [-1, -2]])
        self.assertEqual(
            Bipartition([-7, -6, -5, -4], [3, 2, 1],
                        [-3, -2, -1, 4, 5, 6, 7]).blocks(),
            [[1, 2, 3], [4, 5, 6, 7, -1, -2, -3], [-4, -5, -6, -7]])
        self.assertEqual(
            Bipartition([-1, -2], [2, -3], [1, 3]).blocks(),
            [[1, 3], [2, -3], [-1, -2]])

        x = Bipartition([-1, -2], [2, -3], [1, 3])
        self.assertEqual((x * x).blocks(), [[1, 3], [2, -3], [-1, -2]])
    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(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
    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_mul(self):
        self.assertEqual(
            PBR([[1, -1]], [[1]]) * PBR([[1, -1]], [[1]]), PBR([[1, -1]],
                                                               [[1]]))
        self.assertEqual(
            PBR([[1, -1], [-2, -1]], [[1], [-2, -1]]) *
            PBR([[-1, 1, 2], [2]], [[-1, 1], [-2, 2]]),
            PBR([[1, -1], [1, -1]], [[1, -1], [1, -1, -2]]))
        self.assertEqual(
            PBR([[-1, 1, 2], [2]], [[-1, 1], [-2, 2]]) *
            PBR([[1, -1], [-2, -1]], [[1], [-2, -1]]),
            PBR([[-1, 1, 2], [2]], [[-1, 1], [-2, -1]]))
        self.assertEqual(
            PBR([[1, -1, 3], [-2, -1, 2], [3, -2]], [[2], [-2], [1, -1, 2]]) *
            PBR([[1, -1, 3], [-2, -1, 2], [3, -3, -2]],
                [[1, 2], [-2, 3, -3], [1, -1]]),
            PBR([[-1, 1, 2, 3], [-2, -1, 1, 2], [-2, -1, 3]],
                [[-2, -1, 2], [-3, -2, -1, 1, 2], [-1, 2]]))

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

        with self.assertRaises(ValueError):
            PBR([[1, -1, 3], [-2, -1, 2], [3, -2]],
                [[2], [-2], [1, -1, 2]]) * PBR([[1, -1]], [[1]])
    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_init(self):
        Semigroup(-1)
        Semigroup(Transformation([1, 0, 1]), Transformation([0, 0, 0]))

        with self.assertRaises(ValueError):
            Semigroup()

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

        with self.assertRaises(TypeError):
            Semigroup({2, 3})
 def test_repr(self):
     self.assertEqual(eval(Bipartition([1, 2], [-2, -1]).__repr__()),
                      Bipartition([1, 2], [-2, -1]))
     self.assertEqual(
         eval(Bipartition([-1, -2], [2, -3], [1, 3]).__repr__()),
         Bipartition([-1, -2], [2, -3], [1, 3]))
     self.assertEqual(
         eval(
             Bipartition([-7, -6, -5, -4], [3, 2, 1],
                         [-3, -2, -1, 4, 5, 6, 7]).__repr__()),
         Bipartition([-7, -6, -5, -4], [3, 2, 1], [-3, -2, -1, 4, 5, 6, 7]))
 def test_identity(self):
     self.assertEqual(
         Bipartition([1, 2], [-2, -1]).identity(),
         Bipartition([1, -1], [2, -2]))
     self.assertEqual(
         Bipartition([-7, -6, -5, -4], [3, 2, 1],
                     [-3, -2, -1, 4, 5, 6, 7]).identity(),
         Bipartition([1, -1], [2, -2], [3, -3], [4, -4], [5, -5], [6, -6],
                     [7, -7]))
     self.assertEqual(
         Bipartition([-1, -2], [2, -3], [1, 3]).identity(),
         Bipartition([1, -1], [2, -2], [3, -3]))
    def test_block(self):
        self.assertEqual(Bipartition([1, 2], [-2, -1]).block(-2), 1)
        self.assertEqual(
            Bipartition([-7, -6, -5, -4], [3, 2, 1],
                        [-3, -2, -1, 4, 5, 6, 7]).block(3), 0)
        self.assertEqual(Bipartition([-1, -2], [2, -3], [1, 3]).block(-1), 2)

        with self.assertRaises(IndexError):
            Bipartition([1, 2], [-2, -1]).block(-3)
        with self.assertRaises(IndexError):
            Bipartition([-7, -6, -5, -4], [3, 2, 1],
                        [-3, -2, -1, 4, 5, 6, 7]).block(26)
        with self.assertRaises(TypeError):
            Bipartition([-1, -2], [2, -3], [1, 3]).block('a')
    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)
    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_is_transverse_block(self):
        self.assertEqual(
            Bipartition([1, 2], [-2, -1]).is_transverse_block(1), False)
        self.assertEqual(
            Bipartition([-7, -6, -5, -4], [3, 2, 1],
                        [-3, -2, -1, 4, 5, 6, 7]).is_transverse_block(1), True)
        self.assertEqual(
            Bipartition([-1, -2], [2, -3], [1, 3]).is_transverse_block(1),
            True)

        with self.assertRaises(IndexError):
            Bipartition([1, 2], [-2, -1]).is_transverse_block(-3)
        with self.assertRaises(IndexError):
            Bipartition([-7, -6, -5, -4], [3, 2, 1],
                        [-3, -2, -1, 4, 5, 6, 7]).is_transverse_block(26)

        with self.assertRaises(TypeError):
            Bipartition([-1, -2], [2, -3], [1, 3]).is_transverse_block('a')
        with self.assertRaises(TypeError):
            Bipartition([-1, -2], [2, -3], [1, 3]).is_transverse_block([7, 26])
 def test_blocks2(self):
     x = Bipartition([1, 2], [-2, -1, 3], [-3])
     self.assertEqual(x.blocks(), [[1, 2], [3, -1, -2], [-3]])
     self.assertEqual((x * x.identity()).blocks(),
                      [[1, 2], [3, -1, -2], [-3]])
    def test_pow(self):
        self.assertEqual(
            Bipartition([-7, -6, -5, -4], [3, 2, 1],
                        [-3, -2, -1, 4, 5, 6, 7])**20,
            Bipartition([1, 2, 3], [4, 5, 6, 7], [-1, -2, -3],
                        [-4, -5, -6, -7]))
        self.assertEqual(
            Bipartition([1, -1, 2, -2])**26, Bipartition([1, 2, -1, -2]))
        self.assertEqual(
            Bipartition([-1, -2], [2, -3], [1, 3])**3,
            Bipartition([1, 3], [2, -3], [-1, -2]))

        with self.assertRaises(ValueError):
            Bipartition([1, -1, 2, -2])**-26

        self.assertEqual(
            Bipartition([1], [-1, 2, -2])**0,
            Bipartition([1], [-1, 2, -2]).identity())

        with self.assertRaises(TypeError):
            Bipartition([1, 2], [-1], [-2])**3.141592653589793238462643383279
        with self.assertRaises(TypeError):
            Bipartition([1, 2], [-1], [-2])**'c'
 def test_degree(self):
     self.assertEqual(Bipartition([1, 2], [-2, -1]).degree(), 2)
     self.assertEqual(
         Bipartition([-7, -6, -5, -4], [3, 2, 1],
                     [-3, -2, -1, 4, 5, 6, 7]).degree(), 7)
     self.assertEqual(Bipartition([-1, -2], [2, -3], [1, 3]).degree(), 3)
    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_init(self):
     Bipartition([-1, -2], [2, -3], [1, 3])
     Bipartition([-7, -6, -5, -4], [3, 2, 1], [-3, -2, -1, 4, 5, 6, 7])
     Bipartition([1, -1, 2, -2])
    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_nr_blocks(self):
     self.assertEqual(Bipartition([1, 2], [-2, -1]).nr_blocks(), 2)
     self.assertEqual(
         Bipartition([-7, -6, -5, -4], [3, 2, 1],
                     [-3, -2, -1, 4, 5, 6, 7]).nr_blocks(), 3)
     self.assertEqual(Bipartition([-1, -2], [2, -3], [1, 3]).nr_blocks(), 3)