Example #1
0
 def test_alphabet(self):
     with self.assertRaises(ValueError):
         FpSemigroup('', [['a', 'aa']])
     with self.assertRaises(ValueError):
         FpSemigroup('a', [['b', 'aa']])
     with self.assertRaises(ValueError):
         FpSemigroup('aa', [['b', 'aa']])
Example #2
0
 def test_ne_(self):
     FpS = FpSemigroup("ab", [["a^10", "a"], ["bbb", "b"], ["ba", "ab"]])
     a = "aba"
     b = a + a
     self.assertFalse(FpS.equal(a, b))
     a = "aaba"
     b = "ba^4"
     self.assertFalse(FpS.equal(a, b))
Example #3
0
 def test_equal(self):
     S = FpSemigroup("ab", [["a", "a^5"], ["b", "bb"], ["ab", "ba"]])
     self.assertTrue(S.equal("a", "a^5"))
     self.assertTrue(S.equal("a", "aaaaa"))
     self.assertTrue(S.equal("abb", "ba"))
     self.assertTrue(S.equal("ab", "((a)^3b)^167"))
     S = FpSemigroup("ab", [])
     with self.assertRaises(ValueError):
         S.equal("a", "b")
Example #4
0
 def test_eq_(self):
     FpS = FpSemigroup("ab", [["a^10", "a"], ["bbb", "b"], ["ba", "ab"]])
     a = "aba"
     b = a
     self.assertTrue(FpS.equal(a, b))
     a = "aaba"
     b = "ba^3"
     self.assertTrue(FpS.equal(a, b))
     a = ""
     self.assertEqual(a, a)
Example #5
0
 def test_mul(self):
     FpS = FpSemigroup("ab", [["aa", "a"], ["bbb", "b"], ["ba", "ab"]])
     other = "aa"
     a = FpS[1].get_value()
     a * a
     self.assertEqual(a.word + a.word, (a * a).word)
     with self.assertRaises(TypeError):
         a * other
     with self.assertRaises(TypeError):
         FpSemigroup("a", [["aa", "a"]])[0].get_value() * a
Example #6
0
 def test_size(self):
     S = FpSemigroup("a", [["a", "aa"]])
     self.assertEqual(S.size(), 1)
     S = FpSemigroup("ab", [["a", "aa"], ["b", "bb"], ["ab", "ba"]])
     self.assertEqual(S.size(), 3)
     S = FpSemigroup("ab", [])
     self.assertEqual(S.size(), float("inf"))
Example #7
0
 def test_is_finite(self):
     S = FpSemigroup("ab", [["a", "aa"], ["b", "bb"], ["ab", "ba"]])
     self.assertEqual(S.is_finite(), True)
     S = FpSemigroup("ab", [])
     self.assertEqual(S.is_finite(), False)
     S = FpSemigroup("ab", [["a", "a"], ["a", "a"]])
     self.assertEqual(S.is_finite(), False)
Example #8
0
 def test_rels(self):
     with self.assertRaises(TypeError):
         FpSemigroup("ab", "[\"a\", \"aa\"]")
     with self.assertRaises(TypeError):
         FpSemigroup("ab", ["\"b", "aa\""])
     with self.assertRaises(TypeError):
         FpSemigroup("ab", [["a", "aa", "b"]])
     with self.assertRaises(TypeError):
         FpSemigroup("ab", [["b", ["a", "a"]]])
     with self.assertRaises(ValueError):
         FpSemigroup("ab", [["b", "ca"]])
Example #9
0
 def test_nridempotents(self):
     S = FpSemigroup("ab", [["a", "a^5"], ["b", "bb"], ["ab", "ba"]])
     self.assertEqual(S.nridempotents(), 3)
     S = FpMonoid("ab", [["a", "a^5"], ["b", "bb"], ["ab", "ba"]])
     self.assertEqual(S.nridempotents(), 4)
     S = FpSemigroup("ab", [])
     with self.assertRaises(ValueError):
         S.nridempotents()
Example #10
0
 def test_normal_form(self):
     S = FpSemigroup("a", [["a", "aa"]])
     self.assertEqual(S.normal_form("a^1000"), "a")
     S = FpMonoid("a", [["a", "aa"]])
     self.assertEqual(S.normal_form("a^0"), "1")
     S = FpSemigroup("ab", [["a", "aaa"], ["b", "bb"], ["ab", "ba"]])
     self.assertEqual(S.normal_form("(ba)^10"), "aab")
 def test_contains(self):
     FpS = FpSemigroup("ab", [["aa", "a"], ["bbb", "b"], ["ba", "ab"]])
     with self.assertRaises(ValueError):
         1 in FpS
     self.assertTrue("abb" in FpS)
     self.assertFalse("c" in FpS)
     self.assertFalse("" in FpS)
Example #12
0
 def test_identity(self):
     FpS = FpSemigroup("ab", [["a^10", "a"], ["bbb", "b"], ["ba", "ab"]])
     a = FpS[0].get_value()
     self.assertEqual(a.identity().word, "")
     FpS = FpMonoid("ab", [["a^10", "a"], ["bbb", "b"], ["ba", "ab"]])
     a = FpS[1].get_value()
     self.assertEqual(a.identity().word, "1")
