3 namespace Tests\Unit\Models;
5 use App\Models\Channel;
6 use App\Models\GuessingWinner;
7 use PHPUnit\Framework\TestCase;
9 class ChannelTest extends TestCase {
11 public function test_guessing_solutions() {
12 $channel = new Channel();
13 $channel->guessing_type = 'gtbk';
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'));
22 $this->assertFalse($channel->isValidGuess('1:22:56'));
23 $this->assertFalse($channel->isValidGuess('torch'));
26 public function test_guessing_scoring() {
27 $channel = new Channel();
28 $channel->guessing_type = 'gtbk';
29 $channel->guessing_settings = [
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,
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));
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));
51 public function test_guessing_winners() {
52 $channel = new Channel();
53 $channel->guessing_type = 'gtbk';
54 $channel->guessing_settings = [
56 'close_winners_message' => 'within {distance}: {names}',
57 'no_winners_message' => 'no winners',
58 'winners_message' => 'winners: {names}',
62 $this->assertEquals('no winners', $channel->listGuessingWinners([]));
65 $winner = new GuessingWinner();
66 $winner->uname = 'Horstie';
68 $winner->solution = '3';
72 $this->assertEquals('winners: Horstie', $channel->listGuessingWinners($winners));
74 $winner = new GuessingWinner();
75 $winner->uname = 'Borstie';
77 $winner->solution = '3';
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));
86 $winners[0]->guess = '1';
87 $winners[1]->guess = '5';
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));
95 $channel->guessing_settings = [
97 'no_winners_message' => 'no winners',
98 'winners_message' => 'winners: {names}',
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));