示例#1
0
def test_de_Morgan():
    x = ("Not(Or(a,b))")
    y = Parser()
    x = y.create_term(x)
    x = y.de_morgan(x)
    assert x.operator == "And"
    assert x.parameters[0].operator == "Not"
    assert x.parameters[1].operator == "Not"
    assert x.parameters[0].parameters[0].operator == "a"
    assert x.parameters[1].parameters[0].operator == "b"
    x = "Not(Not(a))"
    x = y.create_term(x)
    x = y.de_morgan(x)
    assert x.operator == "a"
    x = ("Not(And(a,b))")
    x = y.create_term(x)
    x = y.de_morgan(x)
    assert x.operator == "Or"
    assert x.parameters[0].operator == "Not"
    assert x.parameters[1].operator == "Not"
    assert x.parameters[0].parameters[0].operator == "a"
    assert x.parameters[1].parameters[0].operator == "b"
    x = "Not(Impl(a,b))"
    x = y.create_term(x)
    assert x.operator == "Not"
    x = y.de_morgan(x)
    assert x.operator == "Not"
    assert x.parameters[0].operator == "Impl"
    x = "Not(Not(a))"
    x = y.create_term(x)
    x = y.de_morgan(x)
    assert x.operator == "a"
示例#2
0
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"
示例#3
0
def test_applyDistributiveLaw():
    y = Parser()
    x = "Or(And(a,b),c)"
    x = y.create_term(x)
    x = y.apply_distributive_law(x)
    assert x.operator == "And"
    assert x.parameters[0].operator == "Or"
    assert x.parameters[0].parameters[0].operator == "a"
    assert x.parameters[0].parameters[1].operator == "c"
    x = "Or(c,And(a,b))"
    x = y.create_term(x)
    x = y.apply_distributive_law(x)
    assert x.operator == "And"
    assert x.parameters[0].operator == "Or"
    assert x.parameters[0].parameters[0].operator == "a"
    assert x.parameters[0].parameters[1].operator == "c"
    x = "Or(And(a,b),And(Impl(a,b),c))"
    x = y.create_term(x)
    x = y.apply_distributive_law(x)
    assert x.operator == "And"
    assert x.parameters[0].operator == "And"
    assert x.parameters[0].parameters[0].operator == "Or"
    assert x.parameters[0].parameters[1].operator == "Or"
    assert x.parameters[1].parameters[0].operator == "Or"
    assert x.parameters[1].parameters[1].operator == "Or"
    assert x.parameters[0].parameters[0].parameters[0].operator == "a"
    assert x.parameters[0].parameters[0].parameters[1].operator == "Impl"
    assert x.parameters[0].parameters[1].parameters[0].operator == "a"
    assert x.parameters[0].parameters[1].parameters[1].operator == "c"
    assert x.parameters[1].parameters[0].parameters[0].operator == "b"
    assert x.parameters[1].parameters[0].parameters[1].operator == "Impl"
    assert x.parameters[1].parameters[1].parameters[0].operator == "b"
    assert x.parameters[1].parameters[1].parameters[1].operator == "c"
