Games-Tournament-Swiss
view release on metacpan or search on metacpan
t/lateentry.t view on Meta::CPAN
$tourney->enter($late[ 0 ]);
$tourney->assignPairingNumbers;
$tourney->initializePreferences;
$tourney->initializePreferences until $lineup[0]->preference->role eq
$Games::Tournament::Swiss::Config::roles[0];
sub runRound {
$tourney->assignPairingNumbers;
my %brackets = $tourney->formBrackets;
my $pairing = $tourney->pairing( \%brackets )->matchPlayers;
my $matches = $pairing->{matches};
$tourney->{matches}->{$round} = $matches;
my @games;
for my $bracket ( keys %$matches ) {
my $tables = $matches->{$bracket};
for my $match ( @$tables ) {
if ( $match->isBye ) {
$match->result( { Bye => 'Bye' } );
}
else {
$match->result( {
$Games::Tournament::Swiss::Config::roles[0] => 'Win',
$Games::Tournament::Swiss::Config::roles[1] => 'Loss',
} );
}
push @games, $match;
}
}
$tourney->collectCards( @games );
$tourney->round(++$round);
};
sub numbercheck {
my $entries = $tourney->entrants;
+{ map { $_->name => $_->pairingNumber } @$entries }
}
sub prefcheck {
my $entries = $tourney->entrants;
+{ map {$_->name => [ $_->preference->role, $_->preference->strength ] }
@$entries
};
}
sub floatcheck {
my $entries = $tourney->entrants;
+{ map {$_->name => $_->floats } @$entries };
}
sub scorecheck {
my $entries = $tourney->entrants;
+{ map {$_->name => $_->score } @$entries };
}
plan tests => 1 * blocks;
sub RunCheckEnter {
runRound;
my $numbers = next_block;
is_deeply( $numbers->input, $numbers->expected, $numbers->name );
my $prefs = next_block;
is_deeply( $prefs->input, $prefs->expected, $prefs->name );
my $floats = next_block;
is_deeply( $floats->input, $floats->expected, $floats->name );
my $score = next_block;
is_deeply( $score->input, $score->expected, $score->name );
$tourney->enter($late[ shift ]);
}
RunCheckEnter(1);
RunCheckEnter(2);
=head 3 TODO
After round 4, the pairings of the script are differing from those of pair. So I stopped before round 4 pairing numbers. It's not the purpose of the test to see if pairing is taking place correctly, but only to assimilate late entries.
Remember to un/comment RunCheckEnter.
=cut
RunCheckEnter(3);
# RunCheckEnter(4);
__DATA__
=== Round 1 pairingnumbers
--- input chomp numbercheck
0
--- expected yaml
A: 1
a: 2
B: 3
C: 4
D: 5
=== Post-Round 1 prefs
--- input chomp prefcheck
0
--- expected yaml
A: [ Black, Strong ]
a: [ White, Strong ]
B: [ White, Strong ]
C: [ Black, Strong ]
D: [ ~, Mild ]
=== Post-Round 1 floats
--- input chomp floatcheck
0
--- expected yaml
A: [ Not ]
a: [ Not ]
B: [ Not ]
C: [ Not ]
D: [ Down ]
=== Post-Round 1 score
--- input chomp scorecheck
0
--- expected yaml
A: 1
a: 0
B: 0
C: 1
D: 1
=== Round 2 pairingnumbers
--- input chomp numbercheck
1
--- expected yaml
A: 1
a: 2
B: 3
b: 4
C: 5
D: 6
=== Post-Round 2 prefs
--- input chomp prefcheck
1
--- expected yaml
A: [ White, Mild ]
a: [ Black, Mild ]
B: [ Black, Mild ]
b: [ White, Strong ]
C: [ White, Mild ]
D: [ Black, Strong ]
=== Post-Round 2 floats
--- input chomp floatcheck
1
--- expected yaml
A: [ Not, Not ]
a: [ Not, Not ]
B: [ Not, Up ]
b: [ ~, Not ]
C: [ Not, Down ]
D: [ Down, Not ]
=== Post-Round 2 score
--- input chomp scorecheck
1
--- expected yaml
A: 1
a: 1
B: 1
b: 0
C: 1
D: 2
=== Round 3 pairingnumbers
--- input chomp numbercheck
2
--- expected yaml
A: 1
a: 2
B: 3
b: 4
C: 5
c: 6
D: 7
=== Post-Round 3 prefs
--- input chomp prefcheck
2
--- expected yaml
A: [ Black, Strong ]
a: [ White, Strong ]
B: [ White, Strong ]
b: [ Black, Mild ]
C: [ Black, Strong ]
c: [ ~, Mild ]
D: [ White, Mild ]
=== Post-Round 3 floats
--- input chomp floatcheck
2
--- expected yaml
A: [ Not, Not, Not ]
a: [ Not, Not, Not ]
B: [ Not, Up, Down ]
b: [ ~, Not, Up ]
C: [ Not, Down, Up ]
c: [ ~, ~, Down ]
D: [ Down, Not, Down ]
=== Post-Round 3 score
--- input chomp scorecheck
2
--- expected yaml
A: 2
a: 1
B: 1
b: 1
C: 2
c: 1
D: 2
--- LAST
=== Round 4 pairingnumbers
--- input chomp numbercheck
3
--- expected yaml
A: 1
a: 2
B: 3
b: 4
C: 5
c: 6
D: 7
d: 8
=== Post-Round 4 prefs
--- input chomp prefcheck
3
--- expected yaml
A: [ White, Mild ]
a: [ Black, Mild ]
B: [ Black, Mild ]
b: [ White, Strong ]
C: [ Black, Absolute ]
c: [ White, Strong ]
D: [ Black, Strong ]
d: [ White, Strong ]
=== Post-Round 4 floats
--- input chomp floatcheck
3
--- expected yaml
A: [ Not, Not, Not, Not ]
a: [ Not, Not, Not, Down ]
B: [ Not, Up, Down, Not ]
b: [ ~, Not, Up, Up ]
C: [ Not, Down, Up, Not ]
c: [ ~, ~, Down, Not ]
D: [ Down, Not, Down, Down ]
d: [ ~, ~, ~, Up ]
=== Post-Round 4 score
--- input chomp scorecheck
3
--- expected yaml
A: 2
a: 2
B: 2
b: 1
C: 3
c: 1
D: 3
d: 0
( run in 2.201 seconds using v1.01-cache-2.11-cpan-302cb4679cc )