File tree Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use Fhaculty \Graph \Algorithm \Loop as AlgorithmLoop ;
4
+ use Fhaculty \Graph \Graph ;
5
+
6
+ class LoopTest extends TestCase
7
+ {
8
+ public function testGraphEmpty ()
9
+ {
10
+ $ graph = new Graph ();
11
+
12
+ $ alg = new AlgorithmLoop ($ graph );
13
+
14
+ $ this ->assertFalse ($ alg ->hasLoop ());
15
+ }
16
+
17
+ public function testGraphWithMixedCircuitIsNotConsideredLoop ()
18
+ {
19
+ // 1 -> 2
20
+ // 2 -- 1
21
+ $ graph = new Graph ();
22
+ $ v1 = $ graph ->createVertex (1 );
23
+ $ v2 = $ graph ->createVertex (2 );
24
+ $ v1 ->createEdgeTo ($ v2 );
25
+ $ v2 ->createEdge ($ v1 );
26
+
27
+ $ alg = new AlgorithmLoop ($ graph );
28
+
29
+ $ this ->assertFalse ($ alg ->hasLoop ());
30
+ $ this ->assertFalse ($ alg ->hasLoopVertex ($ v1 ));
31
+ $ this ->assertFalse ($ alg ->hasLoopVertex ($ v2 ));
32
+ }
33
+
34
+ public function testGraphUndirectedLoop ()
35
+ {
36
+ // 1 -- 1
37
+ $ graph = new Graph ();
38
+ $ graph ->createVertex (1 )->createEdge ($ v1 = $ graph ->getVertex (1 ));
39
+
40
+ $ alg = new AlgorithmLoop ($ graph );
41
+
42
+ $ this ->assertTrue ($ alg ->hasLoop ());
43
+ $ this ->assertTrue ($ alg ->hasLoopVertex ($ v1 ));
44
+ }
45
+
46
+ public function testGraphDirectedLoop ()
47
+ {
48
+ // 1 -> 1
49
+ $ graph = new Graph ();
50
+ $ graph ->createVertex (1 )->createEdgeTo ($ v1 = $ graph ->getVertex (1 ));
51
+
52
+ $ alg = new AlgorithmLoop ($ graph );
53
+
54
+ $ this ->assertTrue ($ alg ->hasLoop ());
55
+ $ this ->assertTrue ($ alg ->hasLoopVertex ($ v1 ));
56
+ }
57
+ }
You can’t perform that action at this time.
0 commit comments