proper naming and error printing
This commit is contained in:
parent
214e81592d
commit
c1f8dbfa90
@ -1,8 +1,6 @@
|
|||||||
import string
|
|
||||||
import sys
|
import sys
|
||||||
import csv
|
import csv
|
||||||
import os
|
import os
|
||||||
from more_itertools import difference
|
|
||||||
|
|
||||||
from numpy import append
|
from numpy import append
|
||||||
|
|
||||||
@ -26,6 +24,7 @@ with open(join_path(sys.argv[1]), "r", newline="", encoding="utf8") as csvfile:
|
|||||||
accepting_state = int(fsa_description[-1][0])
|
accepting_state = int(fsa_description[-1][0])
|
||||||
fsa_description = fsa_description[:-1]
|
fsa_description = fsa_description[:-1]
|
||||||
fsa_description_map = {}
|
fsa_description_map = {}
|
||||||
|
is_error = False
|
||||||
for num, item in enumerate(fsa_description):
|
for num, item in enumerate(fsa_description):
|
||||||
for letter in item[2]:
|
for letter in item[2]:
|
||||||
if letter not in alfabet:
|
if letter not in alfabet:
|
||||||
@ -33,10 +32,13 @@ with open(join_path(sys.argv[1]), "r", newline="", encoding="utf8") as csvfile:
|
|||||||
exit(-1)
|
exit(-1)
|
||||||
if (int(item[0]), letter) in fsa_description_map:
|
if (int(item[0]), letter) in fsa_description_map:
|
||||||
print("ERROR - duplicate letter:", letter, "| line:", num + 1)
|
print("ERROR - duplicate letter:", letter, "| line:", num + 1)
|
||||||
exit(-1)
|
is_error = True
|
||||||
tuple = (int(item[0]), letter)
|
tuple = (int(item[0]), letter)
|
||||||
fsa_description_map[tuple] = int(item[1])
|
fsa_description_map[tuple] = int(item[1])
|
||||||
|
|
||||||
|
if is_error:
|
||||||
|
exit(-1)
|
||||||
|
|
||||||
states = {}
|
states = {}
|
||||||
for item in fsa_description_map:
|
for item in fsa_description_map:
|
||||||
states[item[0]] = states[item[0]] + item[1] if item[0] in states else item[1]
|
states[item[0]] = states[item[0]] + item[1] if item[0] in states else item[1]
|
||||||
@ -75,7 +77,7 @@ with open(join_path(sys.argv[3]), "r", newline="", encoding="utf8") as csvfile:
|
|||||||
test_out = list(filereader)
|
test_out = list(filereader)
|
||||||
|
|
||||||
|
|
||||||
difference = []
|
is_difference = []
|
||||||
for i, word in enumerate(test_in):
|
for i, word in enumerate(test_in):
|
||||||
current_state = 0
|
current_state = 0
|
||||||
if len(word) != 0:
|
if len(word) != 0:
|
||||||
@ -87,12 +89,13 @@ for i, word in enumerate(test_in):
|
|||||||
print("YES\t", end="")
|
print("YES\t", end="")
|
||||||
if "YES" != test_out[i][0]:
|
if "YES" != test_out[i][0]:
|
||||||
print("ERROR", word, end="")
|
print("ERROR", word, end="")
|
||||||
difference.append(i)
|
is_difference.append(i)
|
||||||
else:
|
else:
|
||||||
print("NO\t", end="")
|
print("NO\t", end="")
|
||||||
if "NO" != test_out[i][0]:
|
if "NO" != test_out[i][0]:
|
||||||
print("ERROR", word, end="")
|
print("ERROR", word, end="")
|
||||||
difference.append(i)
|
is_difference.append(i)
|
||||||
print()
|
print()
|
||||||
|
|
||||||
print(difference)
|
if len(is_difference) != 0:
|
||||||
|
print(is_difference)
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
from re import T
|
|
||||||
import string
|
|
||||||
import sys
|
import sys
|
||||||
import csv
|
import csv
|
||||||
import os
|
import os
|
||||||
from more_itertools import difference
|
|
||||||
|
|
||||||
from numpy import append
|
from numpy import append
|
||||||
|
|
||||||
@ -80,7 +77,7 @@ with open(join_path(sys.argv[3]), "r", newline="", encoding="utf8") as csvfile:
|
|||||||
test_out = list(filereader)
|
test_out = list(filereader)
|
||||||
|
|
||||||
|
|
||||||
difference = []
|
is_difference = []
|
||||||
for i, word in enumerate(test_in):
|
for i, word in enumerate(test_in):
|
||||||
current_state = 0
|
current_state = 0
|
||||||
if len(word) != 0:
|
if len(word) != 0:
|
||||||
@ -92,12 +89,13 @@ for i, word in enumerate(test_in):
|
|||||||
print("YES\t", end="")
|
print("YES\t", end="")
|
||||||
if "YES" != test_out[i][0]:
|
if "YES" != test_out[i][0]:
|
||||||
print("ERROR", word, end="")
|
print("ERROR", word, end="")
|
||||||
difference.append(i)
|
is_difference.append(i)
|
||||||
else:
|
else:
|
||||||
print("NO\t", end="")
|
print("NO\t", end="")
|
||||||
if "NO" != test_out[i][0]:
|
if "NO" != test_out[i][0]:
|
||||||
print("ERROR", word, end="")
|
print("ERROR", word, end="")
|
||||||
difference.append(i)
|
is_difference.append(i)
|
||||||
print()
|
print()
|
||||||
|
|
||||||
print(difference)
|
if len(is_difference) != 0:
|
||||||
|
print(is_difference)
|
||||||
|
Loading…
Reference in New Issue
Block a user