tennis 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Makefile +4 -1
- data/lib/tennis/version.rb +1 -1
- data/lib/tennis.rb +26 -7
- data/spec/tennis_spec.rb +7 -7
- 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: cd583e116bb97ed17c1e2fcd2f3226740f9e5ae2
|
4
|
+
data.tar.gz: 0de701c7fc9ef68b462653297f2c6c4353440b2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65df88626e25f108eb082aff044b5bbf4a3f680cc0d6500cc05a70f250c47a547febf8411cdbf07483244515c4063b8cc394d7fa8786bc6652f36e153ded4a86
|
7
|
+
data.tar.gz: 2364bb158a00d34af3932050351a452a1ce17934ace29c55f3d9dcdc23f4537c49378e9f136755bcabb27d6e387daef55fc73d72e51fb258132eabac25c86670
|
data/Makefile
CHANGED
data/lib/tennis/version.rb
CHANGED
data/lib/tennis.rb
CHANGED
@@ -4,10 +4,10 @@ class Tennis
|
|
4
4
|
# player 1 is the home player(0) , player 2 is the away player(1)
|
5
5
|
# winner is either 0 or 1
|
6
6
|
# points is an array: [points for 0 , points for 1]
|
7
|
-
#
|
8
|
-
#
|
7
|
+
# sets_lost is an array: [sets lost by 0, sets lost by 1]
|
8
|
+
# games_lost is an array: [games won by 0, games won by 1]
|
9
9
|
|
10
|
-
attr_reader :winner, :points, :
|
10
|
+
attr_reader :winner, :points, :sets_lost, :games_lost
|
11
11
|
|
12
12
|
def initialize(scores)
|
13
13
|
# dfh -> default win for home player(0)
|
@@ -17,8 +17,8 @@ class Tennis
|
|
17
17
|
@winner = match_winner if @winner == :default
|
18
18
|
@points = match_points
|
19
19
|
unless @scores.is_a? String
|
20
|
-
@
|
21
|
-
@
|
20
|
+
@sets_lost = count_sets_lost
|
21
|
+
@games_lost = count_games_lost
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -79,7 +79,26 @@ class Tennis
|
|
79
79
|
@winner == 0 || @winner == 1 ? complete_match_points : incomplete_match_points
|
80
80
|
end
|
81
81
|
|
82
|
-
# returns the number of sets
|
82
|
+
# returns the number of sets lost by each player
|
83
|
+
def count_sets_lost
|
84
|
+
sets = [0, 0]
|
85
|
+
(0...@scores.length).step(2).each do |i|
|
86
|
+
@scores[i] > @scores[i + 1] ? sets[1] += 1 : sets[0] += 1
|
87
|
+
end
|
88
|
+
sets
|
89
|
+
end
|
90
|
+
|
91
|
+
# returns the number of won by each player
|
92
|
+
def count_games_lost
|
93
|
+
games = [0, 0]
|
94
|
+
(0...@scores.length).step(2).each do |i|
|
95
|
+
games[0] += @scores[i + 1]
|
96
|
+
games[1] += @scores[i]
|
97
|
+
end
|
98
|
+
games
|
99
|
+
end
|
100
|
+
|
101
|
+
# returns the number of sets won by each player
|
83
102
|
def sets_won
|
84
103
|
sets = [0, 0]
|
85
104
|
(0...@scores.length).step(2).each do |i|
|
@@ -88,7 +107,7 @@ class Tennis
|
|
88
107
|
sets
|
89
108
|
end
|
90
109
|
|
91
|
-
# returns the number of
|
110
|
+
# returns the number of won by each player
|
92
111
|
def games_won
|
93
112
|
games = [0, 0]
|
94
113
|
(0...@scores.length).step(2).each do |i|
|
data/spec/tennis_spec.rb
CHANGED
@@ -127,22 +127,22 @@ describe Tennis, "#flipped" do
|
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
130
|
-
describe Tennis, "#
|
131
|
-
it "returns the sets
|
132
|
-
scores = [["6-4, 4-6, 6-4", [2
|
130
|
+
describe Tennis, "#sets_lost" do
|
131
|
+
it "returns the sets lost by each player" do
|
132
|
+
scores = [["6-4, 4-6, 6-4", [1,2]],["6-2,6-1", [0, 2]], ["7-6,4-6,6-4", [1, 2]], ["6-4", [0,1]]]
|
133
133
|
scores.each do |s|
|
134
134
|
ts = Tennis.new(s[0])
|
135
|
-
expect(ts.
|
135
|
+
expect(ts.sets_lost).to eq s[1]
|
136
136
|
end
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
140
|
-
describe Tennis, "#
|
140
|
+
describe Tennis, "#games_lost" do
|
141
141
|
it "returns the games won by each player" do
|
142
|
-
scores = [["6-4, 4-6, 6-4", [16
|
142
|
+
scores = [["6-4, 4-6, 6-4", [14,16]],["6-2,6-1", [3, 12]], ["7-6,4-6,6-4", [16, 17]], ["6-4", [4,6]]]
|
143
143
|
scores.each do |s|
|
144
144
|
ts = Tennis.new(s[0])
|
145
|
-
expect(ts.
|
145
|
+
expect(ts.games_lost).to eq s[1]
|
146
146
|
end
|
147
147
|
end
|
148
148
|
end
|