def run_test(input_data): result = "" try: # f = getattr(lab, input_data["function"]) # result = f(**input_data["inputs"]) # Run student code lab.init(input_data['width'], input_data['height'], input_data['ballPosition'], input_data['ballVelocity'], input_data['blocks']) for m, s in enumerate(input_data['steps']): st = lab.step(s['time'], input_data['paddle1X'], input_data['paddle2X'], input_data['paddle_offset'], input_data['paddle_radius']) if not close( st, s['winner'] ): # TODO: Ideally, this should happen in the reducer. This is sketchy because a clever student has access to the expected values! In this case, good enough because we expose all test cases anyway... test_okay = False raise Exception( "Incorrect winner state at timestep {} got {} expected {}". format(str(m), str(st), str(s['winner']))) tocheck = CanvasToList() lab.draw(tocheck, input_data['paddle1X'], input_data['paddle2X'], input_data['paddle_offset'], input_data['paddle_radius']) result = tocheck.objects() except: result = traceback.format_exc() return result
def test_02(self): print("step(step(gas_3)) example ... ", end="", flush=True) input = {"width": 3, "state": [["w"], ["u", "w"], ["w"], ["w"], [], ["w"], ["w"], ["u", "d"], ["w"], ["w"], ["w"], ["w"]], "height": 4} result = lab.step(input) expect = {"width": 3, "state": [["w"], ["w"], ["w"], ["w"], ["d"], ["w"], ["l", "w"], [], ["r", "w"], ["w"], ["w"], ["w"]], "height": 4} self.check_result(result, expect)
def run_test(input_data): result = "" try: # f = getattr(lab, input_data["function"]) # result = f(**input_data["inputs"]) # Run student code lab.init( input_data['width'], input_data['height'], input_data['ballPosition'], input_data['ballVelocity'], input_data['blocks'] ) for m,s in enumerate(input_data['steps']): st = lab.step( s['time'], input_data['paddle1X'], input_data['paddle2X'], input_data['paddle_offset'], input_data['paddle_radius'] ) if not close(st, s['winner']): # TODO: Ideally, this should happen in the reducer. This is sketchy because a clever student has access to the expected values! In this case, good enough because we expose all test cases anyway... test_okay = False raise Exception("Incorrect winner state at timestep {} got {} expected {}".format(str(m),str(st),str(s['winner'])) ) tocheck = CanvasToList() lab.draw( tocheck, input_data['paddle1X'], input_data['paddle2X'], input_data['paddle_offset'], input_data['paddle_radius'] ) result = tocheck.objects() except: result = traceback.format_exc() return result
def step(input_data): return lab.step(input_data['time'], input_data['paddle_1_xpos'], input_data['paddle_2_xpos'], input_data['paddle_offset'], input_data['paddle_radius'])
def step(input_data): return lab.step( input_data['time'], input_data['paddle_1_xpos'], input_data['paddle_2_xpos'], input_data['paddle_offset'], input_data['paddle_radius'] )
def next(d): r = None # MUX r = lab.step(d["gas"]) return r
def next( d ): r = None # MUX r = lab.step(d["gas"]) return r
def test_10(self): descrip, input, expect = self.load_case('10') print(descrip, " ... ", end="", flush=True) result = lab.step(input) self.check_result(result, expect)
class TestGas(unittest.TestCase): def test_01(self): print("step(gas_3) example ... ", end="", flush=True) input = { "width": 3, "state": [["w"], ["w"], ["w"], ["w"], ["r", "l"], ["w"], ["w"], [], ["w"], ["w"], ["d", "w"], ["w"]], "height": 4 } result = lab.step(input) expect = { "width": 3, "state": [["w"], ["u", "w"], ["w"], ["w"], [], ["w"], ["w"], ["u", "d"], ["w"], ["w"], ["w"], ["w"]], "height": 4 } self.check_result(result, expect) def test_02(self): print("step(step(gas_3)) example ... ", end="", flush=True) input = { "width": 3, "state": [["w"], ["u", "w"], ["w"], ["w"], [], ["w"], ["w"], ["u", "d"], ["w"], ["w"], ["w"], ["w"]], "height": 4 } result = lab.step(input) expect = { "width": 3, "state": [["w"], ["w"], ["w"], ["w"], ["d"], ["w"], ["l", "w"], [], ["r", "w"], ["w"], ["w"], ["w"]], "height": 4 } self.check_result(result, expect) def test_03(self): descrip, input, expect = self.load_case('3') print(descrip, " ... ", end="", flush=True) result = lab.step(input) self.check_result(result, expect) def test_04(self): descrip, input, expect = self.load_case('4') print(descrip, " ... ", end="", flush=True) result = lab.step(input) self.check_result(result, expect) def test_05(self): descrip, input, expect = self.load_case('5') print(descrip, " ... ", end="", flush=True) result = lab.step(input) self.check_result(result, expect) def test_06(self): descrip, input, expect = self.load_case('6') print(descrip, " ... ", end="", flush=True) result = lab.step(input) self.check_result(result, expect) def test_07(self): descrip, input, expect = self.load_case('7') print(descrip, " ... ", end="", flush=True) result = lab.step(input) self.check_result(result, expect) def test_08(self): descrip, input, expect = self.load_case('8') print(descrip, " ... ", end="", flush=True) result = lab.step(input) self.check_result(result, expect) def test_09(self): descrip, input, expect = self.load_case('9') print(descrip, " ... ", end="", flush=True) result = lab.step(input) self.check_result(result, expect) def test_10(self): descrip, input, expect = self.load_case('10') print(descrip, " ... ", end="", flush=True) result = lab.step(input) self.check_result(result, expect) def test_11(self): descrip, input, expect = self.load_case('11') print(descrip, " ... ", end="", flush=True) result = lab.step(input) self.check_result(result, expect) def extra_test_all(self): for n in range(1, 12): with self.subTest(case=n): descrip, input, expect = self.load_case(str(n)) print(" subTest:", descrip, "... ", flush=True) result = lab.step(input) self.check_result(result, expect)