1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace SmrTest\lib\DefaultGame; |
4
|
|
|
|
5
|
|
|
use Smr\UserRanking; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @covers Smr\UserRanking |
9
|
|
|
*/ |
10
|
|
|
class UserRankingTest extends \PHPUnit\Framework\TestCase { |
11
|
|
|
|
12
|
|
|
public function test_getName() { |
13
|
|
|
$this->assertSame('Expert', UserRanking::getName(6)); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
public function test_getAllNames() { |
17
|
|
|
$this->assertSame('Expert', UserRanking::getAllNames()[6]); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function test_rank_limits() { |
21
|
|
|
$ranks = array_keys(UserRanking::getAllNames()); |
22
|
|
|
$this->assertSame(UserRanking::MIN_RANK, min($ranks)); |
23
|
|
|
$this->assertSame(UserRanking::MAX_RANK, max($ranks)); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function test_score_limits() { |
27
|
|
|
// test the lowest possible score |
28
|
|
|
$rank = UserRanking::getRankFromScore(0); |
29
|
|
|
$this->assertSame(UserRanking::MIN_RANK, $rank); |
30
|
|
|
// test an absurdly high score |
31
|
|
|
$rank = UserRanking::getRankFromScore(PHP_INT_MAX); |
32
|
|
|
$this->assertSame(UserRanking::MAX_RANK, $rank); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function test_getMinScoreForRank() { |
36
|
|
|
// test all ranks |
37
|
|
|
foreach (UserRanking::getAllNames() as $rank => $name) { |
38
|
|
|
$minScore = UserRanking::getMinScoreForRank($rank); |
39
|
|
|
// make sure the given min score is still the same rank |
40
|
|
|
$rankFromScore = UserRanking::getRankFromScore($minScore); |
41
|
|
|
$this->assertSame($rank, $rankFromScore); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
} |
46
|
|
|
|