示例#4
0
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)
示例#5
0
def test_replace_implication():
    x = "Impl(a,b)"
    y = Parser()
    x = y.create_term(x)
    x = y.replace_implication(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"
 def _call(self, city):
     response = requests.get(f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={API_KEY}")
     if not response.ok:
         return "not_found"
     parsed = Parser().parse(response.json())#class exctracting needed params and returns a dict
     obj = ApiRequests(city=parsed['city'], sky=parsed['sky'],
                 temperature=parsed['temperature'], pressure=parsed['pressure'],
                 humidity=parsed['humidity'], windspeed=parsed['windspeed'],
                 updated=datetime.strptime(parsed['updated'], '%Y-%m-%d %H:%M:%S'))
     db.session.add(obj)
     db.session.commit()
     self.weather = {"city" : parsed['city'], 'sky': parsed['sky'],
                 'temperature': parsed['temperature'], 'pressure': parsed['pressure'],
                 'windspeed': parsed['windspeed'],
                 'humidity': parsed['humidity']}
     return parsed
示例#7
0
def test_get_all_models():
    p = Parser()
    y = "a"
    p.get_all_models(y)
    file = open("allmodels", "r")
    content = file.read()
    assert "1 0" == content
    file.close()
    file = open("allmodels", "w+")
    file.close()
    y = "And(a,b)"
    p.get_all_models(y)
    file = open("allmodels", "r")
    content = file.read()
    assert "1 ß 0" == content
    file.close()
    file = open("allmodels", "w+")
    file.close()
示例#8
0
def test_isClause():
    x = "Not(Or(a,b))"
    y = Parser()
    x = y.create_term(x)
    b = y.is_clause(x)
    assert False == b
    x = "And(Or(a,b))"
    x = y.create_term(x)
    b = y.is_clause(x)
    assert False == b
    x = "Or(Or(a,b),v)"
    x = y.create_term(x)
    b = y.is_clause(x)
    assert True == b
    x = "Or(Or(And(a,b)),v)"
    x = y.create_term(x)
    b = y.is_clause(x)
    assert False == b
示例#9
0
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"
示例#10
0
import subprocess
from Core.Parser import Parser

#y = "Or(Or(a,b),Or(d,c))"
y = "Or(Not(a),b)"
#y = "a"
#y = "Impl(Or(a,b),c)"
#x = Parser.convert_formula_to_dmacs(y)
z = Parser()
f = "Impl(BOT,a)"
f = "And(BOT,a)"
f = "And(b,Impl(BOT,a))"
f = "And(b,BOT)"
f = "And(And(Impl(a,b),Impl(b,a)),Impl(TOP,a))"

#f = Parser.create_term(f)

f = Parser.convert_formula_to_dmacs(f, True)
x = 1
#if content == prob:
#        print("yes")
#else:
#print("no")f
#print(content2)
#print(prob)
#y= Parser.convert_formula_to_dmacs(y)
#print(y)
示例#11
0
def test_create_term():
    p = Parser()
    x = "Or(a,b)"
    x = p.create_term(x)
    assert x.operator == "Or"
    assert len(x.parameters) == 2
    assert x.parameters[0].operator == "a"
    assert x.parameters[1].operator == "b"
    n = "Not(f)"
    n = p.create_term(n)
    assert n.operator == "Not"
    assert len(n.parameters) == 1
    assert n.parameters[0].operator == "f"
    phi = "And(Or(x,b),y)"
    phi = p.create_term(phi)
    assert phi.operator == "And"
    assert len(phi.parameters) == 2
    assert phi.parameters[0].operator == "Or"
    assert phi.parameters[1].operator == "y"
    psi = "BiImpl(Or(x,b),y)"
    psi = p.create_term(psi)
    assert psi.operator == "BiImpl"
    assert len(psi.parameters) == 2
    assert psi.parameters[0].operator == "Or"
    assert psi.parameters[1].operator == "y"
    x = "Impl(Or(a,b),n)"
    x = p.create_term(x)
    assert x.operator == "Impl"
    assert len(x.parameters) == 2
    assert x.parameters[0].operator == "Or"
    assert x.parameters[1].operator == "n"
    x = "Impl(And(a,b),n)"
    x = p.create_term(x)
    assert len(x.parameters) == 2
    assert x.parameters[0].operator == "And"
    assert x.parameters[1].operator == "n"
    x = "Impl(Not(a),n)"
    x = p.create_term(x)
    assert len(x.parameters) == 2
    assert x.parameters[0].operator == "Not"
    assert x.parameters[1].operator == "n"
    assert len(x.parameters[0].parameters) == 1
    x = "Not(Or(a,n))"
    x = p.create_term(x)
    assert x.parameters[0].operator == "Or"
    assert x.operator == "Not"
    x = "Not(And(a,n))"
    x = p.create_term(x)
    assert x.parameters[0].operator == "And"
    assert x.operator == "Not"
    x = "Not(Impl(a,n))"
    x = p.create_term(x)
    assert x.parameters[0].operator == "Impl"
    assert x.operator == "Not"
    x = "Or(And(a,b),And(x,y))"
    x = p.create_term(x)
    assert x.operator == "Or"
    assert x.parameters[0].operator == "And"
    assert x.parameters[1].operator == "And"
    x = "Or(And(Not(a),b),And(x,y))"
    x = p.create_term(x)
    assert x.operator == "Or"
    assert x.parameters[0].operator == "And"
    assert x.parameters[1].operator == "And"