-
Notifications
You must be signed in to change notification settings - Fork 1
/
game_test.rb
116 lines (99 loc) · 2.55 KB
/
game_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
require './test_helper'
require './game'
reporter_options = {color: true}
Minitest::Reporters.use! #[Minitest::Reporters::DefaultReporter.new(reporter_options)]
class GameTest < Minitest::Test
def setup
@game = Game.new
end
def test_20_rolls_of_0_is_0
(1..20).each do |roll|
@game.add_roll(0)
end
assert_equal(0, @game.score, "game score wrong for 0 pins")
end
def test_static_rolls_score_is_correct
(1..9).each do |pin_count|
(0..9).each do |frames|
@game.add_roll(pin_count)
@game.add_roll(0)
end
assert_equal(pin_count * 10, @game.score, "score is wrong first static test!")
@game.reset
end
end
def test_inverse_static_rolls_test
(0..9).each do |pin_count|
(0..9).each do |frames|
@game.add_roll(0)
@game.add_roll(pin_count)
end
assert_equal(pin_count * 10, @game.score, "score is wrong second static test")
@game.reset
end
end
def test_various_non_strike_or_spare_rolls
(1..9).each do |pin_count|
(0..9).each do |frames|
@game.add_roll(pin_count)
@game.add_roll(9 - pin_count)
end
assert_equal(90, @game.score, "various non strike or spare tests failed")
@game.reset
end
end
def test_one_spare
@game.add_roll(5)
@game.add_roll(5)
@game.add_roll(5)
@game.add_roll(0)
(1..8).each do |roll|
@game.add_roll(0)
@game.add_roll(0)
end
assert_equal(20, @game.score, "simple spare and gutters wrong")
end
def test_9_spares
(0..8).each do |frame|
@game.add_roll(5)
@game.add_roll(5)
end
@game.add_roll(5)
@game.add_roll(0)
assert_equal(140, @game.score, "9 spares and a 5 wrong")
end
def test_all_spares
(0..9).each do |frame|
@game.add_roll(5)
@game.add_roll(5)
end
@game.add_roll(5)
assert_equal(150, @game.score, "all spares wrong")
end
def test_one_strike
@game.add_roll(10)
@game.add_roll(5)
@game.add_roll(4)
(1..8).each do |roll|
@game.add_roll(0)
@game.add_roll(0)
end
assert_equal(28, @game.score, "simple strike, 2 non-spare balls, and gutters wrong")
end
def test_nine_strikes
(1..9).each do
@game.add_roll(10)
end
@game.add_roll(0)
@game.add_roll(0)
assert_equal(240, @game.score, "9 strikes, 2 gutter balls wrong")
end
def test_all_strikes
(1..10).each do
@game.add_roll(10)
end
@game.add_roll(10)
@game.add_roll(10)
assert_equal(300, @game.score, "9 strikes, 2 gutter balls wrong")
end
end