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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ab97c6b1bdde123d2b06a05e91db465b8d55dd35
4
- data.tar.gz: 4fae93c7c709ee1dcf9a38bae35585a93caff9a5
3
+ metadata.gz: cd583e116bb97ed17c1e2fcd2f3226740f9e5ae2
4
+ data.tar.gz: 0de701c7fc9ef68b462653297f2c6c4353440b2c
5
5
  SHA512:
6
- metadata.gz: 98b611d18f1758c632f6686d092d4f42d9845875cfa25c731b47339bc7c592141f45101ffcce3cd946251a01031eef7ed4a11335c18766c90a45b8424259db97
7
- data.tar.gz: fb611bd4896d45f25290f857f55afeea4f3b85c284c80df1363d0aba782822865027e28ad6c9172521381b2fd53557cf66b8fa4f66f0aa3f670b0fdb25da8832
6
+ metadata.gz: 65df88626e25f108eb082aff044b5bbf4a3f680cc0d6500cc05a70f250c47a547febf8411cdbf07483244515c4063b8cc394d7fa8786bc6652f36e153ded4a86
7
+ data.tar.gz: 2364bb158a00d34af3932050351a452a1ce17934ace29c55f3d9dcdc23f4537c49378e9f136755bcabb27d6e387daef55fc73d72e51fb258132eabac25c86670
data/Makefile CHANGED
@@ -1,4 +1,6 @@
1
1
 
2
+ VERSION=0.5.7
3
+
2
4
  all:
3
5
  rake spec
4
6
 
@@ -9,4 +11,5 @@ irb:
9
11
  irb -Ilib -rtennis
10
12
 
11
13
  # to push to rubygems
12
- # gem push tennis-0.1.1.gem
14
+ push:
15
+ gem push tennis-$(VERSION).gem
@@ -1,3 +1,3 @@
1
1
  class Tennis
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
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
- # set_count is an array: [sets won by 0, sets won by 1]
8
- # game_count is an array: [games won by 0, games won by 1]
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, :set_count, :game_count
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
- @set_count = sets_won
21
- @game_count = games_won
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 won by the given player (0 or 1)
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 won by the given player (0 or 1)
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, "#set_count" do
131
- it "returns the sets won by each player" do
132
- scores = [["6-4, 4-6, 6-4", [2,1]],["6-2,6-1", [2,0]], ["7-6,4-6,6-4", [2,1]], ["6-4", [1,0]]]
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.set_count).to eq s[1]
135
+ expect(ts.sets_lost).to eq s[1]
136
136
  end
137
137
  end
138
138
  end
139
139
 
140
- describe Tennis, "#game_count" do
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,14]],["6-2,6-1", [12,3]], ["7-6,4-6,6-4", [17,16]], ["6-4", [6,4]]]
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.game_count).to eq s[1]
145
+ expect(ts.games_lost).to eq s[1]
146
146
  end
147
147
  end
148
148
  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.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rohan Katyal