tennis 0.2.0 → 0.3.0
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/Makefile +1 -1
- data/lib/tennis/version.rb +1 -1
- data/lib/tennis.rb +9 -2
- data/spec/tennis_spec.rb +9 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4cae2bc8246ef286862dcaf50932dc0c6163fabb
|
|
4
|
+
data.tar.gz: 1a45d035f3c072e9e81ba11c55c235205dc0d74b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9be5f61f35b63d700bab8a3a5460326b8c7b5aaa22599b10db2385166d0b67bfa4d7a968de09f577d26f64e4776011bb7a43ae8c04dd16878fb12bc230775c7f
|
|
7
|
+
data.tar.gz: 9d4f9ac6eef4d75d9982e6ce9af31f029ae1acc13e4a1051d0c40f000d48b374b59adca29cd40caf62c450b6ce181bdee9ec5cd388995bc5914cfc8ad5a81450
|
data/Makefile
CHANGED
data/lib/tennis/version.rb
CHANGED
data/lib/tennis.rb
CHANGED
|
@@ -60,14 +60,21 @@ class Tennis
|
|
|
60
60
|
games = set.split(/-/).map(&:to_i)
|
|
61
61
|
raise "uneven games in set '#{set}'" unless games.length == 2
|
|
62
62
|
h, a = games
|
|
63
|
-
sw = set_winner(h, a)
|
|
63
|
+
sw = set_winner(h, a, set == sets.last)
|
|
64
64
|
raise "no valid winner in set '#{set}'" unless sw
|
|
65
65
|
[games, sw]
|
|
66
66
|
end
|
|
67
67
|
end
|
|
68
68
|
|
|
69
69
|
# determine the set winner for home and away, or else return nil
|
|
70
|
-
def set_winner(h, a)
|
|
70
|
+
def set_winner(h, a, last_set = false)
|
|
71
|
+
if last_set
|
|
72
|
+
return nil unless h > 5 or a > 5
|
|
73
|
+
# either tie-break or else difference of one+
|
|
74
|
+
return nil unless h + a == 13 or h > a + 1 or a > h + 1
|
|
75
|
+
return nil if h + a > 13 and (h-a).abs != 2
|
|
76
|
+
return h > a ? 0 : 1
|
|
77
|
+
end
|
|
71
78
|
# basic range check
|
|
72
79
|
return nil if h > 7 or a > 7 or h < 0 or a < 0
|
|
73
80
|
# game went to 7
|
data/spec/tennis_spec.rb
CHANGED
|
@@ -27,6 +27,15 @@ describe Tennis, "#scores" do
|
|
|
27
27
|
expect(score.winner).to eq 0
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
+
it "finds the winner properly in three sets with last set beyond tie-break" do
|
|
31
|
+
score = Tennis.new("6-4, 6-7, 18-16")
|
|
32
|
+
expect(score.winner).to eq 0
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "report error is the last set is off by more than 2" do
|
|
36
|
+
expect { Tennis.new("6-4, 6-7, 18-15") }.to raise_error
|
|
37
|
+
end
|
|
38
|
+
|
|
30
39
|
it "reports incomplete match score (set 1-1)" do
|
|
31
40
|
expect { Tennis.new("6-4,4-6") }.to raise_error
|
|
32
41
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tennis
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rohan Katyal
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2015-02
|
|
12
|
+
date: 2015-03-02 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: bundler
|