diff --git a/infection.json.dist b/infection.json.dist new file mode 100644 index 0000000..a88fae0 --- /dev/null +++ b/infection.json.dist @@ -0,0 +1,11 @@ +{ + "timeout": 10, + "source": { + "directories": [ + "src" + ] + }, + "logs": { + "text": "build/logs/infection-log.txt" + } +} diff --git a/tests/Adapting_a_network.php b/tests/Adapting_a_network.php index 9786326..cea2371 100644 --- a/tests/Adapting_a_network.php +++ b/tests/Adapting_a_network.php @@ -45,6 +45,37 @@ function finding_paths_through_a_simple_undirected_graph() $this->assertSame(['A', 'C', 'D'], $shortestPathFromA['D']); } + /** @test */ + function finding_paths_through_a_simple_undirected_graph_with_numeric_ids() + { + $graph = new Graph(); + $a = $graph->createVertex(1); + $b = $graph->createVertex(2); + $c = $graph->createVertex(3); + $d = $graph->createVertex(4); + + $a->createEdgeTo($b)->setWeight(5); + $a->createEdgeTo($c)->setWeight(8); + $b->createEdgeTo($d)->setWeight(9); + $b->createEdgeTo($a)->setWeight(1); + $c->createEdgeTo($d)->setWeight(4); + $c->createEdgeTo($a)->setWeight(1); + $d->createEdgeTo($b)->setWeight(3); + $d->createEdgeTo($c)->setWeight(9); + + $shortestPath = DynamicPathfinder::operatingIn(AdaptedNetwork::from($graph)); + + $this->assertEquals([1, 3, 4], $shortestPath->between('1', '4')); + $this->assertEquals([4, 2, 1], $shortestPath->between('4', '1')); + + $shortestPathFromA = $shortestPath->from('1'); + + $this->assertCount(3, $shortestPathFromA); + $this->assertEquals([1, 2], $shortestPathFromA[2]); + $this->assertEquals([1, 3], $shortestPathFromA[3]); + $this->assertEquals([1, 3, 4], $shortestPathFromA[4]); + } + /** @test */ function finding_paths_through_a_simple_directed_graph() { diff --git a/tests/Adapting_an_environment.php b/tests/Adapting_an_environment.php index 72150c3..afb47bb 100644 --- a/tests/Adapting_an_environment.php +++ b/tests/Adapting_an_environment.php @@ -167,6 +167,44 @@ function finding_paths_through_a_directed_2d_multi_graph() $this->assertSame(['A', 'C', 'D'], $shortestPathFromA['D']); } + /** @test */ + function finding_paths_through_a_directed_2d_multi_graph_with_numeric_ids() + { + $graph = new Graph(); + $a = $graph->createVertex(1); + $a->setAttribute('x', 0); + $a->setAttribute('y', 0); + $b = $graph->createVertex(2); + $b->setAttribute('x', 4); + $b->setAttribute('y', 1); + $c = $graph->createVertex(3); + $c->setAttribute('x', 0); + $c->setAttribute('y', 8); + $d = $graph->createVertex(4); + $d->setAttribute('x', 5); + $d->setAttribute('y', 10); + + $a->createEdge($b)->setWeight(5); + $a->createEdge($c)->setWeight(8); + $a->createEdge($c)->setWeight(15); + $b->createEdge($d)->setWeight(9); + $c->createEdge($d)->setWeight(4); + + $shortestPath = DynamicPathfinder::operatingIn( + AdaptedEnvironment::from($graph) + ); + + $this->assertEquals([1, 3, 4], $shortestPath->between('1', '4')); + $this->assertEquals([4, 3, 1], $shortestPath->between('4', '1')); + + $shortestPathFromA = $shortestPath->from('1'); + + $this->assertCount(3, $shortestPathFromA); + $this->assertEquals([1, 2], $shortestPathFromA[2]); + $this->assertEquals([1, 3], $shortestPathFromA[3]); + $this->assertEquals([1, 3, 4], $shortestPathFromA[4]); + } + /** @test */ function building_an_index_of_the_graph() { diff --git a/tests/Unit/AdaptedEnvironmentTest.php b/tests/Unit/AdaptedEnvironmentTest.php index 70a76d6..54858fe 100644 --- a/tests/Unit/AdaptedEnvironmentTest.php +++ b/tests/Unit/AdaptedEnvironmentTest.php @@ -89,4 +89,22 @@ function cannot_get_the_position_of_a_non_existing_node() $environment->positionOf('X'); } + + /** @test */ + function all_undeclared_dimensions_are_seen_as_zero() + { + $graph = new Graph(); + $a = $graph->createVertex('A'); + $a->setAttribute('x', 10); + $a->setAttribute('y', 15); + $environment = AdaptedEnvironment::from3D($graph); + + $position = $environment->positionOf('A'); + + $this->assertEquals(10, $position[0]); + $this->assertEquals(15, $position[1]); + $this->assertEquals(0, $position[2]); + $this->assertEquals(0, $position[3]); + $this->assertEquals(0, $position[391]); + } } diff --git a/tests/Unit/AdaptedNetworkTest.php b/tests/Unit/AdaptedNetworkTest.php index 6d0dce1..87bee11 100644 --- a/tests/Unit/AdaptedNetworkTest.php +++ b/tests/Unit/AdaptedNetworkTest.php @@ -73,7 +73,7 @@ function graphs_without_negatively_weighing_edges_have_no_negative_edge_costs() $graph = new Graph(); $a = $graph->createVertex('A'); $edge = $a->createEdge($a); - $edge->setWeight(1); + $edge->setWeight(0); $environment = AdaptedNetwork::from($graph);