* @category Class * @license https://www.gnu.org/licenses/lgpl-3.0.en.html GNU Lesser General Public License * @link www.splendidbear.org * @since 2026. 04. 21. */ #[TestDox('User Stats')] class UserStatsTest extends TestCase { #[Test] #[TestDox('Get win rate calculates correctly')] public function getWinRateCalculatesCorrectly(): void { $stats = new UserStats(); $stats->wins = 60; $stats->gamesWithScores = 100; $result = $stats->getWinRate(); $this->assertSame(60, $result); } #[Test] #[TestDox('Get win rate with zero games returns zero')] public function getWinRateWithZeroGamesReturnsZero(): void { $stats = new UserStats(); $stats->wins = 10; $stats->gamesWithScores = 0; $result = $stats->getWinRate(); $this->assertSame(0, $result); } #[Test] #[TestDox('Get win rate rounds correctly')] public function getWinRateRoundsCorrectly(): void { $stats = new UserStats(); $stats->wins = 33; $stats->gamesWithScores = 100; $result = $stats->getWinRate(); $this->assertSame(33, $result); } #[Test] #[TestDox('Get avg score calculates correctly')] public function getAvgScoreCalculatesCorrectly(): void { $stats = new UserStats(); $stats->totalMines = 550; $stats->gamesWithScores = 100; $result = $stats->getAvgScore(); $this->assertSame(6, $result); // 550/100 = 5.5 -> 6 } #[Test] #[TestDox('Get avg score with zero games returns zero')] public function getAvgScoreWithZeroGamesReturnsZero(): void { $stats = new UserStats(); $stats->totalMines = 100; $stats->gamesWithScores = 0; $result = $stats->getAvgScore(); $this->assertSame(0, $result); } #[Test] #[TestDox('Get avg score rounds down')] public function getAvgScoreRoundsDown(): void { $stats = new UserStats(); $stats->totalMines = 101; $stats->gamesWithScores = 100; $result = $stats->getAvgScore(); $this->assertSame(1, $result); // 101/100 = 1.01 -> 1 } #[Test] #[TestDox('Get avg score rounds up')] public function getAvgScoreRoundsUp(): void { $stats = new UserStats(); $stats->totalMines = 151; $stats->gamesWithScores = 100; $result = $stats->getAvgScore(); $this->assertSame(2, $result); // 151/100 = 1.51 -> 2 } #[Test] #[TestDox('Default values')] public function defaultValues(): void { $stats = new UserStats(); $this->assertSame(0, $stats->userId); $this->assertSame(0, $stats->totalGames); $this->assertSame(0, $stats->wins); $this->assertSame(0, $stats->losses); $this->assertSame(0, $stats->draws); $this->assertSame(0, $stats->totalMines); $this->assertSame('0.0', $stats->totalBonusPoints); $this->assertSame('0.0', $stats->avgBonus); $this->assertSame(0, $stats->bestChain); $this->assertSame(0, $stats->blindHits); $this->assertSame(0, $stats->edgeMines); $this->assertSame(0, $stats->gamesWithScores); $this->assertNull($stats->lastGameAt); } }