tennis 0.1.3 → 0.1.4

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: 712dd151385311975555e7760f34efc56cc15bf8
4
- data.tar.gz: 300917e8388e055dc66ccf962bade908d432fc63
3
+ metadata.gz: 92920cd754c3ac7a92528a35692060e8ed472dbe
4
+ data.tar.gz: 8e91f9f5b0a4c2f4902b4eba2b1bc53204cb50bb
5
5
  SHA512:
6
- metadata.gz: bc7af490abc900a2b70b236b8f55e28464d4afd1eb12491d325cb371210656f8c6333553df5820962fd191489c81fc47f3319bf025d8b3700e6be7ea4fadd4a0
7
- data.tar.gz: bda423a9b124c72699ef9cb59d12e20a9dcc1fd9d7748a9a75cd350cb191c50e59cd3a610d11816a85e1ad737b59c251012f6eb2317e9a60c4b161a67eca4658
6
+ metadata.gz: 0eaffb4274e0b704fe739ef00127b8084ae5b8f7dacdd31f3f38eae002b42b64c6a9036d0c1039ed47f7da715e36fe9157a70c4502f8137af33a785c21dc02a1
7
+ data.tar.gz: 0ecc8a77bf85c347177ade9930aa863882c4f11a14dadee09b013ad60663da176d841c5c0c529c3c6a7c3959d27d3a46cabb35cfb24304cbc3ba074f5ae4b283
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in tennis.gemspec
4
4
  gemspec
5
+
6
+ gem "codeclimate-test-reporter", group: :test, require: nil
data/Makefile CHANGED
@@ -5,5 +5,8 @@ all:
5
5
  build:
6
6
  gem build tennis.gemspec
7
7
 
8
+ irb:
9
+ irb -Ilib -rtennis
10
+
8
11
  # to push to rubygems
