]> git.localhorst.tv Git - alttp.git/blob - tests/Unit/Models/ChannelTest.php
fix missing gt bosses on merge
[alttp.git] / tests / Unit / Models / ChannelTest.php
1 <?php
2
3 namespace Tests\Unit\Models;
4
5 use App\Models\Channel;
6 use App\Models\GuessingWinner;
7 use PHPUnit\Framework\TestCase;
8
9 class ChannelTest extends TestCase {
10
11         public function test_guessing_solutions() {
12                 $channel = new Channel();
13                 $channel->guessing_type = 'gtbk';
14
15                 $this->assertTrue($channel->isValidGuess('1'));
16                 $this->assertTrue($channel->isValidGuess('22'));
17                 $this->assertTrue($channel->isValidGuess('3 '));
18                 $this->assertTrue($channel->isValidGuess('vier 4Head'));
19                 $this->assertTrue($channel->isValidGuess('Vier 4Head'));
20                 $this->assertTrue($channel->isValidGuess('roodyo1Gtbigkey'));
21
22                 $this->assertFalse($channel->isValidGuess('1:22:56'));
23                 $this->assertFalse($channel->isValidGuess('torch'));
24         }
25
26         public function test_guessing_scoring() {
27                 $channel = new Channel();
28                 $channel->guessing_type = 'gtbk';
29                 $channel->guessing_settings = [
30                         'gtbk' => [
31                                 'points_exact_first' => 5,
32                                 'points_exact_other' => 4,
33                                 'points_close_first' => 3,
34                                 'points_close_other' => 2,
35                                 'points_close_max' => 5,
36                         ],
37                 ];
38
39                 $this->assertEquals(5, $channel->scoreGuessing('3', '3', true));
40                 $this->assertEquals(4, $channel->scoreGuessing('12', '12', false));
41                 $this->assertEquals(3, $channel->scoreGuessing('15', '14', true));
42                 $this->assertEquals(2, $channel->scoreGuessing('8', '6', false));
43                 $this->assertEquals(0, $channel->scoreGuessing('7', '1', true));
44                 $this->assertEquals(0, $channel->scoreGuessing('3', '22', false));
45
46                 $this->assertEquals(5, $channel->scoreGuessing('2', 'roodyo1Gtbigkey', true));
47                 $this->assertEquals(5, $channel->scoreGuessing('4', 'Vier 4Head', true));
48                 $this->assertEquals(5, $channel->scoreGuessing('5', '5 ', true));
49         }
50
51         public function test_guessing_winners() {
52                 $channel = new Channel();
53                 $channel->guessing_type = 'gtbk';
54                 $channel->guessing_settings = [
55                         'gtbk' => [
56                                 'close_winners_message' => 'within {distance}: {names}',
57                                 'no_winners_message' => 'no winners',
58                                 'winners_message' => 'winners: {names}',
59                         ],
60                 ];
61
62                 $this->assertEquals('no winners', $channel->listGuessingWinners([]));
63
64                 $winners = [];
65                 $winner = new GuessingWinner();
66                 $winner->uname = 'Horstie';
67                 $winner->guess = '3';
68                 $winner->solution = '3';
69                 $winner->score = 1;
70                 $winners[] = $winner;
71
72                 $this->assertEquals('winners: Horstie', $channel->listGuessingWinners($winners));
73
74                 $winner = new GuessingWinner();
75                 $winner->uname = 'Borstie';
76                 $winner->guess = '3';
77                 $winner->solution = '3';
78                 $winner->score = 1;
79                 $winners[] = $winner;
80
81                 $channel->languages = ['de'];
82                 $this->assertEquals('winners: Horstie und Borstie', $channel->listGuessingWinners($winners));
83                 $channel->languages = ['en'];
84                 $this->assertEquals('winners: Horstie and Borstie', $channel->listGuessingWinners($winners));
85
86                 $winners[0]->guess = '1';
87                 $winners[1]->guess = '5';
88
89
90                 $channel->languages = ['de'];
91                 $this->assertEquals('within 2: Horstie und Borstie', $channel->listGuessingWinners($winners));
92                 $channel->languages = ['en'];
93                 $this->assertEquals('within 2: Horstie and Borstie', $channel->listGuessingWinners($winners));
94
95                 $channel->guessing_settings = [
96                         'gtbk' => [
97                                 'no_winners_message' => 'no winners',
98                                 'winners_message' => 'winners: {names}',
99                         ],
100                 ];
101
102                 $channel->languages = ['de'];
103                 $this->assertEquals('winners: Horstie und Borstie', $channel->listGuessingWinners($winners));
104                 $channel->languages = ['en'];
105                 $this->assertEquals('winners: Horstie and Borstie', $channel->listGuessingWinners($winners));
106         }
107
108 }