@@ -11,9 +11,21 @@ func before_each():
1111func after_each ():
1212 remove_child (_game )
1313
14+ func _simulate_p1_score (game ):
15+ game .get_node ('P2KillBox' ).emit_signal ('kill_ball' )
16+
17+ func _simulate_p2_score (game ):
18+ game .get_node ('P1KillBox' ).emit_signal ('kill_ball' )
19+
1420func test_can_make_game ():
1521 assert_not_null (Game .instance ())
1622
23+ func test_get_set_p1_score ():
24+ assert_accessors (_game , 'p1_score' , 0 , 10 )
25+
26+ func test_get_set_p2_score ():
27+ assert_accessors (_game , 'p2_score' , 0 , 10 )
28+
1729func test_when_p1_killbox_emits_kill_ball_then_ball_is_recentered ():
1830 var ball = _game .get_ball ()
1931 var orig_pos = ball .get_position ()
@@ -31,3 +43,30 @@ func test_when_p2_killbox_emits_kill_ball_then_ball_is_recentered():
3143 ball .set_position (Vector2 (1 , 1 ))
3244 kb .emit_signal ('kill_ball' )
3345 assert_eq (ball .get_position (), orig_pos )
46+
47+ func test_when_p1_kill_box_kills_ball_p2_score_increases ():
48+ _simulate_p2_score (_game )
49+ assert_eq (_game .get_p2_score (), 1 )
50+
51+ func test_when_p2_kill_box_kills_ball_p1_score_increases ():
52+ _simulate_p1_score (_game )
53+ assert_eq (_game .get_p1_score (), 1 )
54+
55+ func test_score_labels_show_score_on_start ():
56+ assert_eq (_game .get_node ("P1Score" ).get_text (), '0' , 'p1 initial score' )
57+ assert_eq (_game .get_node ("P2Score" ).get_text (), '0' , 'p2 initial score' )
58+
59+ func test_when_p1_scores_then_score_is_update ():
60+ _simulate_p1_score (_game )
61+ assert_eq (_game .get_node ("P1Score" ).get_text (), '1' )
62+
63+ func test_when_p2_scores_then_score_is_update ():
64+ _simulate_p2_score (_game )
65+ assert_eq (_game .get_node ("P2Score" ).get_text (), '1' )
66+
67+
68+
69+
70+
71+
72+
0 commit comments