forked from TheAlgorithms/PHP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DepthFirstSearchTest.php
48 lines (44 loc) · 1.14 KB
/
DepthFirstSearchTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
require_once __DIR__ . '/../../vendor/autoload.php';
require_once __DIR__ . '/../../Graphs/DepthFirstSearch.php';
use PHPUnit\Framework\TestCase;
class DepthFirstSearchTest extends TestCase
{
public function testDepthFirstSearch()
{
$graph = array(
"A" => ["B", "C", "D"],
"B" => ["A", "D", "E"],
"C" => ["A", "F"],
"D" => ["B", "D"],
"E" => ["B", "F"],
"F" => ["C", "E", "G"],
"G" => ["F"],
);
$visited = dfs($graph, "A");
$this->assertEquals(["A", "B", "D", "E", "F", "C", "G"], $visited);
}
public function testDepthFirstSearch2()
{
$graph = array(
[1, 2],
[2],
[0, 3],
[3],
);
$visited = dfs($graph, 2);
$this->assertEquals([2, 0, 1, 3], $visited);
}
public function testDepthFirstSearch3()
{
$graph = array(
[2, 3, 1],
[0],
[0, 4],
[0],
[2],
);
$visited = dfs($graph, 0);
$this->assertEquals([0, 2, 4, 3, 1], $visited);
}
}