round_robin_tournament 0.1.0 → 0.1.1

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
  SHA256:
3
- metadata.gz: 602722f9a01df5d8ac2c4d6fa8891ba4af1c24fb7420411af5f7b7e9a1914858
4
- data.tar.gz: f6bcabe982701d5a4a2dece4b9b4368d1c5dba3d1e1e1b79ecc1fd83295ec13d
3
+ metadata.gz: c44c37f2ebf4487b93af39b2ffffea2fd40714f8afdcb563a0abe6d842b6ec26
4
+ data.tar.gz: 0065134b6fdcf7fab503de34f76217348f2086829cdd3eb0202c85bc7a4f4143
5
5
  SHA512:
6
- metadata.gz: 5fc2438012012087bb18d08236be7f04fb76bb06a644947833168d0c75fd7effe34ed1abfcab50756c8a631000dd5b3b3000332af6783dc7b5b97f1d9eb41b87
7
- data.tar.gz: c46981d03da742a33febcc0c1dfaa8ad174cf2bdde1782c28d3a21cac340e82709d9b791b74fbe04c2099c079be8f446e37c073c8752326aef3d5d441e3525da
6
+ metadata.gz: '018d0159564979c31b8ee4b5df4b7b9d98474f55c9bad9bc4e52e5a57002775134df27decc2650c55140133c90f4abb72f6b8fd02178a49aa4b55dd3de4ece73'
7
+ data.tar.gz: 27b8f68179e0d0d4c614a5420e6c5cc683fc214a309099ed9be57a44464aefb2214926628d8bf1a7fefd790b728e76ec7c3a23d9e33af335ed50fcac65a01fb5
data/README.md CHANGED
@@ -9,7 +9,7 @@ of students and want them to work in pairs, but with a different partner every d
9
9
 
10
10
  ## Upgrade
11
11
 
12
- If you upgrade from version `0.0.1` to `0.1.0`, the tournament rotation has been reversed, which brings **stability** on first day pairs for a growing number for participants.
12
+ If you upgrade from version `0.0.1` to `0.1.1`, the tournament rotation has been reversed, which brings **stability** on first day pairs for a growing number for participants.
13
13
 
14
14
  ## Installation
15
15
 
@@ -3,12 +3,16 @@ require 'round_robin_tournament/version'
3
3
  module RoundRobinTournament
4
4
 
5
5
  def self.schedule(array)
6
- array.push nil if array.size.odd?
6
+ array.push(nil) if array.size.odd?
7
7
  n = array.size
8
- pivot = array.shift
8
+ 1.step(n / 2, 1).each do |i|
9
+ array.insert(n - i, array.delete_at(i))
10
+ end
11
+ pivot = array.pop
9
12
  games = (n - 1).times.map do
13
+ day = [[array.first, pivot]] + (1...(n / 2)).map { |j| [array[j], array[n - 1 - j]] }
10
14
  array.rotate!
11
- [[array.first, pivot]] + (1...(n / 2)).map { |j| [array[j], array[n - 1 - j]] }
15
+ day
12
16
  end
13
17
  array.push pivot unless pivot.nil?
14
18
  games
@@ -1,3 +1,3 @@
1
1
  module RoundRobinTournament
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -21,18 +21,20 @@ describe RoundRobinTournament do
21
21
  expect { check_schedule!(teams) }.not_to raise_error
22
22
  end
23
23
 
24
- it 'is stable growing the number of participants by 1' do
25
- day_four = RoundRobinTournament.schedule(%w[a b c d]).first
26
- day_five = RoundRobinTournament.schedule(%w[a b c d e]).first
27
- expect(day_five[0..1]).to eq(day_four)
28
- expect(day_five.last).to eq(['e', nil])
29
- end
30
-
31
- it 'is stable growing the number of participants by 2' do
32
- day_four = RoundRobinTournament.schedule(%w[a b c d]).first
33
- day_six = RoundRobinTournament.schedule(%w[a b c d e f]).first
34
- expect(day_six[0..1]).to eq(day_four)
35
- expect(day_six.last).to eq(['e', 'f'])
24
+ (2..20).to_a.each do |n|
25
+ it "is stable growing the number of participants from #{n} to #{n + 1}" do
26
+ day_one = RoundRobinTournament.schedule(("a".."z").to_a.take(n)).first
27
+ participants_day_two = ("a".."z").to_a.take(n + 1)
28
+ participants_day_two_last = participants_day_two.last
29
+ day_two = RoundRobinTournament.schedule(participants_day_two).first
30
+
31
+ if n.even?
32
+ day_two = day_two.reject { |pair| pair.compact.size != 2 }
33
+ else
34
+ day_one = day_one.map { |pair| pair.map { |participant| participant.nil? ? participants_day_two_last : participant } }
35
+ end
36
+ expect(day_two).to eq(day_one)
37
+ end
36
38
  end
37
39
  end
38
40
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: round_robin_tournament
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastien Saunier