std.sql.check_unordered: unordered_checker.py
import sys
from json import loads
ERR_OK = 0
ERR_WA = 1
ERR_PE = 2
ERR_UH = 3
# 2nd argument is 'test.log' file, 3rd is 'n.ans' file
with open(sys.argv[3], 'r') as answer_file, open(sys.argv[2], 'r') as output_file:
err_answer_file = int(answer_file.readline())
err_received_file = int(output_file.readline())
# if not OK print to console received_file and exit with err
if err_received_file != ERR_OK:
print(output_file.read())
exit(err_received_file)
right_answer_dict = loads(answer_file.read())
received_answer_dict = loads(output_file.read())
# if answers doesn't match
if received_answer_dict != right_answer_dict:
if received_answer_dict and len(received_answer_dict[0]) != len(right_answer_dict[0]):
print('Incorrect number of columns!')
exit(ERR_WA)
if received_answer_dict and len(received_answer_dict) != len(right_answer_dict):
print('Incorrect number of rows!')
exit(ERR_WA)
# Data checking:
set_right_ans = set(tuple(it) for it in right_answer_dict)
set_received_ans = set(tuple(it) for it in received_answer_dict)
if set_received_ans == set_right_ans:
# List is not sorted
exit(ERR_OK)
else:
print('Wrong answer!')
exit(ERR_WA)
# if all OK, exit with 0
exit(ERR_OK)