Bowling 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/Gemfile +8 -0
- data/Guardfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/bin/bowling_game +25 -0
- data/bowling.gemspec +30 -0
- data/lib/bowling.rb +11 -0
- data/lib/bowling/ball.rb +49 -0
- data/lib/bowling/frame.rb +144 -0
- data/lib/bowling/game.rb +22 -0
- data/lib/bowling/null_ball.rb +10 -0
- data/lib/bowling/null_frame.rb +9 -0
- data/lib/bowling/version.rb +3 -0
- data/spec/lib/ball_spec.rb +19 -0
- data/spec/lib/frame_spec.rb +99 -0
- data/spec/lib/game_spec.rb +119 -0
- data/spec/spec_helper.rb +2 -0
- metadata +180 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YjZjYjUzZDM3OWM2ZWM3ZmU4MDg0NDAxZWZmODc4YzkwMGUyMmMyMQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NGNjYTQzNmRkNGU2NWM4NTgzZjk2YjAxY2YyMDcxMjhjZWEyYTI2Zg==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZWFlYTM4ZWFiZWMwNDNlMjE3M2YzMGUwMTcyMDg1MWExMTI1NGExZDNlYjMy
|
10
|
+
MWQ2OTA4MTQ5MzBjNWM2MzMyZTI3YTE3ZTg2OTgxOGEyN2EzYWI5YTVkYjdl
|
11
|
+
YWI5YTQ5ZTUwMTczODllZmUxMTg2MGI0NDg5NzQxN2Q4MTM3OTc=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZjA4NWZhMzk5MzliOTk5ZDc2YjY3NjEyNGYxYmZjZGJlMGJhNGVkOWZkZmEw
|
14
|
+
Nzk3YTNiZDIyMjc2YjNjZDBiMWUxNzE3NzJmMmQwZmNmNjE3YjM4YzQ0NGFi
|
15
|
+
YjM4OGMxZTA5M2UwMWUxMmUwMWNiZjUwZjIxMGFhYzEyZDVkMjk=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
guard 'bundler' do
|
2
|
+
watch('Gemfile')
|
3
|
+
watch(/^.+\.gemspec/)
|
4
|
+
end
|
5
|
+
|
6
|
+
|
7
|
+
guard :rspec, cli: "--color --format nested" do
|
8
|
+
watch(%r{^spec/.+_spec\.rb$})
|
9
|
+
watch(%r{^lib/bowling/(.+)\.rb$}){ |m| "spec/lib/#{m[1]}_spec.rb" }
|
10
|
+
watch('spec/spec_helper.rb'){ "spec" }
|
11
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Brett Richardson
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Bowling
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'bowling'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install bowling
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/bowling_game
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'highline/import'
|
4
|
+
require 'formatador'
|
5
|
+
require 'bowling'
|
6
|
+
|
7
|
+
|
8
|
+
game = Bowling::Game.new
|
9
|
+
|
10
|
+
Formatador.display_line "[green]=== Starting Game ===[/]"
|
11
|
+
|
12
|
+
game.frames.each_with_index.map do |frame, i|
|
13
|
+
frame.balls.each_with_index.map do |ball, j|
|
14
|
+
ball.knocked_pins = ask(
|
15
|
+
" - Score for frame #{i+1} ball #{j+1}?", Integer
|
16
|
+
){ |q|
|
17
|
+
q.default = 0
|
18
|
+
q.in = 0..10
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
Formatador.display_line "[red]=== Total Game Score: #{game.score} ===[/]"
|
24
|
+
|
25
|
+
|
data/bowling.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bowling/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "Bowling"
|
8
|
+
spec.version = Bowling::VERSION
|
9
|
+
spec.authors = [ "Brett Richardson" ]
|
10
|
+
spec.email = [ "Brett.Richardson.NZ@gmail.com" ]
|
11
|
+
spec.description = 'Calculates a bowling score'
|
12
|
+
spec.summary = File.expand_path File.join( File.dirname( __FILE__ ), 'README.md' )
|
13
|
+
spec.homepage = "http://www.dablweb.com"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = [ `git ls-files`.split( $/ ) ]
|
17
|
+
spec.executables = [ 'bowling_game' ]
|
18
|
+
spec.test_files = spec.files.grep( %r{^(test|spec|features)/} )
|
19
|
+
spec.require_paths = [ "lib" ]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "highline"
|
22
|
+
spec.add_runtime_dependency "formatador"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
spec.add_development_dependency "guard"
|
28
|
+
spec.add_development_dependency "guard-rspec"
|
29
|
+
spec.add_development_dependency "guard-bundler"
|
30
|
+
end
|
data/lib/bowling.rb
ADDED
data/lib/bowling/ball.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
class Bowling::Ball
|
2
|
+
|
3
|
+
attr_accessor :ball_position, :knocked_pins, :frame
|
4
|
+
alias_method :score, :knocked_pins
|
5
|
+
|
6
|
+
|
7
|
+
#= Construction ===
|
8
|
+
|
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
|
+
|
15
|
+
|
16
|
+
#= Public methods ===
|
17
|
+
|
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
|
+
|
23
|
+
|
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
|
+
|
32
|
+
|
33
|
+
#= Calculations ===
|
34
|
+
|
35
|
+
def strike?
|
36
|
+
first_ball? and perfect?
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
def perfect?
|
41
|
+
knocked_pins == 10
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
def first_ball?
|
46
|
+
ball_position == 0
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
class Bowling::Frame
|
2
|
+
|
3
|
+
attr_accessor :balls, :frame_number, :game
|
4
|
+
|
5
|
+
|
6
|
+
#= Construction ===
|
7
|
+
|
8
|
+
def initialize( frame_number, game, data = nil )
|
9
|
+
@frame_number = frame_number
|
10
|
+
@game = game
|
11
|
+
@balls = Array.new( total_balls ){ |i| Bowling::Ball.new i, self }
|
12
|
+
|
13
|
+
load data if data
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
#= Public methods ===
|
18
|
+
|
19
|
+
##
|
20
|
+
# Load an array of scores (integers) representing each ball
|
21
|
+
#
|
22
|
+
def load( data )
|
23
|
+
raise ArgumentError.new '#load needs array' unless data.instance_of? Array
|
24
|
+
data.each_with_index{ |pins, i| @balls[i].knocked_pins = pins }
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
def first_ball
|
29
|
+
balls[0]
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def next_frame
|
34
|
+
get_frame frame_number+1
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def next_next_frame
|
39
|
+
get_frame frame_number+2
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
def next_ball
|
44
|
+
if final?
|
45
|
+
balls[1]
|
46
|
+
else
|
47
|
+
next_frame.first_ball
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def next_next_ball
|
53
|
+
if final?
|
54
|
+
next_frame.balls[2]
|
55
|
+
elsif next_frame.strike? and not next_frame.final?
|
56
|
+
next_next_frame.first_ball
|
57
|
+
else
|
58
|
+
next_frame.balls[1]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
#= Calculations ===
|
64
|
+
|
65
|
+
def score
|
66
|
+
base_score + strike_score + spare_score
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
##
|
71
|
+
# The base score ignores the 3rd ball of the final frame
|
72
|
+
#
|
73
|
+
def base_score
|
74
|
+
[ balls[0].score + balls[1].score, 10 ].min # No frame should have more than 10
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
##
|
79
|
+
# Strike score represents the _additional_ score added to the base when a strike occurs
|
80
|
+
# It is equal to the knocked_pins of the following 2 balls
|
81
|
+
#
|
82
|
+
def strike_score
|
83
|
+
return 0 unless strike?
|
84
|
+
|
85
|
+
if final?
|
86
|
+
balls[1].score + balls[2].score
|
87
|
+
else
|
88
|
+
next_ball.score + next_next_ball.score
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
##
|
94
|
+
# Spare score represents the _additional_ score added to the base when a spare occurs
|
95
|
+
# It is equal to the knocked_pins of the following ball
|
96
|
+
#
|
97
|
+
def spare_score
|
98
|
+
return 0 unless spare?
|
99
|
+
|
100
|
+
if final?
|
101
|
+
balls[2].score
|
102
|
+
else
|
103
|
+
next_ball.score
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
def total_balls
|
109
|
+
final? ? 3 : 2
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
##
|
114
|
+
# Returns true if this is the last frame of the game
|
115
|
+
#
|
116
|
+
def final?
|
117
|
+
frame_number == 9 # Frame with index 9 is 10th frame
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
def strike?
|
122
|
+
first_ball.perfect?
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
def spare?
|
127
|
+
not strike? and ( balls[0].score + balls[1].score >= 10 )
|
128
|
+
end
|
129
|
+
|
130
|
+
|
131
|
+
#=============================================================================
|
132
|
+
protected
|
133
|
+
#=============================================================================
|
134
|
+
|
135
|
+
|
136
|
+
def get_frame( number )
|
137
|
+
if game.frames[number]
|
138
|
+
game.frames[number]
|
139
|
+
else
|
140
|
+
Bowling::NullFrame
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
data/lib/bowling/game.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
class Bowling::Game
|
2
|
+
|
3
|
+
attr_accessor :frames
|
4
|
+
|
5
|
+
|
6
|
+
def initialize( data = nil )
|
7
|
+
@frames = Array.new( 10 ){ |i| Bowling::Frame.new i, self }
|
8
|
+
load data if data
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
def load( data )
|
13
|
+
raise ArgumentError.new '#load needs array' unless data.instance_of? Array
|
14
|
+
data.each_with_index{ |frame, i| @frames[i].load frame }
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def score
|
19
|
+
frames.inject( 0 ){ |total, frame| total + frame.score }
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe Bowling::Ball do
|
5
|
+
|
6
|
+
subject( :instance ){ Bowling::Ball.new 1, frame }
|
7
|
+
|
8
|
+
|
9
|
+
#= Lets ===
|
10
|
+
|
11
|
+
let( :game ){ Bowling::Game.new }
|
12
|
+
let( :frame ){ Bowling::Frame.new 1, game }
|
13
|
+
|
14
|
+
|
15
|
+
#= Specs ===
|
16
|
+
|
17
|
+
its( :knocked_pins ){ should equal 0 }
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe Bowling::Frame do
|
5
|
+
|
6
|
+
subject( :row_number ){ 1 }
|
7
|
+
subject( :instance ){ described_class.new row_number, game }
|
8
|
+
|
9
|
+
|
10
|
+
#= Lets ===
|
11
|
+
|
12
|
+
let( :game ){ Bowling::Game.new }
|
13
|
+
let( :perfect_frame ){ [ 10, 0 ] }
|
14
|
+
let( :equal_spare ){ [ 5, 5 ] }
|
15
|
+
let( :gutter_frame ){ [ 0, 0 ] }
|
16
|
+
let( :perfect_final_frame ){ [ 10, 10, 10 ] }
|
17
|
+
|
18
|
+
|
19
|
+
#= Specs ===
|
20
|
+
|
21
|
+
it{ should respond_to :frame_number }
|
22
|
+
it{ should respond_to :balls }
|
23
|
+
|
24
|
+
|
25
|
+
#= Methods ===
|
26
|
+
|
27
|
+
describe '#load' do
|
28
|
+
describe 'with perfect frame' do
|
29
|
+
before( :each ){ subject.load perfect_frame }
|
30
|
+
|
31
|
+
specify{
|
32
|
+
subject.load perfect_frame
|
33
|
+
subject.balls[0].knocked_pins.should equal 10
|
34
|
+
subject.balls[1].knocked_pins.should equal 0
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
#= General Specs ===
|
41
|
+
|
42
|
+
describe 'with perfect final frame' do
|
43
|
+
let( :row_number ){ 9 }
|
44
|
+
|
45
|
+
subject{ described_class.new 9, game, perfect_final_frame }
|
46
|
+
|
47
|
+
specify{ subject.balls.length.should == 3 }
|
48
|
+
specify{ subject.base_score.should == 10 }
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
describe 'basic frame' do
|
53
|
+
before( :each ){ subject.load [ 3, 4 ] }
|
54
|
+
|
55
|
+
specify{ subject.base_score.should equal 7 }
|
56
|
+
specify{ subject.strike_score.should equal 0 }
|
57
|
+
specify{ subject.spare_score.should equal 0 }
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
describe 'strike frame' do
|
62
|
+
before( :each ){ subject.load [ 10 ] }
|
63
|
+
|
64
|
+
specify{ subject.base_score.should equal 10 }
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
describe 'perfect before final frame' do
|
69
|
+
subject{ described_class.new 8, game, [ 10, 0 ] }
|
70
|
+
|
71
|
+
before( :each ){
|
72
|
+
subject.stub next_frame: described_class.new( 9, game, [ 10, 10, 10 ] )
|
73
|
+
}
|
74
|
+
|
75
|
+
specify{ subject.base_score.should equal 10 }
|
76
|
+
specify{ subject.strike_score.should equal 20 }
|
77
|
+
specify{ subject.spare_score.should equal 0 }
|
78
|
+
specify{ subject.next_ball.score.should equal 10 }
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
describe 'perfect final frame' do
|
83
|
+
subject{ described_class.new 9, game, [ 10, 10, 10 ] }
|
84
|
+
|
85
|
+
specify{ subject.base_score.should equal 10 }
|
86
|
+
specify{ subject.strike_score.should equal 20 }
|
87
|
+
specify{ subject.spare_score.should equal 0 }
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
describe 'spare final frame' do
|
92
|
+
subject{ described_class.new 9, game, [ 0, 10, 10 ] }
|
93
|
+
|
94
|
+
specify{ subject.base_score.should equal 10 }
|
95
|
+
specify{ subject.strike_score.should equal 0 }
|
96
|
+
specify{ subject.spare_score.should equal 10 }
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe Bowling::Game do
|
5
|
+
|
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
|
+
|
119
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Bowling
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brett Richardson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: highline
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: formatador
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: guard-rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: guard-bundler
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: Calculates a bowling score
|
126
|
+
email:
|
127
|
+
- Brett.Richardson.NZ@gmail.com
|
128
|
+
executables:
|
129
|
+
- bowling_game
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- .gitignore
|
134
|
+
- Gemfile
|
135
|
+
- Guardfile
|
136
|
+
- LICENSE.txt
|
137
|
+
- README.md
|
138
|
+
- Rakefile
|
139
|
+
- bin/bowling_game
|
140
|
+
- bowling.gemspec
|
141
|
+
- lib/bowling.rb
|
142
|
+
- lib/bowling/ball.rb
|
143
|
+
- lib/bowling/frame.rb
|
144
|
+
- lib/bowling/game.rb
|
145
|
+
- lib/bowling/null_ball.rb
|
146
|
+
- lib/bowling/null_frame.rb
|
147
|
+
- lib/bowling/version.rb
|
148
|
+
- spec/lib/ball_spec.rb
|
149
|
+
- spec/lib/frame_spec.rb
|
150
|
+
- spec/lib/game_spec.rb
|
151
|
+
- spec/spec_helper.rb
|
152
|
+
homepage: http://www.dablweb.com
|
153
|
+
licenses:
|
154
|
+
- MIT
|
155
|
+
metadata: {}
|
156
|
+
post_install_message:
|
157
|
+
rdoc_options: []
|
158
|
+
require_paths:
|
159
|
+
- lib
|
160
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - ! '>='
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
167
|
+
- - ! '>='
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: '0'
|
170
|
+
requirements: []
|
171
|
+
rubyforge_project:
|
172
|
+
rubygems_version: 2.0.5
|
173
|
+
signing_key:
|
174
|
+
specification_version: 4
|
175
|
+
summary: /Users/brett/dev/personal/bowling/README.md
|
176
|
+
test_files:
|
177
|
+
- spec/lib/ball_spec.rb
|
178
|
+
- spec/lib/frame_spec.rb
|
179
|
+
- spec/lib/game_spec.rb
|
180
|
+
- spec/spec_helper.rb
|