Skip to content

Commit

Permalink
[#10][BUG] Areas were being set up to max for round robin when above …
Browse files Browse the repository at this point in the history
…a certain point
  • Loading branch information
duereg committed Aug 24, 2014
1 parent 2efccf6 commit 896ca2c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
8 changes: 6 additions & 2 deletions lib/tourney/selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ roundRobin = require('./round-robin');
pods = require('./pods');

module.exports = function(teams, areas) {
var tourney;
var areaLimit, tourney;
if (teams > 8 && areas <= Math.floor(teams / 4)) {
tourney = pods(teams);
return {
Expand All @@ -16,11 +16,15 @@ module.exports = function(teams, areas) {
};
} else {
tourney = roundRobin(teams);
areaLimit = Math.floor(teams / 2);
if (areas > areaLimit) {
areas = areaLimit;
}
return {
type: 'round robin',
games: tourney.games,
schedule: tourney.schedule,
areas: Math.floor(teams / 2)
areas: areas
};
}
};
4 changes: 3 additions & 1 deletion src/tourney/selector.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ module.exports = (teams, areas) ->
{type: 'pods', games: tourney.games, schedule: tourney.schedule, areas}
else
tourney = roundRobin(teams)
{type: 'round robin', games: tourney.games, schedule: tourney.schedule, areas: Math.floor(teams/2)}
areaLimit = Math.floor(teams / 2)
areas = areaLimit if areas > areaLimit
{type: 'round robin', games: tourney.games, schedule: tourney.schedule, areas}
4 changes: 2 additions & 2 deletions test/tourney/selector.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe 'tourney/selector', ->

describe 'and number of areas > teams / 4 but <= teams / 2', ->
beforeEach ->
results = selector(10, 5)
results = selector(10, 4)

it 'returns object with type "round robin"', ->
expect(results.type).to.eq 'round robin'
Expand All @@ -52,7 +52,7 @@ describe 'tourney/selector', ->
expect(results.schedule).to.be.ok

it 'returns object containing number of areas', ->
expect(results.areas).to.eq 5
expect(results.areas).to.eq 4

describe 'and number of areas > teams / 2', ->
beforeEach ->
Expand Down

0 comments on commit 896ca2c

Please sign in to comment.