9
12
  # gem push tennis-0.1.1.gem
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Tennis
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/tennis.svg)](http://badge.fury.io/rb/tennis) [![Build Status](https://travis-ci.org/racketlogger/tennis.svg)](https://travis-ci.org/racketlogger/tennis)
3
+ [![Gem Version](https://badge.fury.io/rb/tennis.svg)](http://badge.fury.io/rb/tennis) [![Build Status](https://travis-ci.org/racketlogger/tennis.svg)](https://travis-ci.org/racketlogger/tennis) [![Code Climate](https://codeclimate.com/github/racketlogger/tennis/badges/gpa.svg)](https://codeclimate.com/github/racketlogger/tennis) [![Test Coverage](https://codeclimate.com/github/racketlogger/tennis/badges/coverage.svg)](https://codeclimate.com/github/racketlogger/tennis)
4
4
 
5
5
  Ruby gem with utilities to manage, print and validate tennis scores
6
6
 
@@ -1,3 +1,3 @@
1
1
  class Tennis
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
data/lib/tennis.rb CHANGED
@@ -6,7 +6,7 @@ class Tennis
6
6
  @result = (1 if scores == 'default-1') || (2 if scores == 'default-2') || :default
7
7
  if @result == :default
8
8
  # check blank input ''
9
- @result = :error if @scores.any? { |score| score.nil? || score == 0 }
9
+ @result = :error if @scores.any? { |score| score.nil? }
10
10
  # to check if score for only 1 set has been input
11
11
  validation_1 = @scores.length == 2
12
12
  # to check if any input > 7
@@ -24,21 +24,13 @@ class Tennis
24
24
  # to_s
25
25
  # return the score in string format
26
26
  def to_s
27
- score = []
28
- (0...@scores.length).step(2).each do |i|
29
- score << [@scores[i], @scores[i+1]].join('-')
30
- end
31
- score.join(', ')
27
+ (0...@scores.length).step(2).map{ |i| [@scores[i], @scores[i+1]].join('-') }.join(', ')
32
28
  end
33
29
 
34
30
  # flip score ( P1-P2 to P2-P1)
35
- # returns the flipped score in string
31
+ # returns the flipped score as a string
36
32
  def flipped
37
- flipped_score = []
38
- (0...@scores.length).step(2).each do |i|
39
- flipped_score << [@scores[i+1], @scores[i]].join('-')
40
- end
41
- flipped_score.join(', ')
33
+ (0...@scores.length).step(2).map{ |i| [@scores[i+1], @scores[i]].join('-') }.join(', ')
42
34
  end
43
35
 
44
36
  # returns who won the match
@@ -48,7 +40,7 @@ class Tennis
48
40
  # 2 (player-2 won)
49
41
  def winner
50
42
  return @result if @result != :default
51
- return @result = (@scores.length == 4) ? two_sets : three_sets
43
+ @result = (@scores.length == 4) ? two_sets : three_sets
52
44
  end
53
45
 
54
46
  # returns an array of points
@@ -57,7 +49,7 @@ class Tennis
57
49
  def points
58
50
  @result = winner
59
51
  (return [0, 0]) if @result == :error
60
- return (complete_match_points if @result == 1 || @result == 2) || incomplete_match_points
52
+ (complete_match_points if @result == 1 || @result == 2) || incomplete_match_points
61
53
  end
62
54
 
63
55
  private
@@ -76,7 +68,7 @@ class Tennis
76
68
  end
77
69
  end
78
70
  # incomplete match e.g: 6-4,5-3
79
- return (set_results[0] if set_results[0] == set_results[1]) || :incomplete_match
71
+ (set_results[0] if set_results[0] == set_results[1]) || :incomplete_match
80
72
  end
81
73
 
82
74
  # helper method: called by RESULT method for valid matches with 3 sets
@@ -95,7 +87,7 @@ class Tennis
95
87
  # checks if the result has been decided in the first 2 sets
96
88
  # but the 3rd set is also present in the input
97
89
  return :error if set_results[0] == set_results[1]
98
- return set_results.count(1) == 2 ? 1 : 2
90
+ set_results.count(1) == 2 ? 1 : 2
99
91
  end
100
92
 
101
93
  # helper method: called by POINTS for complete matches
@@ -106,7 +98,7 @@ class Tennis
106
98
  runner_up = (@result == 1) ? 2 : 1
107
99
  runner_up_points = player_points(runner_up)
108
100
  points[runner_up - 1] = runner_up_points < 8 ? runner_up_points : 8
109
- return points
101
+ points
110
102
  end
111
103
 
112
104
  # helper method: called by POINTS for incomplete matches
@@ -116,7 +108,7 @@ class Tennis
116
108
  player_2_points = player_points(2)
117
109
  points[0] = player_1_points < 10 ? player_1_points : 10
118
110
  points[1] = player_2_points < 10 ? player_2_points : 10
119
- return points
111
+ points
120
112
  end
121
113
 
122
114
  # helper method: returns the POINTS of a player given the player number
@@ -124,6 +116,6 @@ class Tennis
124
116
  player_scores = []
125
117
  @scores.each_with_index { |score, index| (player_scores << score; player +=2) if index == (player - 1) }
126
118
  player_scores = player_scores.sort! { |x, y| y <=> x }
127
- return player_scores[0] + player_scores[1]
119
+ player_scores[0] + player_scores[1]
128
120
  end
129
121
  end
data/spec/spec_helper.rb CHANGED
@@ -17,6 +17,10 @@
17
17
  #
18
18
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
19
 
20
+ require "codeclimate-test-reporter"
21
+ CodeClimate::TestReporter.start
22
+
23
+
20
24
  require 'bundler/setup'
21
25
  Bundler.setup
22
26
  require 'tennis'
data/spec/tennis_spec.rb CHANGED
@@ -101,9 +101,28 @@ describe Tennis, "#points" do
101
101
  end
102
102
 
103
103
  it "checks invalid score: blank score '' " do
104
- pending
105
104
  score = Tennis.new("")
106
- expect(score.points).to eq :error
105
+ expect(score.points).to eq [0,0]
106
+ end
107
+ end
108
+
109
+ describe Tennis, "#as_string" do
110
+ it "normalizes scores to a string properly formatted" do
111
+ scores = [["6-4,4-6, 6-4", "6-4, 4-6, 6-4"], [" 4-6, 4-6 ", "4-6, 4-6"],
112
+ [" 4 -6, 4- 6 ", "4-6, 4-6"], [" 0 - 6, 6 - 0, 3 - 6 ", "0-6, 6-0, 3-6"]]
113
+ scores.each do |s|
114
+ ts = Tennis.new(s[0])
115
+ expect(ts.to_s).to eq s[1]
116
+ end
107
117
  end
118
+ end
108
119
 
120
+ describe Tennis, "#flipped" do
121
+ it "returns a normalized scores, but flipped" do
122
+ scores = [["6-4, 4-6, 6-4", "4-6, 6-4, 4-6"], ["6-4, 7-6", "4-6, 6-7"]]
123
+ scores.each do |s|
124
+ ts = Tennis.new(s[0])
125
+ expect(ts.flipped).to eq s[1]
126
+ end
127
+ end
109
128
  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.3
4
+ version: 0.1.4
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-07 00:00:00.000000000 Z
12
+ date: 2015-02-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler