From 02455892dac1d52914e5702fd8e895d5cee1f083 Mon Sep 17 00:00:00 2001 From: FBeans Date: Sat, 21 May 2022 19:07:32 +0100 Subject: Add world, boid and all collision detection --- tests/World/BoidTest.php | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/World/BoidTest.php (limited to 'tests/World/BoidTest.php') 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 @@ +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)); + } +} -- cgit v1.2.3