Example #1
0
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
Example #2
0
def draw(input_data):
  lab.draw(    canvas.clear(),
                input_data['paddle_1_xpos'],
                input_data['paddle_2_xpos'],
                input_data['paddle_offset'],
                input_data['paddle_radius'] )
  return canvas.get_state()
Example #3
0
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
Example #4
0
def draw(input_data):
    lab.draw(canvas.clear(), input_data['paddle_1_xpos'],
             input_data['paddle_2_xpos'], input_data['paddle_offset'],
             input_data['paddle_radius'])
    return canvas.get_state()