def test_state(self): ReportGuard(False) S = FroidurePin(Transformation([1, 0] + list(range(2, 10)))) S.add_generator(Transformation(list(range(1, 10)) + [0])) self.assertFalse(S.started()) S.run_for(milliseconds(10)) self.assertTrue(S.started()) self.assertTrue(S.timed_out()) self.assertTrue(S.stopped()) self.assertFalse(S.finished())
def test_run_until(self): if compare_version_numbers(libsemigroups_version(), "1.0.8"): ReportGuard(False) S = FroidurePin(Transformation([1, 0] + list(range(2, 10)))) S.add_generator(Transformation(list(range(1, 10)) + [0])) S.run_until(lambda: S.current_size() > 10) self.assertFalse(S.finished()) self.assertTrue(S.current_size() > 10) S.run_until(lambda: S.current_nr_rules() > 100) self.assertFalse(S.finished()) self.assertTrue(S.current_nr_rules() > 100)
def test_membership(self): S = FroidurePin(Transformation(list(range(1, 5)) + [0])) S.add_generator(Transformation([1, 0] + list(range(2, 5)))) if compare_version_numbers(libsemigroups_version(), "1.0.8"): self.assertEqual( S.current_position(Transformation([2, 0, 3, 4, 1])), 18446744073709551615, ) self.assertEqual(S.at(10), Transformation([2, 0, 3, 4, 1])) with self.assertRaises(Exception): S.at(120) with self.assertRaises(Exception): S[120] self.assertTrue(S.contains(Transformation([2, 0, 3, 4, 1]))) self.assertEqual(S.position(Transformation([2, 0, 3, 4, 1])), 10) self.assertEqual(S.sorted_position(Transformation([2, 0, 3, 4, 1])), 51) self.assertEqual(S.sorted_at(51), Transformation([2, 0, 3, 4, 1])) if compare_version_numbers(libsemigroups_version(), "1.0.8"): self.assertEqual(S.current_position(Transformation([2, 0, 3, 4, 1])), 10)
def test_factorisation_and_relations(self): ReportGuard(False) S = FroidurePin(Transformation(list(range(1, 10)) + [0])) self.assertEqual(S.length_const(0), 1) with self.assertRaises(LibsemigroupsException): S.length_const(1) self.assertEqual(S.current_max_word_length(), 1) S.run() self.assertEqual(S.current_max_word_length(), 10) self.assertTrue(S.equal_to([0, 0], [0, 0])) self.assertFalse(S.equal_to([0], [0, 0])) self.assertFalse(S.equal_to([0] * 10, [0])) with self.assertRaises(LibsemigroupsException): self.assertFalse(S.equal_to([0] * 10, [1])) with self.assertRaises(LibsemigroupsException): self.assertFalse(S.equal_to([1], [0] * 10)) for i in range(S.size()): self.assertEqual(S.length_const(i), i + 1) self.assertEqual(S.length_non_const(i), i + 1) with self.assertRaises(LibsemigroupsException): S.length_non_const(10) self.assertEqual(S.letter_to_pos(0), 0) with self.assertRaises(LibsemigroupsException): S.letter_to_pos(1) S.add_generator(Transformation([1, 0] + list(range(2, 10)))) self.assertEqual(S.letter_to_pos(1), 10) S.add_generator(Transformation(list(range(1, 10)) + [0])) self.assertEqual(S.letter_to_pos(2), 0) self.assertEqual( [S.minimal_factorisation(x) for x in range(10)], [ [0], [0, 0], [0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1], ], ) with self.assertRaises(LibsemigroupsCppyyException): S.next_relation() S = FroidurePin(Transformation(list(range(1, 5)) + [0])) S.add_generator(Transformation([1, 0] + list(range(2, 5)))) self.assertEqual(S.current_nr_rules(), 0) self.assertEqual(S.word_to_pos([0, 1, 0, 1]), 18446744073709551615) self.assertEqual(S.nr_rules(), 25) self.assertEqual(S.word_to_element([0, 1, 0, 1]), Transformation([0, 3, 4, 1, 2])) self.assertEqual(S.word_to_pos([0, 1, 0, 1]), 15)
def test_run_for(self): ReportGuard(False) S = FroidurePin(Transformation([1, 0] + list(range(2, 10)))) S.add_generator(Transformation(list(range(1, 10)) + [0])) S.run_for(milliseconds(10))
def test_add_generator(self): ReportGuard(False) S = FroidurePin(Transformation([1, 0, 1]), Transformation([0, 0, 0])) self.assertEqual(S.size(), 4) S.add_generator(Transformation([1, 2, 0])) self.assertEqual(S.size(), 24)