def test_buildString(): x = "Or(And(a,b),And(x,y))" y = Parser() x = y.create_term(x) x = y.convert_to_cnf(x) x = y.build_string(x) assert x[0] == "a"
def test_parser_hardcore(): p = Parser() comparator = TermComparator() for i in range(0, 100): term = RandomTermGenerator.generate_random_term(6, 10) term_cnf = p.convert_to_cnf(term) assert comparator.terms_are_equivalent(term, term_cnf)
def test_convertToCNF(): y = Parser() x = "a" x = y.create_term(x) x = y.convert_to_cnf(x) assert x.operator == "a" x = "Or(And(a,b),Impl(c,d))" x = y.create_term(x) x = y.convert_to_cnf(x) assert x.operator == "And" assert x.parameters[0].operator == "Or" assert x.parameters[1].operator == "Or" assert x.parameters[0].parameters[0].operator == "a" assert x.parameters[0].parameters[1].operator == "Or" x = "Not(And(a,b))" x = y.create_term(x) x = y.convert_to_cnf(x) assert x.operator == "Or" assert x.parameters[0].operator == "Not" assert x.parameters[0].parameters[0].operator == "a" assert x.parameters[1].operator == "Not" assert x.parameters[1].parameters[0].operator == "b" x = "Not(Impl(a,b))" x = y.create_term(x) x = y.convert_to_cnf(x) assert x.operator == "And" assert x.parameters[0].operator == "a" assert x.parameters[1].operator == "Not" assert x.parameters[1].parameters[0].operator == "b" x = "Not(Not(Impl(a,b)))" x = y.create_term(x) x = y.convert_to_cnf(x) assert x.operator == "Or" assert x.parameters[0].operator == "Not" assert x.parameters[0].parameters[0].operator == "a" assert x.parameters[1].operator == "b"
from Core.Parser import Parser, Term print(Parser.convert_formula_to_dmacs("And(x,y)")) #parser = Parser() megaformel1 = "Or(Impl(Not(a),And(b,Not(a))),And(d,Or(e,f)))" megaformel1AlsTerm = Parser.create_term(megaformel1) megaformel1InCnf = Parser.convert_to_cnf(megaformel1AlsTerm) print( Parser.convert_formula_to_dmacs( "Or(Impl(Not(a),And(b,Not(a))),And(d,Or(e,f)))")) megaformel2a = "Or(Impl(Not(a),And(b,Not(g))),And(d,Or(e,f)))" megaformel2 = "Impl(And(g,a)," + megaformel2a + ")" #megaforme21AlsTerm = parser.create_term(megaformel2) #megaformel1InCnf = parser.convertToCNF(megaforme21AlsTerm) print(Parser.convert_formula_to_dmacs(megaformel2))