コード例 #1
0
def test_finding_circle_error_after_one_slow_increment():
    queue_a = Manager().Queue()
    queue_b = Manager().Queue()
    queue_c = Manager().Queue()

    ball = server.BouncingBall(500, 500, 20,
                               server.BouncingBall.BallSpeed.SLOW)
    new_ball_img = ball.increment_ball()

    queue_a.put(new_ball_img)

    p1 = Process(target=client.process_a, args=(
        queue_a,
        queue_b,
    ))
    p1.start()
    p2 = Process(target=server.calculate_error,
                 args=(
                     ball,
                     queue_b,
                     queue_c,
                 ))
    p2.start()

    p1.join()
    p2.join()

    dist_error = queue_c.get()
    assert dist_error < 10.0
コード例 #2
0
def test_bouncing_ball_fake_speed():
    try:
        ball = server.BouncingBall(500, 500, 20, 1)
        raise Exception(
            "BouncingBall should have raised ValueError because 1 is not a BallSpeed"
        )
    except ValueError:
        pass  # expected error
コード例 #3
0
def test_bouncing_ball_slow_increment():
    ball = server.BouncingBall(500, 500, 20,
                               server.BouncingBall.BallSpeed.SLOW)
    expected_x = int(500 / 4)
    expected_y = int(500 / 3)
    assert (ball.get_current_position() == (expected_x, expected_y))
    ball.increment_ball()
    assert (ball.get_current_position() == (expected_x + 1, expected_y + 1)
            )  # Since speed is slow
コード例 #4
0
def test_bouncing_ball_large_width_error():
    try:
        ball = server.BouncingBall(500, 5000, 20,
                                   server.BouncingBall.BallSpeed.SLOW)
        raise Exception(
            "BouncingBall should have raised ValueError because 3000 is too large a window length"
        )
    except ValueError:
        pass  # expected error
コード例 #5
0
def test_bouncing_ball_large_radius_error():
    try:
        ball = server.BouncingBall(500, 500, 101,
                                   server.BouncingBall.BallSpeed.SLOW)
        raise Exception(
            "BouncingBall should have raised ValueError because 101 is too large a ball radius"
        )
    except ValueError:
        pass  # expected error
コード例 #6
0
def view_ball():
    ball = server.BouncingBall(500, 500, 20,
                               server.BouncingBall.BallSpeed.SLOW)
    while True:
        updated_ball = ball.increment_ball()
        cv2.startWindowThread()
        cv2.imshow('screensaver', updated_ball)
        key = cv2.waitKey(1)
        if key == '27':  # escape
            break