getLength()); self::assertEquals([], $path->getPath()); self::assertEquals([], $path->expandPath()); } /** * @testdox The diagonal euclidean path length is calculated correctly * @covers phpOMS\Algorithm\PathFinding\Path */ public function testDiagonalPathLength() : void { $grid = Grid::createGridFromArray([ [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], ], Node::class); $path = new Path($grid); $path->addNode(new Node(1, 3)); $path->addNode(new Node(3, 1)); $path->addNode(new Node(4, 0)); self::assertEqualsWithDelta(4.2426, $path->getLength(), 0.001); } /** * @testdox The straight euclidean path length is calculated correctly * @covers phpOMS\Algorithm\PathFinding\Path */ public function testStraightPathLength() : void { $grid = Grid::createGridFromArray([ [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], ], Node::class); $path = new Path($grid); $path->addNode(new Node(1, 3)); $path->addNode(new Node(1, 1)); $path->addNode(new Node(3, 1)); self::assertEqualsWithDelta(4.0, $path->getLength(), 0.001); } /** * @testdox The path is correctly expanded in case only jump points are defined * @covers phpOMS\Algorithm\PathFinding\Path */ public function testPathExpansion() : void { $grid = Grid::createGridFromArray([ [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], ], Node::class); $path = new Path($grid); $path->addNode(new Node(1, 3)); $path->addNode(new Node(3, 1)); $path->addNode(new Node(4, 0)); self::assertEquals(3, \count($path->getPath())); self::assertEquals(4, \count($path->expandPath())); } }