def test_generate_formula_tree_op0(self): tree_list = fg.generate_formula_tree('0', 0, True) expected_formula_list = ['x0 < p0', 'x0 > p0'] self.assertSetEqual(set(expected_formula_list), set(tree_list)) tree_list = fg.generate_formula_tree(['0'], 0, True, ['0']) expected_formula_list = ['x0 = p0'] self.assertSetEqual(set(expected_formula_list), set(tree_list))
def test_generate_formula_tree_op1(self): tree_list = fg.generate_formula_tree([0], 1, True) expected_formula_list = [ '! ( x0 < p0 )', '! ( x0 > p0 )', '( x0 < p0 ) & ( x0 < p0 )', '( x0 < p0 ) & ( x0 > p0 )', '( x0 > p0 ) & ( x0 < p0 )', '( x0 > p0 ) & ( x0 > p0 )', '( x0 < p0 ) | ( x0 < p0 )', '( x0 < p0 ) | ( x0 > p0 )', '( x0 > p0 ) | ( x0 < p0 )', '( x0 > p0 ) | ( x0 > p0 )', 'P pP pP ( x0 < p0 )', 'P pP pP ( x0 > p0 )', 'A pA pA ( x0 < p0 )', 'A pA pA ( x0 > p0 )', '( x0 < p0 ) S pS pS ( x0 < p0 )', '( x0 < p0 ) S pS pS ( x0 > p0 )', '( x0 > p0 ) S pS pS ( x0 < p0 )', '( x0 > p0 ) S pS pS ( x0 > p0 )' ] self.assertSetEqual(set(expected_formula_list), set(tree_list))
def test_generate_formula_tree_op2(self): tree_list = fg.generate_formula_tree('0', 2, False) count_with_0_operator = 2 count_with_1_operator = 18 count_with_2_root_binary_operator = 3 * 2 * count_with_0_operator * count_with_1_operator count_with_2_root_unary_operator = 3 * count_with_1_operator expected_formula_count = count_with_2_root_binary_operator + count_with_2_root_unary_operator self.assertEqual(len(tree_list), expected_formula_count) # A few scheck: formulas = set( ["".join(tree.to_formula().split()) for tree in tree_list]) self.assertIn("".join('A pA pA ( P pP pP (x0 < p0) )'.split()), formulas)
def test_generate_formula_tree_iterative_setValued(self): tree_list_recur = fg.generate_formula_tree([0, 1], 2, True, [0]) tree_list_iter = fg.generate_formula_tree_iterative([0, 1], 2, True, [0], False) self.assertSetEqual(set(tree_list_recur), set(tree_list_iter))
def test_generate_formula_tree_iterative_op1(self): tree_list_recur = fg.generate_formula_tree([0], 1, True) tree_list_iter = fg.generate_formula_tree_iterative([0], 1, True, [], False) self.assertSetEqual(set(tree_list_recur), set(tree_list_iter))