Bowling 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/lib/bowling/ball.rb +31 -31
- data/lib/bowling/null_ball.rb +6 -6
- data/lib/bowling/null_frame.rb +6 -6
- data/lib/bowling/version.rb +1 -1
- data/spec/lib/ball_spec.rb +8 -8
- data/spec/lib/frame_spec.rb +1 -5
- data/spec/lib/game_spec.rb +112 -112
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZWZlZTI1Yzc4NTBlOWMxZGNmZWUwZDFmY2M0NGQwNjAyMzkxOGY4ZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MjQ1MWM3OTJjMjRlYmIyYjFlNTFmZGNmMTY0ZTU1MzhlMzIyOTA1ZA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NGFiN2E4MTk0YzczZjMyODU4OWFlNjg3YTBkNGEyYWNhMWU5NjIwNzNmMTIz
|
10
|
+
NzFmMTZhZmZiODM4NTljNzdkNmZhZWNiMjM3ZWI2OTg0NjQyNDc4N2E2MmNj
|
11
|
+
YTg3MzcyOWI1OGI0Y2QwMmY2MmUwZDVhOWU3NWViMjk5M2YzZjc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YmU1MTM2MGFjNmI4M2M3MTNjM2JiZDRhMjVjNDE0OGMxMTJiNjMyMGYxZjg0
|
14
|
+
N2RjMWYzM2I1YjJiYmQ4ZTQ5MGRkYWUxNmM2YmYyYzNlODhjOWQyODU4ZDBi
|
15
|
+
NmVkM2U3ZDlhY2MyMzE4MjNmYTc0OTU4MmJmNzQzMzY4N2E3ZmM=
|
data/lib/bowling/ball.rb
CHANGED
@@ -1,49 +1,49 @@
|
|
1
1
|
class Bowling::Ball
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
attr_accessor :ball_position, :knocked_pins, :frame
|
4
|
+
alias_method :score, :knocked_pins
|
5
5
|
|
6
6
|
|
7
|
-
|
7
|
+
#= Construction ===
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
def initialize( ball_position, frame, knocked_pins = nil )
|
10
|
+
@ball_position = ball_position
|
11
|
+
@frame = frame
|
12
|
+
@knocked_pins = knocked_pins || 0
|
13
|
+
end
|
14
14
|
|
15
15
|
|
16
|
-
|
16
|
+
#= Public methods ===
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
def knock_over( amount )
|
19
|
+
knocked_pins += amount
|
20
|
+
raise Error.new 'Knocked pins can not exceed 10' if knocked_pins > 10
|
21
|
+
end
|
22
22
|
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
def next_ball
|
25
|
+
if strike?
|
26
|
+
frame.next_frame.first_ball
|
27
|
+
else
|
28
|
+
frame.balls[ball_position + 1]
|
29
|
+
end
|
30
|
+
end
|
31
31
|
|
32
32
|
|
33
|
-
|
33
|
+
#= Calculations ===
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
def strike?
|
36
|
+
first_ball? and perfect?
|
37
|
+
end
|
38
38
|
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
def perfect?
|
41
|
+
knocked_pins == 10
|
42
|
+
end
|
43
|
+
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
def first_ball?
|
46
|
+
ball_position == 0
|
47
|
+
end
|
48
48
|
|
49
49
|
end
|
data/lib/bowling/null_ball.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
class Bowling::NullBall < NilClass
|
2
|
-
|
2
|
+
class << self
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
def score ; 0 ; end
|
5
|
+
def knocked_pins ; 0 ; end
|
6
|
+
def strike? ; false ; end
|
7
|
+
def perfect? ; false ; end
|
8
8
|
|
9
|
-
|
9
|
+
end
|
10
10
|
end
|
data/lib/bowling/null_frame.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
class Bowling::NullFrame < NilClass
|
2
|
-
|
2
|
+
class << self
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
def strike? ; false ; end
|
5
|
+
def balls ; [] ; end
|
6
|
+
def first_ball ; Bowling::NullBall ; end
|
7
|
+
|
8
|
+
end
|
9
9
|
end
|
data/lib/bowling/version.rb
CHANGED
data/spec/lib/ball_spec.rb
CHANGED
@@ -2,18 +2,18 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
|
4
4
|
describe Bowling::Ball do
|
5
|
-
|
6
|
-
|
5
|
+
|
6
|
+
subject( :instance ){ Bowling::Ball.new 1, frame }
|
7
7
|
|
8
8
|
|
9
|
-
|
9
|
+
#= Lets ===
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
let( :game ){ Bowling::Game.new }
|
12
|
+
let( :frame ){ Bowling::Frame.new 1, game }
|
13
13
|
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
#= Specs ===
|
16
|
+
|
17
|
+
its( :knocked_pins ){ should equal 0 }
|
18
18
|
|
19
19
|
end
|
data/spec/lib/frame_spec.rb
CHANGED
@@ -2,9 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
|
4
4
|
describe Bowling::Frame do
|
5
|
-
|
6
|
-
subject( :row_number ){ 1 }
|
7
|
-
subject( :instance ){ described_class.new row_number, game }
|
5
|
+
subject( :instance ){ described_class.new 1, game }
|
8
6
|
|
9
7
|
|
10
8
|
#= Lets ===
|
@@ -40,8 +38,6 @@ describe Bowling::Frame do
|
|
40
38
|
#= General Specs ===
|
41
39
|
|
42
40
|
describe 'with perfect final frame' do
|
43
|
-
let( :row_number ){ 9 }
|
44
|
-
|
45
41
|
subject{ described_class.new 9, game, perfect_final_frame }
|
46
42
|
|
47
43
|
specify{ subject.balls.length.should == 3 }
|
data/spec/lib/game_spec.rb
CHANGED
@@ -3,117 +3,117 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe Bowling::Game do
|
5
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
|
-
|
117
|
-
|
6
|
+
#= Lets ===
|
7
|
+
|
8
|
+
let( :perfect_game ){ Array.new( 9 ){ [ 10 ] } << [ 10, 10, 10 ] }
|
9
|
+
let( :spare_game ){ Array.new( 9 ){ [ 0, 10 ] } << [ 0, 10, 0 ] }
|
10
|
+
let( :all_ones ){ Array.new( 9 ){ [ 1, 1 ] } << [ 1, 1 ] }
|
11
|
+
let( :all_twos ){ Array.new( 9 ){ [ 2, 2 ] } << [ 2, 2 ] }
|
12
|
+
|
13
|
+
let( :geometric_game ){ Array.new( 9 ){ |i| [ i, i ] } << [ 10, 10, 10 ] }
|
14
|
+
|
15
|
+
|
16
|
+
#= Specs ===
|
17
|
+
|
18
|
+
subject{ described_class.new }
|
19
|
+
|
20
|
+
it{ should respond_to :frames }
|
21
|
+
|
22
|
+
|
23
|
+
describe '#score' do
|
24
|
+
context 'with perfect_game data' do
|
25
|
+
before( :each ){ subject.load perfect_game }
|
26
|
+
|
27
|
+
its( :score ){ should == 300 }
|
28
|
+
|
29
|
+
specify( 'all frames have a score of 30' ){
|
30
|
+
subject.frames.each do |frame|
|
31
|
+
frame.score.should equal 30
|
32
|
+
end
|
33
|
+
}
|
34
|
+
|
35
|
+
describe 'penultimate frame' do
|
36
|
+
specify{ subject.frames[8].base_score.should equal 10 }
|
37
|
+
specify{ subject.frames[8].strike_score.should equal 20 }
|
38
|
+
specify{ subject.frames[8].spare_score.should equal 0 }
|
39
|
+
|
40
|
+
specify{ subject.frames[8].next_ball.ball_position.should equal 0 }
|
41
|
+
specify{ subject.frames[8].next_next_ball.ball_position.should equal 1 }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'with spare_game data' do
|
46
|
+
before( :each ){ subject.load spare_game }
|
47
|
+
|
48
|
+
its( :score ){ should == 100 }
|
49
|
+
|
50
|
+
specify( 'all frames have a score of 30' ){
|
51
|
+
subject.frames.each do |frame|
|
52
|
+
frame.score.should equal 10
|
53
|
+
end
|
54
|
+
}
|
55
|
+
|
56
|
+
describe 'ultimate frame' do
|
57
|
+
specify{ subject.frames[9].base_score.should equal 10 }
|
58
|
+
specify{ subject.frames[9].strike_score.should equal 0 }
|
59
|
+
specify{ subject.frames[9].spare_score.should equal 0 }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'with all_ones data' do
|
64
|
+
before( :each ){ subject.load all_ones }
|
65
|
+
|
66
|
+
its( :score ){ should == 20 }
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'with all_twos data' do
|
70
|
+
before( :each ){ subject.load all_twos }
|
71
|
+
|
72
|
+
its( :score ){ should == 40 }
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'with geometric_game data' do
|
76
|
+
before( :each ){ subject.load geometric_game }
|
77
|
+
|
78
|
+
describe '#base_score' do
|
79
|
+
specify{ subject.frames[ 0].base_score.should equal 0 }
|
80
|
+
specify{ subject.frames[ 1].base_score.should equal 2 }
|
81
|
+
specify{ subject.frames[ 2].base_score.should equal 4 }
|
82
|
+
specify{ subject.frames[ 3].base_score.should equal 6 }
|
83
|
+
specify{ subject.frames[ 4].base_score.should equal 8 }
|
84
|
+
specify{ subject.frames[ 5].base_score.should equal 10 }
|
85
|
+
specify{ subject.frames[ 6].base_score.should equal 10 }
|
86
|
+
specify{ subject.frames[ 7].base_score.should equal 10 }
|
87
|
+
specify{ subject.frames[ 8].base_score.should equal 10 }
|
88
|
+
specify{ subject.frames[ 9].base_score.should equal 10 }
|
89
|
+
end
|
90
|
+
|
91
|
+
describe '#spare_score' do
|
92
|
+
specify{ subject.frames[ 0].spare_score.should equal 0 }
|
93
|
+
specify{ subject.frames[ 1].spare_score.should equal 0 }
|
94
|
+
specify{ subject.frames[ 2].spare_score.should equal 0 }
|
95
|
+
specify{ subject.frames[ 3].spare_score.should equal 0 }
|
96
|
+
specify{ subject.frames[ 4].spare_score.should equal 0 }
|
97
|
+
specify{ subject.frames[ 5].spare_score.should equal 6 }
|
98
|
+
specify{ subject.frames[ 6].spare_score.should equal 7 }
|
99
|
+
specify{ subject.frames[ 7].spare_score.should equal 8 }
|
100
|
+
specify{ subject.frames[ 8].spare_score.should equal 10 }
|
101
|
+
specify{ subject.frames[ 9].spare_score.should equal 0 }
|
102
|
+
end
|
103
|
+
|
104
|
+
describe '#strike_score' do
|
105
|
+
specify{ subject.frames[ 0].strike_score.should equal 0 }
|
106
|
+
specify{ subject.frames[ 1].strike_score.should equal 0 }
|
107
|
+
specify{ subject.frames[ 2].strike_score.should equal 0 }
|
108
|
+
specify{ subject.frames[ 3].strike_score.should equal 0 }
|
109
|
+
specify{ subject.frames[ 4].strike_score.should equal 0 }
|
110
|
+
specify{ subject.frames[ 5].strike_score.should equal 0 }
|
111
|
+
specify{ subject.frames[ 6].strike_score.should equal 0 }
|
112
|
+
specify{ subject.frames[ 7].strike_score.should equal 0 }
|
113
|
+
specify{ subject.frames[ 8].strike_score.should equal 0 }
|
114
|
+
specify{ subject.frames[ 9].strike_score.should equal 20 }
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
118
|
|
119
119
|
end
|