proper naming and error printing

This commit is contained in:
HOME-VM-TOSCHOOL 2023-11-01 23:41:39 +01:00
parent 214e81592d
commit c1f8dbfa90
2 changed files with 15 additions and 14 deletions

View File

@ -1,8 +1,6 @@
import string
import sys
import csv
import os
from more_itertools import difference
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])
fsa_description = fsa_description[:-1]
fsa_description_map = {}
is_error = False
for num, item in enumerate(fsa_description):
for letter in item[2]:
if letter not in alfabet:
@ -33,10 +32,13 @@ with open(join_path(sys.argv[1]), "r", newline="", encoding="utf8") as csvfile:
exit(-1)
if (int(item[0]), letter) in fsa_description_map:
print("ERROR - duplicate letter:", letter, "| line:", num + 1)
exit(-1)
is_error = True
tuple = (int(item[0]), letter)
fsa_description_map[tuple] = int(item[1])
if is_error:
exit(-1)
states = {}
for item in fsa_description_map:
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)
difference = []
is_difference = []
for i, word in enumerate(test_in):
current_state = 0
if len(word) != 0:
@ -87,12 +89,13 @@ for i, word in enumerate(test_in):
print("YES\t", end="")
if "YES" != test_out[i][0]:
print("ERROR", word, end="")
difference.append(i)
is_difference.append(i)
else:
print("NO\t", end="")
if "NO" != test_out[i][0]:
print("ERROR", word, end="")
difference.append(i)
is_difference.append(i)
print()
print(difference)
if len(is_difference) != 0:
print(is_difference)

View File

@ -1,9 +1,6 @@
from re import T
import string
import sys
import csv
import os
from more_itertools import difference
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)
difference = []
is_difference = []
for i, word in enumerate(test_in):
current_state = 0
if len(word) != 0:
@ -92,12 +89,13 @@ for i, word in enumerate(test_in):
print("YES\t", end="")
if "YES" != test_out[i][0]:
print("ERROR", word, end="")
difference.append(i)
is_difference.append(i)
else:
print("NO\t", end="")
if "NO" != test_out[i][0]:
print("ERROR", word, end="")
difference.append(i)
is_difference.append(i)
print()
print(difference)
if len(is_difference) != 0:
print(is_difference)