diff options
Diffstat (limited to 'tests/World')
-rw-r--r-- | tests/World/BoidTest.php | 45 | ||||
-rw-r--r-- | tests/World/WorldTest.php | 25 |
2 files changed, 70 insertions, 0 deletions
diff --git a/tests/World/BoidTest.php b/tests/World/BoidTest.php new file mode 100644 index 0000000..1c7202d --- /dev/null +++ b/tests/World/BoidTest.php @@ -0,0 +1,45 @@ +<?php + +namespace Tests\World; + +use App\World\Boid; +use App\World\World; +use PHPUnit\Framework\TestCase; + +class BoidTest extends TestCase +{ + public function testBoidConstruction() + { + $boid = new Boid(5, 1, 2, 'boid'); + + $this->assertEquals(5, $boid->radius()); + $this->assertEquals([1, 2], $boid->position()); + $this->assertEquals('boid', $boid->name()); + + $boid = new Boid(5, 1, 2); + $this->assertEquals(5, $boid->radius()); + $this->assertEquals([1, 2], $boid->position()); + $this->assertTrue(is_string($boid->name())); + $this->assertTrue(strpos($boid->name(), 'boid') === 0); + } + + public function testBoidWorldCollision() + { + $world = new World(200, 200); + + $boid = new Boid(5, 10, 10); + $this->assertEquals(false, $boid->isCollisionWithWorld($world->width(), $world->height(), 0, 0)); + + $boid = new Boid(5, 0, 0); + $this->assertEquals(true, $boid->isCollisionWithWorld($world->width(), $world->height(), 0, 0)); + + $boid = new Boid(5, -100, 100); + $this->assertEquals(true, $boid->isCollisionWithWorld($world->width(), $world->height(), 0, 0)); + + $boid = new Boid(5, 100, -100); + $this->assertEquals(true, $boid->isCollisionWithWorld($world->width(), $world->height(), 0, 0)); + + $boid = new Boid(5, 200, 200); + $this->assertEquals(true, $boid->isCollisionWithWorld($world->width(), $world->height(), 0, 0)); + } +} diff --git a/tests/World/WorldTest.php b/tests/World/WorldTest.php new file mode 100644 index 0000000..c2b117e --- /dev/null +++ b/tests/World/WorldTest.php @@ -0,0 +1,25 @@ +<?php + +namespace Tests\World; + +use App\World\World; +use PHPUnit\Framework\TestCase; + +class WorldTest extends TestCase +{ + public function testWorldConstruction() + { + $world = new World(1, 2, 'test-world'); + + $this->assertEquals('test-world', $world->name()); + $this->assertEquals(1, $world->width()); + $this->assertEquals(2, $world->height()); + + $world = new World(1, 2); + + $this->assertTrue(is_string($world->name())); + $this->assertTrue(strpos($world->name(), 'world') === 0); + $this->assertEquals(1, $world->width()); + $this->assertEquals(2, $world->height()); + } +} |