-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
68 lines (63 loc) · 2.79 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import csv
from reconstruction import solver
from preprocessing import convert_to_single_line, prepare_string
def main(csv_path: str, row_number: int) -> bool:
"""
Main function that loads the desired line form csv file and
calls the main processing function on it and then compares the output to the correct anwser
Input: csv_path, row_number
Output: None
"""
with open(csv_path, 'r') as csv_file:
csv_reader = csv.reader(csv_file)
# Skip the header
next(csv_reader)
for _ in range(row_number):
next(csv_reader)
row = next(csv_reader)
# Call main preprocessing funciton on input cypher statemenet which also validates the cypher direction
output, variable_length_flag = prepare_string(row)
# Check if the input statement is of variable length (contains *)
if not variable_length_flag:
# Call main processing function on input cypher statemenet
# Triple string quotes are used so this code can work for older versions of python
solution = solver(output, f'''{convert_to_single_line(row[0])}''')
else:
# When variable length is present, the output should just match the input statement
solution = output
print("Input statement:")
print(convert_to_single_line(row[0]))
print("------------------------------")
print("My output:")
print(solution)
if row[2] == '':
# Some rows were marked as incorrect syntax by Tomaz and were left empty
# Since my code marks lines with incorrect syntax as 'Syntax error', I will compare it to that
correct_anwser = 'Syntax error'
else:
correct_anwser = convert_to_single_line(row[2])
print('------------------------------')
print('Correct input anwser:')
print(correct_anwser)
# Compare the output of my code to the correct anwser from csv file
if solution == correct_anwser:
print('Evaluation: Correct')
return True
elif solution == 'Syntax error':
print('My code marks this input statement as invalid (syntax error)')
else:
print('Evaluation: Incorrect')
return False
if __name__ == '__main__':
# Run the main function on all 74 lines from csv file
final_evaluation = []
for i in range(74):
print("===============================================================================")
print("Statement number: ", i)
final_evaluation.append(main('examples.csv', i))
print("===============================================================================")
print("Final evaluation:")
if all(final_evaluation):
print("All correct")
else:
print("Fail")