tennis 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/tennis/version.rb +1 -1
- data/lib/tennis.rb +3 -3
- data/spec/tennis_spec.rb +97 -96
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 712dd151385311975555e7760f34efc56cc15bf8
|
4
|
+
data.tar.gz: 300917e8388e055dc66ccf962bade908d432fc63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc7af490abc900a2b70b236b8f55e28464d4afd1eb12491d325cb371210656f8c6333553df5820962fd191489c81fc47f3319bf025d8b3700e6be7ea4fadd4a0
|
7
|
+
data.tar.gz: bda423a9b124c72699ef9cb59d12e20a9dcc1fd9d7748a9a75cd350cb191c50e59cd3a610d11816a85e1ad737b59c251012f6eb2317e9a60c4b161a67eca4658
|
data/.gitignore
CHANGED
data/lib/tennis/version.rb
CHANGED
data/lib/tennis.rb
CHANGED
@@ -46,7 +46,7 @@ class Tennis
|
|
46
46
|
# :error (bad input for sure)
|
47
47
|
# 1 (player-1 won)
|
48
48
|
# 2 (player-2 won)
|
49
|
-
def
|
49
|
+
def winner
|
50
50
|
return @result if @result != :default
|
51
51
|
return @result = (@scores.length == 4) ? two_sets : three_sets
|
52
52
|
end
|
@@ -55,7 +55,7 @@ class Tennis
|
|
55
55
|
# returns (points_player_1 , points_player_2)
|
56
56
|
# returns (0,0) for bad input
|
57
57
|
def points
|
58
|
-
@result =
|
58
|
+
@result = winner
|
59
59
|
(return [0, 0]) if @result == :error
|
60
60
|
return (complete_match_points if @result == 1 || @result == 2) || incomplete_match_points
|
61
61
|
end
|
@@ -101,7 +101,7 @@ class Tennis
|
|
101
101
|
# helper method: called by POINTS for complete matches
|
102
102
|
def complete_match_points
|
103
103
|
points = [0, 0]
|
104
|
-
@result =
|
104
|
+
@result = winner
|
105
105
|
points[@result - 1] = (@scores.length == 6) ? 12 : 14
|
106
106
|
runner_up = (@result == 1) ? 2 : 1
|
107
107
|
runner_up_points = player_points(runner_up)
|
data/spec/tennis_spec.rb
CHANGED
@@ -1,108 +1,109 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Tennis, "#packge" do
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
it 'has a version number' do
|
5
|
+
expect(Tennis::VERSION).not_to be nil
|
6
|
+
end
|
7
7
|
end
|
8
8
|
|
9
9
|
describe Tennis, "#scores" do
|
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
|
-
|
10
|
+
it "finds the winner properly in two sets" do
|
11
|
+
score = Tennis.new("6-4, 6-4")
|
12
|
+
expect(score.winner).to eq 1
|
13
|
+
end
|
14
|
+
|
15
|
+
it "finds the winner properly in three sets" do
|
16
|
+
score = Tennis.new("4-6, 6-2, 3-6")
|
17
|
+
expect(score.winner).to eq 2
|
18
|
+
end
|
19
|
+
|
20
|
+
it "finds the winner properly in two sets with tie break" do
|
21
|
+
score = Tennis.new("6-4, 7-6")
|
22
|
+
expect(score.winner).to eq 1
|
23
|
+
end
|
24
|
+
|
25
|
+
it "finds the winner properly in three sets with tie break" do
|
26
|
+
score = Tennis.new("6-4, 6-7, 7-6")
|
27
|
+
expect(score.winner).to eq 1
|
28
|
+
end
|
29
|
+
|
30
|
+
it "reports incomplete match score (set 1-1)" do
|
31
|
+
score = Tennis.new("6-4,4-6")
|
32
|
+
expect(score.winner).to eq :incomplete_match
|
33
|
+
end
|
34
|
+
|
35
|
+
it "reports incomplete match score (set incomplete)" do
|
36
|
+
score = Tennis.new("6-4,4-5")
|
37
|
+
expect(score.winner).to eq :incomplete_match
|
38
|
+
end
|
39
|
+
|
40
|
+
it "checks invalid score: difference in games won < 2" do
|
41
|
+
score = Tennis.new("6-5,4-6,7-6")
|
42
|
+
expect(score.winner).to eq :incomplete_match
|
43
|
+
end
|
44
|
+
|
45
|
+
it "checks invalid score: only 1 set input" do
|
46
|
+
score = Tennis.new("6-4")
|
47
|
+
expect(score.winner).to eq :error
|
48
|
+
end
|
49
|
+
|
50
|
+
it "checks invalid score: winner decided in first 2 sets but 3rd set input" do
|
51
|
+
score = Tennis.new("6-4,6-4,4-6")
|
52
|
+
expect(score.winner).to eq :error
|
53
|
+
end
|
54
|
+
|
55
|
+
it "checks invalid score: bad input for tie break" do
|
56
|
+
score = Tennis.new("7-0,4-6,6-2")
|
57
|
+
expect(score.winner).to eq :error
|
58
|
+
end
|
59
|
+
|
60
|
+
it "checks invalid score: no score > 7" do
|
61
|
+
score = Tennis.new("8-4,2-6,6-1")
|
62
|
+
expect(score.winner).to eq :error
|
63
|
+
end
|
64
|
+
|
65
|
+
it "checks invalid score: blank score '' " do
|
66
|
+
score = Tennis.new("")
|
67
|
+
expect(score.winner).to eq :error
|
68
|
+
end
|
69
69
|
|
70
70
|
end
|
71
71
|
|
72
72
|
describe Tennis, "#points" do
|
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
|
-
|
73
|
+
it "returns 12 points in a three set win in a complete match" do
|
74
|
+
score = Tennis.new("6-4, 4-6, 6-4")
|
75
|
+
expect(score.points).to eq [12,8]
|
76
|
+
end
|
77
|
+
|
78
|
+
it "returns 14 points in two set win in a complete match" do
|
79
|
+
score = Tennis.new("4-6, 4-6")
|
80
|
+
expect(score.points).to eq [8,14]
|
81
|
+
end
|
82
|
+
|
83
|
+
it "returns a max of 8 points for the runners up in a complete match" do
|
84
|
+
score = Tennis.new("4-6, 6-2, 3-6")
|
85
|
+
expect(score.points).to eq [8,12]
|
86
|
+
end
|
87
|
+
|
88
|
+
it "return a max of 10 points for each player in an incomplete match" do
|
89
|
+
score = Tennis.new("7-6,6-7")
|
90
|
+
expect(score.points).to eq [10,10]
|
91
|
+
end
|
92
|
+
|
93
|
+
it "return a max of 10 points for each player in an incomplete match" do
|
94
|
+
score = Tennis.new("7-6,4-6,4-1")
|
95
|
+
expect(score.points).to eq [10,10]
|
96
|
+
end
|
97
|
+
|
98
|
+
it "return [0,0] for bad input" do
|
99
|
+
score = Tennis.new("8-1")
|
100
|
+
expect(score.points).to eq [0,0]
|
101
|
+
end
|
102
|
+
|
103
|
+
it "checks invalid score: blank score '' " do
|
104
|
+
pending
|
105
|
+
score = Tennis.new("")
|
106
|
+
expect(score.points).to eq :error
|
107
|
+
end
|
107
108
|
|
108
109
|
end
|