Commit | Line | Data |
---|---|---|
dc4278d6 MG |
1 | #!/usr/bin/perl |
2 | use strict; | |
3 | use warnings; | |
4 | ||
5 | use Test::More tests => 7; | |
6 | BEGIN { use_ok('Games::Ratings::LogisticElo', 'multi_elo') }; | |
7 | ||
8 | my $player = Games::Ratings::LogisticElo->new; | |
9 | $player->set_rating(2240); | |
10 | $player->set_coefficient(15); | |
11 | $player->add_game({ | |
12 | opponent_rating => 2114, | |
13 | result => 'win', | |
14 | }); | |
15 | my $rating_change = int ($player->get_rating_change + 0.5); | |
16 | my $new_rating = int ($player->get_new_rating + 0.5); | |
17 | ||
18 | is $rating_change, 5, 'rating change'; | |
19 | is $new_rating, 2245, 'new rating'; | |
20 | ||
21 | ||
22 | sub clean_ratings { | |
23 | map { int ($_ + 0.5) } @_ | |
24 | } | |
25 | ||
26 | my @ratings = clean_ratings multi_elo [2240, 5]; | |
27 | is_deeply [@ratings], [2240], 'multi_elo - 1 arg'; | |
28 | ||
29 | @ratings = clean_ratings multi_elo [2240, 5], [2114, 2]; | |
30 | is_deeply [@ratings], [2245, 2109], 'multi_elo - 2 args'; | |
31 | ||
32 | @ratings = clean_ratings multi_elo 30, [2114, 2], [2240, 5]; | |
33 | is_deeply [@ratings], [2104, 2250], 'multi_elo - 2 args, custom K'; | |
34 | ||
35 | ||
36 | $player = Games::Ratings::LogisticElo->new; | |
37 | $player->set_rating(2240); | |
38 | $player->set_coefficient(15); | |
39 | $player->add_game({ | |
40 | opponent_rating => 2240, | |
41 | result => 'draw', | |
42 | }) for 1 .. 100; | |
43 | $rating_change = int ($player->get_rating_change + 0.5); | |
44 | is $rating_change, 0, 'rating change (only draws against self)'; |