|
3 | 3 | require 'minitest/autorun'
|
4 | 4 | require_relative 'bowling'
|
5 | 5 |
|
6 |
| -class GameTest < Minitest::Test |
| 6 | +# Test data version: |
| 7 | +# 0a51cfc |
| 8 | +class BowlingTest < Minitest::Test |
7 | 9 | def setup
|
8 | 10 | @game = Game.new
|
9 | 11 | end
|
10 | 12 |
|
11 |
| - def test_must_be_able_to_roll_with_number_of_pins |
12 |
| - assert_respond_to @game, :roll |
13 |
| - assert_equal 1, @game.method(:roll).arity |
| 13 | + def roll(rolls) |
| 14 | + rolls.each { |pins| @game.roll(pins) } |
14 | 15 | end
|
15 | 16 |
|
16 |
| - def test_must_have_a_score |
17 |
| - skip |
18 |
| - assert_respond_to @game, :score |
| 17 | + def test_should_be_able_to_score_a_game_with_all_zeros |
| 18 | + roll([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) |
| 19 | + assert_equal 0, @game.score |
19 | 20 | end
|
20 | 21 |
|
21 |
| - def test_should_be_able_to_score_open_frame |
| 22 | + def test_should_be_able_to_score_a_game_with_no_strikes_or_spares |
22 | 23 | skip
|
23 |
| - @game.roll(3) |
24 |
| - @game.roll(4) |
25 |
| - roll_n_times(18, 0) |
26 |
| - assert_equal 7, @game.score |
| 24 | + roll([3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6]) |
| 25 | + assert_equal 90, @game.score |
27 | 26 | end
|
28 | 27 |
|
29 |
| - def test_should_be_able_to_score_multiple_frames |
| 28 | + def test_a_spare_followed_by_zeros_is_worth_ten_points |
30 | 29 | skip
|
31 |
| - [3, 4, 2, 3, 5, 2].each do |pins| |
32 |
| - @game.roll pins |
33 |
| - end |
34 |
| - roll_n_times(14, 0) |
35 |
| - assert_equal 19, @game.score |
| 30 | + roll([6, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) |
| 31 | + assert_equal 10, @game.score |
36 | 32 | end
|
37 | 33 |
|
38 |
| - def test_should_score_a_game_with_all_gutterballs |
| 34 | + def test_points_scored_in_the_roll_after_a_spare_are_counted_twice |
39 | 35 | skip
|
40 |
| - roll_n_times(20, 0) |
41 |
| - assert_equal 0, @game.score |
| 36 | + roll([6, 4, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) |
| 37 | + assert_equal 16, @game.score |
42 | 38 | end
|
43 | 39 |
|
44 |
| - def test_should_score_a_game_with_all_single_pin_rolls |
| 40 | + def test_consecutive_spares_each_get_a_one_roll_bonus |
45 | 41 | skip
|
46 |
| - roll_n_times(20, 1) |
47 |
| - assert_equal 20, @game.score |
| 42 | + roll([5, 5, 3, 7, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) |
| 43 | + assert_equal 31, @game.score |
48 | 44 | end
|
49 | 45 |
|
50 |
| - def test_should_allow_game_with_all_open_frames |
| 46 | + def test_a_spare_in_the_last_frame_gets_a_one_roll_bonus_that_is_counted_once |
51 | 47 | skip
|
52 |
| - roll_n_times(10, [3, 6]) |
53 |
| - assert_equal 90, @game.score |
| 48 | + roll([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 3, 7]) |
| 49 | + assert_equal 17, @game.score |
54 | 50 | end
|
55 | 51 |
|
56 |
| - def test_should_correctly_score_a_strike_that_is_not_on_the_last_frame |
| 52 | + def test_a_strike_earns_ten_points_in_frame_with_a_single_roll |
57 | 53 | skip
|
58 |
| - @game.roll(10) |
59 |
| - @game.roll(5) |
60 |
| - @game.roll(3) |
61 |
| - roll_n_times(16, 0) |
62 |
| - |
63 |
| - assert_equal 26, @game.score |
| 54 | + roll([10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) |
| 55 | + assert_equal 10, @game.score |
64 | 56 | end
|
65 | 57 |
|
66 |
| - def test_should_score_a_spare_that_is_not_on_the_last_frame |
| 58 | + def test_points_scored_in_the_two_rolls_after_a_strike_are_counted_twice_as_a_bonus |
67 | 59 | skip
|
68 |
| - @game.roll(5) |
69 |
| - @game.roll(5) |
70 |
| - @game.roll(3) |
71 |
| - @game.roll(4) |
72 |
| - roll_n_times(16, 0) |
73 |
| - |
74 |
| - assert_equal 20, @game.score |
| 60 | + roll([10, 5, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) |
| 61 | + assert_equal 26, @game.score |
75 | 62 | end
|
76 | 63 |
|
77 |
| - def test_should_score_multiple_strikes_in_a_row |
| 64 | + def test_consecutive_strikes_each_get_the_two_roll_bonus |
78 | 65 | skip
|
79 |
| - @game.roll(10) |
80 |
| - @game.roll(10) |
81 |
| - @game.roll(10) |
82 |
| - @game.roll(5) |
83 |
| - @game.roll(3) |
84 |
| - roll_n_times(12, 0) |
85 |
| - |
| 66 | + roll([10, 10, 10, 5, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) |
86 | 67 | assert_equal 81, @game.score
|
87 | 68 | end
|
88 | 69 |
|
89 |
| - def test_should_score_multiple_spares_in_a_row |
| 70 | + def test_a_strike_in_the_last_frame_gets_a_two_roll_bonus_that_is_counted_once |
90 | 71 | skip
|
91 |
| - @game.roll(5) |
92 |
| - @game.roll(5) |
93 |
| - @game.roll(3) |
94 |
| - @game.roll(7) |
95 |
| - @game.roll(4) |
96 |
| - @game.roll(1) |
97 |
| - roll_n_times(14, 0) |
98 |
| - |
99 |
| - assert_equal 32, @game.score |
| 72 | + roll([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 7, 1]) |
| 73 | + assert_equal 18, @game.score |
100 | 74 | end
|
101 | 75 |
|
102 |
| - def test_should_allow_fill_balls_when_the_final_frame_is_strike |
| 76 | + def test_rolling_a_spare_with_the_two_roll_bonus_does_not_get_a_bonus_roll |
103 | 77 | skip
|
104 |
| - roll_n_times(18, 0) |
105 |
| - @game.roll(10) |
106 |
| - @game.roll(7) |
107 |
| - @game.roll(1) |
108 |
| - |
109 |
| - assert_equal 18, @game.score |
| 78 | + roll([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 7, 3]) |
| 79 | + assert_equal 20, @game.score |
110 | 80 | end
|
111 | 81 |
|
112 |
| - def test_should_allow_fill_ball_in_last_frame_if_spare |
| 82 | + def test_strikes_with_the_two_roll_bonus_do_not_get_bonus_rolls |
113 | 83 | skip
|
114 |
| - roll_n_times(18, 0) |
115 |
| - @game.roll(9) |
116 |
| - @game.roll(1) |
117 |
| - @game.roll(7) |
118 |
| - |
119 |
| - assert_equal 17, @game.score |
| 84 | + roll([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 10]) |
| 85 | + assert_equal 30, @game.score |
120 | 86 | end
|
121 | 87 |
|
122 |
| - def test_should_allow_fill_balls_to_be_strike |
| 88 | + def test_a_strike_with_the_one_roll_bonus_after_a_spare_in_the_last_frame_does_not_get_a_bonus |
123 | 89 | skip
|
124 |
| - roll_n_times(18, 0) |
125 |
| - @game.roll(10) |
126 |
| - @game.roll(10) |
127 |
| - @game.roll(10) |
128 |
| - |
129 |
| - assert_equal 30, @game.score |
| 90 | + roll([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 3, 10]) |
| 91 | + assert_equal 20, @game.score |
130 | 92 | end
|
131 | 93 |
|
132 |
| - def test_should_score_a_perfect_game |
| 94 | + def test_all_strikes_is_a_perfect_game |
133 | 95 | skip
|
134 |
| - roll_n_times(12, 10) |
| 96 | + roll([10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) |
135 | 97 | assert_equal 300, @game.score
|
136 | 98 | end
|
137 | 99 |
|
138 |
| - def test_should_not_allow_rolls_with_negative_pins |
| 100 | + def test_rolls_can_not_score_negative_points |
139 | 101 | skip
|
140 |
| - assert_raises( |
141 |
| - RuntimeError, |
142 |
| - 'Pins must have a value from 0 to 10') do |
143 |
| - @game.roll(-1) |
144 |
| - end |
| 102 | + assert_raises StandardError do |
| 103 | + roll([-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) |
| 104 | + @game.score |
| 105 | + end |
145 | 106 | end
|
146 | 107 |
|
147 |
| - def test_should_not_allow_rolls_better_than_strike |
| 108 | + def test_a_roll_can_not_score_more_than_10_points |
148 | 109 | skip
|
149 |
| - assert_raises( |
150 |
| - RuntimeError, |
151 |
| - 'Pins must have a value from 0 to 10') do |
152 |
| - @game.roll(11) |
153 |
| - end |
| 110 | + assert_raises StandardError do |
| 111 | + roll([11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) |
| 112 | + @game.score |
| 113 | + end |
154 | 114 | end
|
155 | 115 |
|
156 |
| - def test_should_not_allow_two_normal_rolls_better_than_strike |
| 116 | + def test_two_rolls_in_a_frame_can_not_score_more_than_10_points |
157 | 117 | skip
|
158 |
| - assert_raises RuntimeError, 'Pin count exceeds pins on the lane' do |
159 |
| - @game.roll(5) |
160 |
| - @game.roll(6) |
| 118 | + assert_raises StandardError do |
| 119 | + roll([5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) |
| 120 | + @game.score |
161 | 121 | end
|
162 | 122 | end
|
163 | 123 |
|
164 |
| - def test_should_not_allow_two_normal_rolls_better_than_strike_in_last_frame |
| 124 | + def test_two_bonus_rolls_after_a_strike_in_the_last_frame_can_not_score_more_than_10_points |
165 | 125 | skip
|
166 |
| - roll_n_times(18, 0) |
167 |
| - assert_raises RuntimeError, 'Pin count exceeds pins on the lane' do |
168 |
| - @game.roll(10) |
169 |
| - @game.roll(5) |
170 |
| - @game.roll(6) |
| 126 | + assert_raises StandardError do |
| 127 | + roll([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 5, 6]) |
| 128 | + @game.score |
171 | 129 | end
|
172 | 130 | end
|
173 | 131 |
|
174 |
| - def test_should_not_allow_to_take_score_at_the_beginning |
| 132 | + def test_an_unstarted_game_can_not_be_scored |
175 | 133 | skip
|
176 |
| - assert_raises( |
177 |
| - RuntimeError, |
178 |
| - 'Score cannot be taken until the end of the game', |
179 |
| - ) do |
| 134 | + assert_raises StandardError do |
| 135 | + roll([]) |
180 | 136 | @game.score
|
181 | 137 | end
|
182 | 138 | end
|
183 | 139 |
|
184 |
| - def test_should_not_allow_to_take_score_before_game_has_ended |
| 140 | + def test_an_incomplete_game_can_not_be_scored |
185 | 141 | skip
|
186 |
| - roll_n_times(19, 5) |
187 |
| - assert_raises( |
188 |
| - RuntimeError, |
189 |
| - 'Score cannot be taken until the end of the game') do |
190 |
| - @game.score |
191 |
| - end |
| 142 | + assert_raises StandardError do |
| 143 | + roll([0, 0]) |
| 144 | + @game.score |
| 145 | + end |
192 | 146 | end
|
193 | 147 |
|
194 |
| - def test_should_not_allow_rolls_after_the_tenth_frame |
| 148 | + def test_a_game_with_more_than_ten_frames_can_not_be_scored |
195 | 149 | skip
|
196 |
| - roll_n_times(20, 0) |
197 |
| - assert_raises( |
198 |
| - RuntimeError, |
199 |
| - 'Should not be able to roll after game is over', |
200 |
| - ) do |
201 |
| - @game.roll(0) |
| 150 | + assert_raises StandardError do |
| 151 | + roll([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) |
| 152 | + @game.score |
202 | 153 | end
|
203 | 154 | end
|
204 | 155 |
|
205 |
| - def test_should_not_calculate_score_before_fill_balls_have_been_played |
| 156 | + def test_bonus_rolls_for_a_strike_in_the_last_frame_must_be_rolled_before_score_can_be_calculated |
206 | 157 | skip
|
207 |
| - roll_n_times(10, 10) |
| 158 | + assert_raises StandardError do |
| 159 | + roll([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10]) |
| 160 | + @game.score |
| 161 | + end |
| 162 | + end |
208 | 163 |
|
209 |
| - assert_raises RuntimeError, 'Game is not yet over, cannot score!' do |
| 164 | + def test_both_bonus_rolls_for_a_strike_in_the_last_frame_must_be_rolled_before_score_can_be_calculated |
| 165 | + skip |
| 166 | + assert_raises StandardError do |
| 167 | + roll([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10]) |
210 | 168 | @game.score
|
211 | 169 | end
|
212 | 170 | end
|
213 | 171 |
|
214 |
| - def roll_n_times(rolls, pins) |
215 |
| - rolls.times do |
216 |
| - Array(pins).each { |value| @game.roll(value) } |
| 172 | + def test_bonus_roll_for_a_spare_in_the_last_frame_must_be_rolled_before_score_can_be_calculated |
| 173 | + skip |
| 174 | + assert_raises StandardError do |
| 175 | + roll([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 3]) |
| 176 | + @game.score |
217 | 177 | end
|
218 | 178 | end
|
219 |
| - private :roll_n_times |
220 | 179 |
|
221 |
| - # Don't forget to define a constant VERSION inside of BookKeeping. |
| 180 | + # Problems in exercism evolve over time, as we find better ways to ask |
| 181 | + # questions. |
| 182 | + # The version number refers to the version of the problem you solved, |
| 183 | + # not your solution. |
| 184 | + # |
| 185 | + # Define a constant named VERSION inside of the top level BookKeeping |
| 186 | + # module, which may be placed near the end of your file. |
| 187 | + # |
| 188 | + # In your file, it will look like this: |
| 189 | + # |
| 190 | + # module BookKeeping |
| 191 | + # VERSION = 1 # Where the version number matches the one in the test. |
| 192 | + # end |
| 193 | + # |
| 194 | + # If you are curious, read more about constants on RubyDoc: |
| 195 | + # http://ruby-doc.org/docs/ruby-doc-bundle/UsersGuide/rg/constants.html |
| 196 | + |
222 | 197 | def test_bookkeeping
|
223 | 198 | skip
|
224 |
| - assert_equal 1, BookKeeping::VERSION |
| 199 | + assert_equal 2, BookKeeping::VERSION |
225 | 200 | end
|
226 | 201 | end
|
0 commit comments