Example #13
0
    def test_word_to_class_index_str(self):
        S = FpSemigroup(["a", "b"], [["a", "aa"], ["b", "bb"], ["ab", "ba"]])

        self.assertIsInstance(S.word_to_class_index("aba"), int)

        with self.assertRaises(TypeError):
            S.word_to_class_index([1, "0"])

        with self.assertRaises(TypeError):
            S.word_to_class_index(["aba"])

        self.assertEqual(S.word_to_class_index("aba"),
                         S.word_to_class_index("abaaabb"))
Example #14
0
 def test_valid_init(self):
     with self.assertRaises(TypeError):
         FpSemigroup(['a'], [])
     with self.assertRaises(ValueError):
         FpSemigroup('aa', [])
     with self.assertRaises(TypeError):
         FpSemigroup('a', []).check_word({})
     FpSemigroup('a', [])
     FpSemigroup('~', [])
     FpSemigroup('a', [['a', 'aa']])
     FpSemigroup('ab', [['b', 'a(a)']])
     FpSemigroup('a', [['a', 'a^4']])
     FpSemigroup('ab', [['b', '(ab)^2a']])
Example #15
0
 def test_current_max_word_length(self):
     S = FpSemigroup("ab", [["a", "a^5"], ["b", "bb"], ["ab", "ba"]])
     S.current_max_word_length()
Example #16
0
 def test_set_report(self):
     S = FpSemigroup("a", [["a", "aa"]])
     S.set_report(True)
     S.set_report(False)
     with self.assertRaises(TypeError):
         S.set_report("False")
Example #17
0
 def test_repr(self):
     FpS = FpSemigroup("ab", [["aa", "a"], ["bbb", "b"], ["ab", "ba"]])
     self.assertEqual(FpS[0].__repr__(),
                      "'" + FpS[0].get_value().Repword + "'")
Example #18
0
 def test_contains(self):
     FpS = FpSemigroup("ab", [["aa", "a"], ["bbb", "b"], ["ba", "ab"]])
     self.assertFalse(1 in FpS)
     self.assertTrue("abb" in FpS)
     self.assertFalse("c" in FpS)
     self.assertFalse("" in FpS)
Example #19
0
 def test_parse_word(self):
     S = FpSemigroup('~', [])
     self.assertFalse(S._pure_letter_alphabet)
     self.assertEqual(S._parse_word("~"), "~")
     S = FpSemigroup('a', [])
     self.assertEqual(S._parse_word("aa"), "aa")
     self.assertEqual(S._parse_word("()(()())"), "")
     self.assertEqual(S._parse_word("ba^10b"), "baaaaaaaaaab")
     self.assertEqual(S._parse_word("((b)a)^3b"), "bababab")
     with self.assertRaises(ValueError):
         S._parse_word(")(")
     with self.assertRaises(ValueError):
         S._parse_word("(((b)^2(a))))")
     with self.assertRaises(ValueError):
         S._parse_word("(((b)^2)))((((a))(b))")
     with self.assertRaises(ValueError):
         S._parse_word("^2")
     with self.assertRaises(ValueError):
         S._parse_word("a^")
     with self.assertRaises(ValueError):
         S._parse_word("a^a")
Example #20
0
 def test_enumerate(self):
     S = FpSemigroup("ab", [["a", "a^5"], ["b", "bb"], ["ab", "ba"]])
     S.enumerate(73)
     S = FpSemigroup("ab", [])
     with self.assertRaises(ValueError):
         S.enumerate(73)
Example #21
0
 def test_size_str(self):
     S = FpSemigroup(["a"], [["a", "aa"]])
     self.assertEqual(S.size(), 1)
     S = FpSemigroup(["a", "b"], [["a", "aa"], ["b", "bb"], ["ab", "ba"]])
     self.assertEqual(S.size(), 3)
Example #22
0
 def test_factorisation(self):
     S = FpSemigroup("ab", [["a", "a^5"], ["b", "bb"], ["ab", "ba"]])
     self.assertEqual(S.factorisation("aba"), [0, 0, 1])
     S = FpSemigroup("ab", [])
     with self.assertRaises(ValueError):
         S.factorisation("aba")
Example #23
0
 def test_repr(self):
     S = FpSemigroup("ab", [["aa", "a"], ["bbb", "ab"], ["ab", "ba"]])
     self.assertEqual(S.__repr__(),
                      "<fp semigroup with 2 generators and 3 relations>")
Example #24
0
 def test_valid_init(self):
     FpS = FpSemigroup("ab", [["aa", "a"], ["bbb", "b"], ["ba", "ab"]])
     FpS.equal("a", "aba")
     FpS = FpSemigroup("mo", [["m", "mm"], ["ooo", "o"], ["mo", "om"]])
     FpS.equal("moo", "ooo")
     FpS = FpSemigroup(
         "cowie",
         [["c", "o"], ["o", "w"], ["w", "i"], ["i", "e"], ["ee", "e"]])
     FpS.equal("cowie", "cowie")
     FpS2 = FpSemigroup('~', [["~~", "~"]])
     FpS2.equal("~", "~~")
     with self.assertRaises(TypeError):
         FpS.equal(FpS, FpS)
     with self.assertRaises(ValueError):
         FpS.equal("abc", "abc")
Example #25
0
 def test_valid_init(self):
     FpSemigroup(['a'], [])
     FpSemigroup(['a'], [['a', 'aa']])
     FpSemigroup(['a', 'b'], [['b', 'aa']])