diff options
author | FBeans <phil@pgburton.com> | 2022-05-21 19:07:32 +0100 |
---|---|---|
committer | FBeans <phil@pgburton.com> | 2022-05-21 19:07:32 +0100 |
commit | 02455892dac1d52914e5702fd8e895d5cee1f083 (patch) | |
tree | 5cbafc717c099ee42c32ee21270b569a55089261 /tests/World/BoidTest.php | |
parent | 5832634b35b475f607f4c695ccad310ee2467e57 (diff) |
Diffstat (limited to 'tests/World/BoidTest.php')
-rw-r--r-- | tests/World/BoidTest.php | 45 |
1 files changed, 45 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)); + } +} |