Skip to content
Snippets Groups Projects
Commit d6fd9433 authored by Ashwin Maran's avatar Ashwin Maran
Browse files

p6_test update

parent 3f47b18f
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/python
import os, json, math
import os, json, math
MAX_FILE_SIZE = 500 # units - KB
REL_TOL = 6e-04 # relative tolerance for floats
ABS_TOL = 15e-03 # absolute tolerance for floats
......@@ -90,15 +91,21 @@ expected_json = {"1": (TEXT_FORMAT_UNORDERED_LIST, ['Brooklyn', 'Manhattan',
'1 Pvt. Room in Upper West Manhattan']),
"20": (TEXT_FORMAT, 30)}
def check_cell(qnum, actual):
special_ordered_json = {}
def check_cell_text(qnum, actual):
format, expected = expected_json[qnum[1:]]
try:
if format == TEXT_FORMAT:
return simple_compare(expected, actual)
elif format in [TEXT_FORMAT_ORDERED_LIST, TEXT_FORMAT_LIST_DICTS_ORDERED]:
return list_compare_ordered(expected, actual)
elif format == TEXT_FORMAT_UNORDERED_LIST:
return list_compare_unordered(expected, actual)
elif format == TEXT_FORMAT_ORDERED_LIST:
return list_compare_ordered(expected, actual)
elif format == TEXT_FORMAT_SPECIAL_ORDERED_LIST:
return list_compare_special(expected, actual, special_ordered_json[qnum[1:]])
elif format == TEXT_FORMAT_DICT:
return dict_compare(expected, actual)
else:
if expected != actual:
return "expected %s but found %s " % (repr(expected), repr(actual))
......@@ -130,15 +137,6 @@ def simple_compare(expected, actual, complete_msg=True):
msg = msg + " but found %s" % (repr(actual))
return msg
def namedtuple_compare(expected, actual):
msg = PASS
for field in expected._fields:
val = simple_compare(getattr(expected, field), getattr(actual, field))
if val != PASS:
msg = "at attribute %s of namedtuple %s, " % (field, type(expected).__name__) + val
return msg
return msg
def list_compare_ordered(expected, actual, obj="list"):
msg = PASS
......@@ -230,6 +228,7 @@ def list_compare_unordered(expected, actual, obj="list"):
sort_expected)
return msg
def list_compare_special_init(expected, special_order):
real_expected = []
for i in range(len(expected)):
......@@ -295,7 +294,11 @@ def dict_compare(expected, actual, obj="dict"):
def check(qnum, actual):
msg = check_cell(qnum, actual)
msg = check_cell_text(qnum, actual)
if msg == PASS:
return True
print("<b style='color: red;'>ERROR:</b> " + msg)
def check_file_size(path):
size = os.path.getsize(path)
assert size < MAX_FILE_SIZE * 10**3, "Your file is too big to be processed by Gradescope; please delete unnecessary output cells so your file size is < %s KB" % MAX_FILE_SIZE
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment