]> git.localhorst.tv Git - alttp.git/blobdiff - tests/Unit/Models/ChatLibTest.php
separate chatlib database generation
[alttp.git] / tests / Unit / Models / ChatLibTest.php
diff --git a/tests/Unit/Models/ChatLibTest.php b/tests/Unit/Models/ChatLibTest.php
new file mode 100644 (file)
index 0000000..7289200
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+
+namespace Tests\Unit\Models;
+
+use App\Models\ChatLib;
+use PHPUnit\Framework\TestCase;
+
+class ChatLibTest extends TestCase {
+
+       public function test_binary_search() {
+               $options = [
+                       ['a', 0, 2],
+                       ['b', 2, 3],
+                       ['c', 3, 6],
+               ];
+
+               $this->assertEquals('a', ChatLib::search($options, 0)[0]);
+               $this->assertEquals('a', ChatLib::search($options, 1)[0]);
+               $this->assertEquals('b', ChatLib::search($options, 2)[0]);
+               $this->assertEquals('c', ChatLib::search($options, 3)[0]);
+               $this->assertEquals('c', ChatLib::search($options, 4)[0]);
+               $this->assertEquals('c', ChatLib::search($options, 5)[0]);
+
+               $this->assertEquals('a', ChatLib::search($options, -1)[0]);
+               $this->assertEquals('c', ChatLib::search($options, 6)[0]);
+       }
+
+}