TEXT_FORMAT="text"# question type when expected answer is a str, int, float, or bool
TEXT_FORMAT_NAMEDTUPLE="text namedtuple"# question type when expected answer is a namedtuple
TEXT_FORMAT_UNORDERED_LIST="text list_unordered"# question type when the expected answer is a list where the order does *not* matter
TEXT_FORMAT_ORDERED_LIST="text list_ordered"# question type when the expected answer is a list where the order does matter
TEXT_FORMAT_SPECIAL_ORDERED_LIST="text list_special_ordered"# question type when the expected answer is a list where order does matter, but with possible ties. Elements are ordered according to values in special_ordered_json (with ties allowed)
TEXT_FORMAT_DICT="text dict"# question type when the expected answer is a dictionary
HTML_FORMAT="html"# question type when the expected answer is a DataFrame
FILE_JSON_FORMAT="file json"# question type when the expected answer is a JSON file
defreturn_expected_json():
expected_json={"1":(HTML_FORMAT,None),
"2":(HTML_FORMAT,None),
"3":(HTML_FORMAT,None),
"4":(HTML_FORMAT,None),
"5":(HTML_FORMAT,None),
"6":(HTML_FORMAT,None),
"7":(HTML_FORMAT,None),
"8":(HTML_FORMAT,None),
"9":(HTML_FORMAT,None),
"10":(HTML_FORMAT,None),
"11":(TEXT_FORMAT,0.5213253604130499),
"12":(TEXT_FORMAT,0.557397228343763),
"13":(HTML_FORMAT,None),
"14":(HTML_FORMAT,None),
"15":(HTML_FORMAT,None),
"16":(HTML_FORMAT,None),
"17":(HTML_FORMAT,None),
"18":(HTML_FORMAT,None),
"19":(TEXT_FORMAT,56),
"20":(HTML_FORMAT,None)}
returnexpected_json
defcheck_cell(qnum,actual):
expected_json=return_expected_json()
format,expected=expected_json[qnum[1:]]
try:
ifformat==TEXT_FORMAT:
returnsimple_compare(expected,actual)
elifformat==TEXT_FORMAT_UNORDERED_LIST:
returnlist_compare_unordered(expected,actual)
elifformat==TEXT_FORMAT_ORDERED_LIST:
returnlist_compare_ordered(expected,actual)
elifformat==TEXT_FORMAT_DICT:
returndict_compare(expected,actual)
elifformat==TEXT_FORMAT_NAMEDTUPLE:
returnnamedtuple_compare(expected,actual)
elifformat==HTML_FORMAT:
returncheck_cell_html(qnum[1:],actual)
elifformat==FILE_JSON_FORMAT:
returncheck_json(expected,actual)
else:
ifexpected!=actual:
return"expected %s but found %s "%(repr(expected),repr(actual))
assertsize<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