def check_bonus_email(test_email, grade_email): if grade_email in found_emails: found_emails.remove(grade_email) student("Bonus:", test_email, "PASSED (+1 bonus!)") return "PASSED" else: student("Bonus:", test_email, "fail (does not count against you)") return "FAILED"
def check_email(test_email, grade_email): if grade_email in found_emails: found_emails.remove(grade_email) correct_emails.remove(grade_email) student("Test:", test_email, "PASSED") return "PASSED" else: student("Test:", test_email, "FAILED!") grader("Test:", test_email, "FAILED!") return "FAILED"
name = None newio = timeout.CustomIO() oio = sys.stdout, sys.stdin try: sys.stdout, sys.stdin = newio, newio try: runpy.run_module('rumple') except: pass ans = newio.printed[0] name = ' '.join(ans.strip().split('\n')[0].split()[7:-3]) finally: sys.stdout, sys.stdin = oio if name is None: student('We failed to find the answer on the first line of output') grader('Score: 0 / 10') quit() if expect("rumple", [name], [re.compile(r".* $"), re.compile(r".*")], "Failed first example."): correct += 1 else: wrong += 1 if expect("rumple", ['x' + name, name], [re.compile(r".* $"), re.compile(r".* $"), re.compile(r".*")], ""): correct += 1 else:
"Failed multi-line punctuation test.", maxtime=5): correct += 1 else: wrong += 1 if expect( "spellcheck", ["Ne'er 'ave I bein' so hurt.", ''], [None, re.compile('^\s*MISSPELLED: *ave\s*MISSPELLED: *bein\s*$'), ''], "Failed apostrophe test.", maxtime=5): correct += 1 else: wrong += 1 if expect("spellcheck", ["yes", 'yess', 'yes'] * 4 + [''], [None] + ['', re.compile('^\s*MISSPELLED: *yess\s*$'), ''] * 4 + [''], "Failed many-line test test.", maxtime=5): correct += 1 else: wrong += 1 if wrong == 0: student("Congratulations, you passed all of our tests!") else: student("You passed", correct, "out of", correct + wrong, "tests.") grader("Score:", correct, "/", correct + wrong)
with open(mod + '.py') as f: src = f.read() tree = ast.parse(src, mod + '.py') for kid in ast.iter_child_nodes(tree): if isinstance(kid, ast.FunctionDef): funcs[str(kid.name)] = has_loops(kid), invokes_and_operators(kid) fcor = 0 func = 'mean' try: fcor += test_func(mod, func, 2.0, None, [2, 2, 2], full=True) fcor += test_func(mod, func, 2.0, None, [1, 2, 3]) fcor += test_func(mod, func, 8.0 / 3, None, [1, 1, 6]) except: student( "something unexpected happened in our autograding; your score below might be incorrectly small" ) student(func + ' passed', fcor, 'out of', 5, 'automated test cases') correct += fcor fcor = 0 func = 'median' try: fcor += test_func(mod, func, 2.0, None, [2, 2, 2], full=True) fcor += test_func(mod, func, -2.0, None, [-3, -1, -2]) fcor += test_func(mod, func, -2.0, None, [-3, -2, -1]) fcor += test_func(mod, func, -2.0, None, [-2, -3, -1]) fcor += test_func(mod, func, -2.0, None, [-1, -3, -2]) fcor += test_func(mod, func, -2.0, None, [-1, -2, -3]) fcor += test_func(mod, func, -2.0, None, [-2, -1, -3])
from gradetools import grader, student, test_func correct = 0 mod = 'credit_card' func = 'check' try: correct += test_func(mod, func, False, None, [1], full=True) for num in [5490123456789129, 5490123456789122, 54906789122]: correct += test_func(mod, func, False, None, [num]) for num in [378282246310005, 6011111111111117, 5555555555554444]: correct += test_func(mod, func, True, None, [num]) except: student("something unexpected happened in our autograding; your score below might be incorrectly small") student(func+' passed', correct, 'out of', 9, 'automated test cases') grader('Score:', correct, '/', 9)
# # if expect("roman", ["27"],[re.compile(r".*"),re.compile(r".*(XXVII).*")], "Failed small number"): # correct += 1 # else: # wrong += 1 # # if expect("roman", ["1"],[re.compile(r".*"),re.compile(r".*(I).*")], "Failed very small number"): # correct += 1 # else: # wrong += 1 # # if expect("roman", ["184"],[re.compile(r".*"),re.compile(r".*(CLXXXIV).*")], "Failed small number 2"): # correct += 1 # else: # wrong += 1 else: wrong += 1 student( 'Because you failed when the input was 1, we did not test anything else' ) if wrong == 0: student("Congratulations, you passed all of our tests!") else: student( "You passed", correct, "out of", correct + wrong, "tests. If you failed all tests, but your values look correct, make sure to double check your spelling, punctuation, capitalization, and spacing! It must match the assignment page exactly!" ) grader("Score:", correct, "/", correct + wrong)
def check_bonus_email(test_email, grade_email): if grade_email in found_emails: found_emails.remove(grade_email) student("Bonus:", test_email, "PASSED (+1 bonus!)") return "PASSED" else: student("Bonus:", test_email, "fail (does not count against you)") return "FAILED" try: import email_finder except: student( "You are missing at least one function or a function's header is incorrect. Tests will not run until you fix this problem." ) grader("Exception thrown - missing function") bad_function = True exit() program_search = open("email_finder.py", "r") for line in program_search: if "print(" in line: student( "You are calling print from inside your code. Please remove all testing statements before submitting." ) bad_function = False exit() if not bad_function:
CS1110-001/smile ! hi there mst3k +3o-___26 t.j t.j. "hi there" but not " hi there" or "hi there " or "I said "hi" just now" 3,4, 3.0, 4.5 and -3.14159265 1110 but not 3.4.5, 1 or 1 2 or 3 - 4 Thomas Jefferson and Edmund Jennings Randolph and J. Pierpont Finch and T. Jefferson but not T Jefferson or Thomas J. or Flannery O'Connor ''' score = 0 if 'nospace' in dir(regexs) and type(regexs.nospace) is ret: ns = full_match(regexs.nospace, text) nss = sum([ 'CS1110-001/smile' in ns, '!' in ns, 'hi there' not in ns, '' not in ns ]) student('nospace: passed', nss, 'out of', 4, 'tests') score += nss else: student('nospace was not a compiled regular expression in regexs.py') #if 'email_name' in dir(regexs) and type(regexs.email_name) is ret: # en = full_match(regexs.email_name, text) # ens = sum(['mst3k' in en, '+3o-___26' in en, 't.j' in en, 't.j.' not in en]) # student('email_name: passed', nss, 'out of', 4, 'tests') # score += nss #else: # student('email_name was not a compiled regular expression in regexs.py') if 'quotation' in dir(regexs) and type(regexs.quotation) is ret: q = full_match(regexs.quotation, text) qs = sum([
fcor += test_func(mod, func, [2], None, [(1, 2), (2, 3)], sort=True) fcor += test_func(mod, func, [1, 3, 2], None, [[0, 1, 2, 3, 4], [-1, 1, 3, 5, 2]], sort=True) fcor += test_func(mod, func, [1, 3, 2], None, [[1, 2, 3], [-1, 1, 3, 5, 2]], sort=True) fcor += test_func(mod, func, [1, 3, 2], None, [[0, 1, 2, 3, 4], [1, 3, 2]], sort=True) except: student( "something unexpected happened in our autograding; your score below might be incorrectly small" ) student(func + ' passed', fcor, 'out of', 7, 'automated test cases') correct += fcor fcor = 0 func = 'disagreement' try: fcor += test_func(mod, func, [], None, [[], []], full=True, sort=True) fcor += test_func(mod, func, [1, 3], None, [(1, 2), (2, 3)], sort=True) fcor += test_func(mod, func, [0, 4, -1, 5], None, [[0, 1, 2, 3, 4], [-1, 1, 3, 5, 2]], sort=True) fcor += test_func(mod,