dodanie kilku edge caseów

This commit is contained in:
emile 2019-05-30 20:36:52 +02:00
parent ded73fd70a
commit 427d769aa6

View File

@ -19,7 +19,7 @@ class SimpleInterpreter(AbstractInterpreter):
logic_signs = ['=', '>', '&', '|', '!', '(', ')']
return char in logic_signs
def isParentice(char):
return char in ('(', ')')
return char in ['(', ')']
def isVariable(char):
return not isSign(char)
def isNegation(char):
@ -31,13 +31,21 @@ class SimpleInterpreter(AbstractInterpreter):
prev = formula.s[i-1] if i>0 else None #None, gdy jesteśmy na pierwszym znaku
if (char=='(' and isVariable(prev) and prev is not None): #a(b|c)
return False
if (prev is None):
if not (isVariable(char) or isParentice(char) or isNegation(char)):
return False
if isSign(char):
if (not isNegation(char)):
if isSign(prev) and not isNegation(prev): # tylko negacje mogą się powtarzać po innym znaku
return False
else:
if isVariable(prev) and prev is not None: # obrona przed a!>b
return False
if isNegation(prev):
if not (isNegation(char) or isParentice(char)):
print("xd")
return False
if isVariable(prev): #a!
return False
else:
#if current char is a variable
if isVariable(prev) and prev is not None: #Obrona abc>d
@ -113,6 +121,7 @@ class ProperInterpreter(AbstractInterpreter):
if len(formula)==0:
# print("Empty subformula")
return None
if (formula=='!'): raise Exception("Negacja źle postawiona")
x=[0 for u in formula]
current_depth=0
for i,char in enumerate(formula):
@ -131,7 +140,7 @@ class ProperInterpreter(AbstractInterpreter):
if current_depth!=0:
raise Exception("Nawiasy źle umieszczone w podformule: {0}".format(formula))
#print(formula)
print(formula)
min_depth = min(x)
@ -148,7 +157,7 @@ class ProperInterpreter(AbstractInterpreter):
slice_point = i
break
if is_simple:
# print(formula, " is simple")
#print(formula, " is simple")
if not self.check_simple_formula(formula):
raise Exception("Błąd na poziomie formuły bez zagnieżdzeń: {0}".format(formula))
return False
@ -177,7 +186,7 @@ class Formula:
def isValid(self, interpreter=None)->bool:
i = self.__i if interpreter is None else interpreter
return i.isValid(self)
sim = SimpleInterpreter()
if len(sys.argv) > 1 :
i = ProperInterpreter()
if '-g' in sys.argv:
@ -192,7 +201,9 @@ if len(sys.argv) > 1 :
for l in u:
print(Formula(l,i).isValid())
else:
print(Formula( sys.argv[1] if sys.argv[1] != '-g' else sys.argv[2],i).isValid())
print(
Formula(sys.argv[1] if sys.argv[1] != '-g' else sys.argv[2],i).isValid()
)
else:
print("help?")