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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
| import unittest import random from gradescope_utils.autograder_utils.decorators import partial_credit, visibility import os import re
class TestPartialCredit(unittest.TestCase): def setUp(self): pass
@visibility('after_due_date') @partial_credit(70.0) def test_fanout_free(self, set_score=None): with open(f"./result_sort/log", 'r') as IN: fanout_free = 0 fanout = 0 xlist = 0 unique = 0 for line in IN: line = line.strip() score = 0 if ":" in line: score = float(line.split(":")[1].strip()) if re.match(r'^c7\.(\d)', line): fanout_free += score elif re.match(r'^nand\.(\d)', line): fanout_free += score elif re.match(r'^or\.(\d)', line): fanout_free += score else: continue print(f"line={line}, this benchmark's score={score}, fanout_free cumulative score={fanout_free}") fanout_free = fanout_free * 10 """Sets partial credit""" set_score(fanout_free + 10)
@partial_credit(30.0) @visibility('after_due_date') def test_fanout(self, set_score=None): with open(f"./result_sort/log", 'r') as IN: fanout_free = 0 fanout = 0 xlist = 0 unique = 0 for line in IN: line = line.strip() score = 0 if ":" in line: score = float(line.split(":")[1].strip()) if re.match(r'^c7\.(\d)', line): fanout_free += score elif re.match(r'^nand\.(\d)', line): fanout_free += score elif re.match(r'^or\.(\d)', line): fanout_free += score elif "xlist" in line: xlist += score xlist = xlist * 10 elif "unique" in line: unique += score unique = unique * 10 else: fanout += score print(f"line={line}, this benchmark's score={score}, fanout cumulative score={fanout}")
fanout = fanout * 5 set_score(fanout) @partial_credit(20.0) @visibility('after_due_date') def test_extra(self, set_score=None): with open(f"./result_sort/log", 'r') as IN: fanout_free = 0 fanout = 0 xlist = 0 unique = 0 for line in IN: line = line.strip() score = 0 if ":" in line: score = float(line.split(":")[1].strip()) if re.match(r'^c7\.(\d)', line): fanout_free += score elif re.match(r'^nand\.(\d)', line): fanout_free += score elif re.match(r'^or\.(\d)', line): fanout_free += score elif "xlist" in line: xlist += score xlist = xlist * 10 print(f"line={line}, this benchmark's score={score}, xlist cumulative score={xlist}, unique cumulative score={unique}") elif "unique" in line: unique += score unique = unique * 10 print(f"line={line}, this benchmark's score={score}, xlist cumulative score={xlist}, unique cumulative score={unique}") else: fanout += score extra = xlist + unique set_score(extra) @partial_credit(10.0) @visibility('after_due_date') def test_clarity(self, set_score=None): set_score(10)
|