brackets 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/brackets.gemspec +1 -1
- data/lib/brackets/match.rb +1 -1
- data/lib/brackets/tournament.rb +3 -1
- data/spec/brackets/tournament_spec.rb +25 -0
- 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: 3cdb35f83c0d29c3790eafbef261816e62bf6176
|
4
|
+
data.tar.gz: 223e2209efcd6aa22decfd876843cdb87c49c9f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 303155079213b985b127484c1b88b558d7eaa163e4e600d2a85b6f5aae9cba82a287b1ccd1a662eb76996af51a988cff3f3a2844d4109c97e940fb79520ff8a5
|
7
|
+
data.tar.gz: 3f21e9e2306b0cd10b90f8ba1a3c20fbb5cabbe4ce462c11b539b6e58a0bfaa016df5bd0d3e2eece39e1e5480b238121503ff89dd12c9ac7f31f84c1f0fb2472
|
data/Gemfile.lock
CHANGED
data/brackets.gemspec
CHANGED
@@ -2,7 +2,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'brackets'
|
5
|
-
s.version = '0.0.
|
5
|
+
s.version = '0.0.2'
|
6
6
|
s.date = '2015-11-08'
|
7
7
|
s.summary = "A gem to generate tournament brackets"
|
8
8
|
s.description = "A gem to generate tournament brackets"
|
data/lib/brackets/match.rb
CHANGED
data/lib/brackets/tournament.rb
CHANGED
@@ -5,6 +5,8 @@ module Brackets
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def generate(competitors)
|
8
|
+
return [] if competitors.to_a.empty?
|
9
|
+
|
8
10
|
generate_rounds(generate_first_round(competitors))
|
9
11
|
end
|
10
12
|
|
@@ -27,7 +29,7 @@ module Brackets
|
|
27
29
|
end
|
28
30
|
|
29
31
|
def generate_rounds(round, deph = 2)
|
30
|
-
if round.size == 1
|
32
|
+
if round.size == 1 || round.size == 3
|
31
33
|
round
|
32
34
|
else
|
33
35
|
matches = round.select{|m| m.deph == deph - 1 }.each_slice(2).map do |slice|
|
@@ -15,10 +15,27 @@ module Brackets
|
|
15
15
|
|
16
16
|
let(:competitors) { [anakin, obiwan, maul, mace] }
|
17
17
|
|
18
|
+
|
18
19
|
it "numbers the matches sequentially" do
|
19
20
|
expect(subject.map(&:number)).to eq([1, 2, 3])
|
20
21
|
end
|
21
22
|
|
23
|
+
describe "when receiving an empty array" do
|
24
|
+
let(:competitors) { [] }
|
25
|
+
|
26
|
+
it "returns an empty array" do
|
27
|
+
expect(subject).to eq([])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "when receiving nil" do
|
32
|
+
let(:competitors) { nil }
|
33
|
+
|
34
|
+
it "returns an empty array" do
|
35
|
+
expect(subject).to eq([])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
22
39
|
context "with one participant" do
|
23
40
|
let(:competitors) { [anakin] }
|
24
41
|
|
@@ -41,6 +58,14 @@ module Brackets
|
|
41
58
|
end
|
42
59
|
end
|
43
60
|
|
61
|
+
context "with three competitors" do
|
62
|
+
let(:competitors) { [anakin, obiwan, yoda] }
|
63
|
+
|
64
|
+
it "generates one match with no winner", focus: true do
|
65
|
+
expect(subject.length).to eq(3)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
44
69
|
context "when number of competitors is a power of two" do
|
45
70
|
let(:competitors) { [yoda, mace, anakin, obiwan] }
|
46
71
|
|