@@ -12,18 +12,45 @@ func test_bounce_inverts_x():
1212
1313 stub (ball , 'get_direction' ).to_return (Vector2 (1 , 1 ))
1414 paddle .bounce (ball )
15- assert_called (ball , 'set_direction' , [Vector2 (- 1 , 1 )])
15+ var new_x = get_call_parameters (ball , 'set_direction' )[0 ].x
16+ assert_eq (new_x , - 1.0 )
17+
1618
1719func test_bounce_inverts_x_other_direction ():
1820 var ball = double (Ball ).new ()
1921 var paddle = Paddle .new ()
2022
2123 stub (ball , 'get_direction' ).to_return (Vector2 (- 1 , 1 ))
2224 paddle .bounce (ball )
23- assert_called (ball , 'set_direction' , [Vector2 (1 , 1 )])
25+ var new_x = get_call_parameters (ball , 'set_direction' )[0 ].x
26+ assert_eq (new_x , 1.0 )
2427
2528func test_bounce_changes_y_randomly ():
2629 var paddle = Paddle .new ()
2730 var ball = double (Ball ).new ()
2831 stub (ball , 'get_direction' ).to_return (Vector2 (1 , 1 ))
29-
32+ stub (ball , 'set_direction' ).to_do_nothing ()
33+
34+ for i in range (1000 ):
35+ paddle .bounce (ball )
36+
37+ var last_y = get_call_parameters (ball , 'set_direction' , 0 )[0 ].y
38+ var current_y = 0
39+ var num_equal = 0
40+ var min_y = 3
41+ var max_y = - 3
42+ for i in range (1 , 1000 ):
43+ current_y = get_call_parameters (ball , 'set_direction' , i )[0 ].y
44+ if (current_y == last_y ):
45+ num_equal += 1
46+ last_y = current_y
47+
48+ max_y = max (max_y , current_y )
49+ min_y = min (min_y , current_y )
50+
51+ assert_eq (num_equal , 0 )
52+
53+ assert_between (min_y , - .5 , - .3 )
54+ assert_between (max_y , .3 , .5 )
55+
56+
0 commit comments