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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f6e209d9196cecd2a9e47953f230d89d63496aae
4
- data.tar.gz: d5bd1a1d77ecc2d243207bb6cd8315a53fd1d54a
3
+ metadata.gz: 712dd151385311975555e7760f34efc56cc15bf8
4
+ data.tar.gz: 300917e8388e055dc66ccf962bade908d432fc63
5
5
  SHA512:
6
- metadata.gz: 754ce0601818ee8e17e4222b8fb31884a1b6f00fb2d2c5500e967fe16ae0f6c583d4c5c71d731e524be9e2a49af97905c0f1b18cac6ef2249eca35b69263d0bb
7
- data.tar.gz: 1f3c1371982bdcccf50d37ba8f8967182e02e94c4995eac80f20ec3d1efd9f1d324dfc489beebb559ce608ea628f1cb35ac9ccc6100081f142a04f9c3c7dcef3
6
+ metadata.gz: bc7af490abc900a2b70b236b8f55e28464d4afd1eb12491d325cb371210656f8c6333553df5820962fd191489c81fc47f3319bf025d8b3700e6be7ea4fadd4a0
7
+ data.tar.gz: bda423a9b124c72699ef9cb59d12e20a9dcc1fd9d7748a9a75cd350cb191c50e59cd3a610d11816a85e1ad737b59c251012f6eb2317e9a60c4b161a67eca4658
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ *.gem
@@ -1,3 +1,3 @@
1
1
  class Tennis
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
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 result
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 = self.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 = self.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
- it 'has a version number' do
5
- expect(Tennis::VERSION).not_to be nil
6
- end
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
- it "finds the winner properly in two sets" do
11
- score = Tennis.new("6-4, 6-4")
12
- expect(score.result).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.result).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.result).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.result).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.result).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.result).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.result).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.result).to eq :error
48
- end
49
-
50
- it "checks invalid score: result decided in first 2 sets but 3rd set input" do
51
- score = Tennis.new("6-4,6-4,4-6")
52
- expect(score.result).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.result).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.result).to eq :error
63
- end
64
-
65
- it "checks invalid score: blank score '' " do
66
- score = Tennis.new("")
67
- expect(score.result).to eq :error
68
- end
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
- 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
- score = Tennis.new("")
105
- expect(score.points).to eq :error
106
- end
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
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.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rohan Katyal