bowling_score 0.0.1 → 0.0.2
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 +4 -4
- data/README.md +21 -0
- data/bowling_score.gemspec +2 -2
- data/lib/bowling_score/score_calculator.rb +3 -1
- data/lib/bowling_score/version.rb +1 -1
- data/spec/bowling_score/score_calculator_spec.rb +24 -0
- metadata +3 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6e8e32b7b3d9cac7e1b6a52b725fbf39524cce8
|
4
|
+
data.tar.gz: 34777190ba17aedbefeb51ff5dc2d004343e5d52
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 838700075ec3fff31cf3b8b3839442d9f23463cf4602d6a8830eca6805f69be30a4ebf893d252be51f0df6f4c3779ea29befc4bc2bfd2cac669613a17eea5d47
|
7
|
+
data.tar.gz: 01eff0f00f09359dac9dec803260e5d1bce2cf682017a22c6617d43c1378b2217d1899c813722ef5e9e7a29c5fd16b136b1e95840b30662729f31b918f7ae37a
|
data/README.md
CHANGED
@@ -4,3 +4,24 @@ This gem supports score calculation for a bowling game given a string of comma s
|
|
4
4
|
of integer. The scoring rule is based on http://bowling.about.com/od/rulesofthegame/a/bowlingscoring.htm and
|
5
5
|
https://en.wikipedia.org/wiki/Ten-pin_bowling#Scoring. The calculation consider the rules for strike and spare
|
6
6
|
rewarding.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
[sudo] gem install bowling_score
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
require 'bowling_score'
|
16
|
+
|
17
|
+
scores = '1,2,3,4,5,5,10,2,4'
|
18
|
+
calculator = BowlingScore::ScoreCalculator.new(scores)
|
19
|
+
calculator.calculate
|
20
|
+
# result: 52
|
21
|
+
```
|
22
|
+
|
23
|
+
## TODO
|
24
|
+
|
25
|
+
* ScoresToFramesConvertor - to convert array of integers into frames based on rules, and validate the format and validity of the array of scores.
|
26
|
+
* ScoreBoard Class - as a data structure to hold frames and responsibility to provide score status per frame and adding score to board.
|
27
|
+
* ScoreCalculator - to take ScoreBoard Class and iterate by Frames.
|
data/bowling_score.gemspec
CHANGED
@@ -15,8 +15,8 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.license = 'MIT'
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0")
|
18
|
-
spec.executables = spec.files.grep(
|
19
|
-
spec.test_files = spec.files.grep(
|
18
|
+
spec.executables = spec.files.grep('^bin/') { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep('^(test|spec|features)/')
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
|
22
22
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
@@ -8,12 +8,14 @@ module BowlingScore
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def calculate
|
11
|
+
@current_frame = 0
|
11
12
|
_calculate_from_frame(0)
|
12
13
|
end
|
13
14
|
|
14
15
|
private
|
15
16
|
|
16
17
|
def _calculate_from_frame(index)
|
18
|
+
@current_frame += 1
|
17
19
|
return 0 if _out_of_range?(index)
|
18
20
|
return _rewarded_frame(index) unless _without_bonus?(index)
|
19
21
|
_unrewarded_frame(index)
|
@@ -31,7 +33,7 @@ module BowlingScore
|
|
31
33
|
|
32
34
|
def _out_of_range?(index)
|
33
35
|
return true unless @scores[index]
|
34
|
-
|
36
|
+
@current_frame > BowlingScore::NUMBER_OF_FRAME
|
35
37
|
end
|
36
38
|
|
37
39
|
def _rewarded_frame(index)
|
@@ -107,6 +107,30 @@ describe BowlingScore::ScoreCalculator do
|
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
110
|
+
context 'with 1,2,3,4,5,5' do
|
111
|
+
it 'returns 20' do
|
112
|
+
test_array = [1, 2, 3, 4, 5, 5]
|
113
|
+
subject.instance_variable_set(:@scores, test_array)
|
114
|
+
expect(subject.calculate).to eq(20)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context 'with 9,1,10,8,0,2' do
|
119
|
+
it 'returns 48' do
|
120
|
+
test_array = [9, 1, 10, 8, 0, 2]
|
121
|
+
subject.instance_variable_set(:@scores, test_array)
|
122
|
+
expect(subject.calculate).to eq(48)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
context 'with 10,0,0,9,1,0,0,8,2,0,0,7,3,0,0,6,4,0,0' do
|
127
|
+
it 'returns 50' do
|
128
|
+
test_array = [10, 0, 0, 9, 1, 0, 0, 8, 2, 0, 0, 7, 3, 0, 0, 6, 4, 0, 0]
|
129
|
+
subject.instance_variable_set(:@scores, test_array)
|
130
|
+
expect(subject.calculate).to eq(50)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
110
134
|
context 'with a single strike' do
|
111
135
|
context 'as the last score' do
|
112
136
|
it 'returns sum of all scores' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bowling_score
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ian Choi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -84,8 +84,4 @@ rubygems_version: 2.4.5
|
|
84
84
|
signing_key:
|
85
85
|
specification_version: 4
|
86
86
|
summary: Bowling score calculator
|
87
|
-
test_files:
|
88
|
-
- spec/bowling_score/score_calculator_spec.rb
|
89
|
-
- spec/bowling_score_spec.rb
|
90
|
-
- spec/spec_helper.rb
|
91
|
-
has_rdoc:
|
87
|
+
test_files: []
|