test("match partitioning GroupStage", function (t) { var gs = new GroupStage(16, 4); t.deepEqual(gs.findMatch({s:1, r:1, m:1}), { id: { s: 1, r: 1, m: 1 }, p: [ 1, 16 ] }, "find returns sensible GroupStage result" ); t.ok(gs.findMatch({s:4, r:1, m:1}), "4 groups in group stage"); t.equal(gs.findMatch({s:5, r:1, m:1}), undefined, "so no 5th would exist"); t.equal(gs.sections().length, 4, "four groups"); t.equal(gs.sections()[1].length, 6, "six matches in group 1"); t.deepEqual(gs.findMatches({s:1}), gs.sections()[0], "Group 1 === Group 1"); t.deepEqual(gs.findMatches({s:2}), gs.sections()[1], "Group 2 === Group 2"); t.deepEqual(gs.findMatches({s:3}), gs.sections()[2], "Group 3 === Group 3"); t.deepEqual(gs.findMatches({s:4}), gs.sections()[3], "Group 4 === Group 4"); t.deepEqual(gs.findMatches({s:3, r:2}), gs.sections(2)[3-1], "G3R2 === G3R2"); t.deepEqual(gs.findMatches({s:2, r:3}), gs.rounds(2)[3-1], "G2R3 == G2R3"); t.deepEqual( gs.findMatchesRanged({s:2, r: 3}, {s:2, r:3}), gs.findMatches({s:2, r:3}), "sandwiched G2R3 === G2R3" ); t.deepEqual( gs.findMatchesRanged({s:1, r:1}, {s:4, r:1}), gs.rounds()[0], "G1->G4 R1 === rounds[0]" ); t.deepEqual( gs.findMatchesRanged({s:1, r:2}, {s:4, r:3}), gs.rounds()[1].concat(gs.rounds()[2]).sort(comp), // this restacks "G1->G4 R2->R3 === (rounds[1] ++ rounds[2]).resort" ); t.deepEqual( gs.findMatchesRanged({s:3, r:1}, {s:4, r:1}), gs.sections(1)[2].concat(gs.sections(1)[3]), "G3->G4 R1 === sections(1)[2] ++ sections(1)[3]" ); t.deepEqual( gs.findMatchesRanged({s:2, r:1}, {s:2}), $.flatten(gs.sections()[1]), "G2 R1->R4 === flattenend sections()[1]" ); t.end(); });
test("current and next round GroupStage", function (t) { var rep = GroupStage.idString; var scorer = function (m) { t.ok(gs.score(m.id, m.p[0] < m.p[1] ? [1,0] : [0,1]), "score " + rep(m.id)); }; var gs = new GroupStage(16, 4); t.deepEqual(gs.currentRound(1), gs.findMatches({s:1, r:1}), "current === G1R1"); t.deepEqual(gs.currentRound(), gs.findMatches({r:1}), "currentAll R1"); t.deepEqual(gs.nextRound(1), gs.findMatches({s:1, r:2}), "next === G1R2"); t.deepEqual(gs.nextRound(), gs.findMatches({r:2}), "nextAll R2"); // this will update current round for this group but not across groups gs.findMatches({s:1, r:1}).forEach(scorer); t.deepEqual(gs.currentRound(1), gs.findMatches({s:1, r:2}), "current now G1R2"); t.deepEqual(gs.currentRound(), gs.findMatches({r:1}), "currentAll still R1"); t.deepEqual(gs.nextRound(1), gs.findMatches({s:1, r:3}), "next now G1R3"); t.deepEqual(gs.nextRound(), gs.findMatches({r:2}), "nextAll still R2"); // this will update R1 everywhere though gs.findMatchesRanged({s:2, r:1}).forEach(scorer); t.deepEqual(gs.currentRound(1), gs.findMatches({s:1, r:2}), "current still G1R2"); t.deepEqual(gs.currentRound(), gs.findMatches({r:2}), "currentAll R2"); t.deepEqual(gs.nextRound(1), gs.findMatches({s:1, r:3}), "next still G1R3"); t.deepEqual(gs.nextRound(), gs.findMatches({r:3}), "nextAll now R3"); // score remaining matches gs.findMatchesRanged({r:2}).forEach(scorer); // should be no current or nexts now t.equal(gs.currentRound(1), undefined, "no current round for group 1 after end"); t.equal(gs.currentRound(), undefined, "no current round after end"); t.equal(gs.nextRound(1), undefined, "no next round for group 1 after end"); t.equal(gs.nextRound(), undefined, "no next round after end"); t.end(); });