Beispiel #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
Beispiel #2
0
def init(input_data):
    global canvas
    canvas = Canvas()
    return lab.init(   input_data['width'],
                input_data['height'],
                input_data['ball_position'],
                input_data['ball_velosity'],
                input_data['blocks'] )
Beispiel #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
Beispiel #4
0
def init(input_data):
    global canvas
    canvas = Canvas()
    return lab.init(input_data['width'], input_data['height'],
                    input_data['ball_position'], input_data['ball_velosity'],
                    input_data['blocks'])