Skip to content

Commit

Permalink
Add infection config and improve MSI
Browse files Browse the repository at this point in the history
  • Loading branch information
Stratadox committed Mar 7, 2019
1 parent bbe0401 commit 700b9f3
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 1 deletion.
11 changes: 11 additions & 0 deletions infection.json.dist
@@ -0,0 +1,11 @@
{
"timeout": 10,
"source": {
"directories": [
"src"
]
},
"logs": {
"text": "build/logs/infection-log.txt"
}
}
31 changes: 31 additions & 0 deletions tests/Adapting_a_network.php
Expand Up @@ -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()
{
Expand Down
38 changes: 38 additions & 0 deletions tests/Adapting_an_environment.php
Expand Up @@ -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()
{
Expand Down
18 changes: 18 additions & 0 deletions tests/Unit/AdaptedEnvironmentTest.php
Expand Up @@ -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]);
}
}
2 changes: 1 addition & 1 deletion tests/Unit/AdaptedNetworkTest.php
Expand Up @@ -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);

Expand Down

0 comments on commit 700b9f3

Please sign in to comment.