def test_alphabet(self): with self.assertRaises(ValueError): FpMonoid("", [["a", "aa"]]) with self.assertRaises(ValueError): FpMonoid("a", [["b", "aa"]]) with self.assertRaises(ValueError): FpMonoid("aa", [["b", "aa"]])
def test_rels(self): with self.assertRaises(TypeError): FpMonoid("ab", "[\"a\", \"aa\"]") with self.assertRaises(TypeError): FpMonoid("ab", ["\"b\", \"aa\""]) with self.assertRaises(TypeError): FpMonoid("ab", [["a", "aa", "b"]]) with self.assertRaises(TypeError): FpMonoid("ab", [["b", ["a", "a"]]]) with self.assertRaises(ValueError): FpMonoid("ab", [["b", "ca"]])
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_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")
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()
def test_valid_init(self): FpMonoid("", []) FpMonoid("a", []) with self.assertRaises(ValueError): FpMonoid("1", []) FpMonoid("a", [["a", "aa"]]) FpMonoid("ab", [["b", "aa"]]) FpMonoid("ab", [["1", "aa"]]) FpMonoid("ab", [["b", "a^2"]]) FpMonoid("ab", [["1", "(a)^6"]])
def test_word_to_class_index(self): M = FpMonoid("ab", [["a", "aa"], ["b", "bb"], ["ab", "ba"]]) self.assertEqual(M.word_to_class_index('a'), M.word_to_class_index('aa')) self.assertNotEqual(M.word_to_class_index('a'), M.word_to_class_index('bb')) self.assertIsInstance(M.word_to_class_index('aba'), int)
def test_repr(self): M = FpMonoid("ab", [["aa", "a"], ["bbb", "ab"], ["ab", "ba"]]) self.assertEqual(M.__repr__(), "<fp monoid with 2 generators and 3 relations>")
def test_size(self): self.assertEqual(FpMonoid("a", [["a", "aa"]]).size(), 2) self.assertEqual( FpMonoid("ab", [["a", "aa"], ["b", "bb"], ["ab", "ba"]]).size(), 4)
def test_set_report(self): M = FpMonoid("a", [["a", "aa"]]) M.set_report(True) M.set_report(False) with self.assertRaises(TypeError): M.set_report("False")
def test_contains(self): FpM = FpMonoid("ab", [["aa", "a"], ["bbb", "b"], ["ba", "ab"]]) self.assertFalse(1 in FpM) self.assertTrue("abb" in FpM) self.assertTrue("" in FpM)
def test_contains(self): FpM = FpMonoid("ab", [["aa", "a"], ["bbb", "b"], ["ba", "ab"]]) with self.assertRaises(ValueError): 1 in FpM self.assertTrue("abb" in FpM) self.assertTrue("" in FpM)
def test_valid_init(self): FpMonoid([], []) FpMonoid(["a"], []) FpMonoid(["a"], [["a", "aa"]]) FpMonoid(["a", "b"], [["b", "aa"]]) FpMonoid(["a", "b"], [["1", "aa"]])