]> git.localhorst.tv Git - alttp.git/blob - tests/Unit/Models/ChatLibTest.php
separate chatlib database generation
[alttp.git] / tests / Unit / Models / ChatLibTest.php
1 <?php
2
3 namespace Tests\Unit\Models;
4
5 use App\Models\ChatLib;
6 use PHPUnit\Framework\TestCase;
7
8 class ChatLibTest extends TestCase {
9
10         public function test_binary_search() {
11                 $options = [
12                         ['a', 0, 2],
13                         ['b', 2, 3],
14                         ['c', 3, 6],
15                 ];
16
17                 $this->assertEquals('a', ChatLib::search($options, 0)[0]);
18                 $this->assertEquals('a', ChatLib::search($options, 1)[0]);
19                 $this->assertEquals('b', ChatLib::search($options, 2)[0]);
20                 $this->assertEquals('c', ChatLib::search($options, 3)[0]);
21                 $this->assertEquals('c', ChatLib::search($options, 4)[0]);
22                 $this->assertEquals('c', ChatLib::search($options, 5)[0]);
23
24                 $this->assertEquals('a', ChatLib::search($options, -1)[0]);
25                 $this->assertEquals('c', ChatLib::search($options, 6)[0]);
26         }
27
28 }