tennis 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ce621f74414d103564e2bcc239a788d487c912ee
4
- data.tar.gz: 7fb8ec8e853cf6b05f775aed1ad42a95fe982d34
3
+ metadata.gz: 4cae2bc8246ef286862dcaf50932dc0c6163fabb
4
+ data.tar.gz: 1a45d035f3c072e9e81ba11c55c235205dc0d74b
5
5
  SHA512:
6
- metadata.gz: e693fb0265a8e3934b631971f86a57320003ac1fe82863ad840478cc3ab57cf5107f98e9d314483ee8b6a5fe59338ea45e2723b7d7a06f2752e94d35f1974ec4
7
- data.tar.gz: f69de2817fda3554545f98af969f1dbf6d2dbceafff7f43c3b6109d0adbb3fde5889bc4ad870ad8a893ca8b7966dd8698ff76e9fe8f1277d63ad77717796ee7d
6
+ metadata.gz: 9be5f61f35b63d700bab8a3a5460326b8c7b5aaa22599b10db2385166d0b67bfa4d7a968de09f577d26f64e4776011bb7a43ae8c04dd16878fb12bc230775c7f
7
+ data.tar.gz: 9d4f9ac6eef4d75d9982e6ce9af31f029ae1acc13e4a1051d0c40f000d48b374b59adca29cd40caf62c450b6ce181bdee9ec5cd388995bc5914cfc8ad5a81450
data/Makefile CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- VERSION=0.2.0
2
+ VERSION=0.3.0
3
3
 
4
4
  all:
5
5
  rake spec
@@ -1,3 +1,3 @@
1
1
  class Tennis
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
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.2.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-16 00:00:00.000000000 Z
12
+ date: 2015-03-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler