File tree Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -116,6 +116,24 @@ public function testSeparateGraphsAreNotReachable()
116
116
$ alg ->getEdgesTo ($ vg2 );
117
117
}
118
118
119
+ public function testGraphUnweighted ()
120
+ {
121
+ // 1 -> 2
122
+ $ graph = new Graph ();
123
+ $ v1 = $ graph ->createVertex (1 );
124
+ $ v2 = $ graph ->createVertex (2 );
125
+ $ e1 = $ v1 ->createEdgeTo ($ v2 );
126
+
127
+ $ alg = $ this ->createAlg ($ v1 );
128
+
129
+ $ expectedWeight = $ this ->getExpectedWeight (array ($ e1 ));
130
+ $ this ->assertEquals ($ expectedWeight , $ alg ->getDistance ($ v2 ));
131
+ $ this ->assertEquals (array (2 => $ expectedWeight ), $ alg ->getDistanceMap ());
132
+ $ this ->assertEquals (array ($ e1 ), $ alg ->getEdges ()->getVector ());
133
+ $ this ->assertEquals (array ($ e1 ), $ alg ->getEdgesTo ($ v2 )->getVector ());
134
+ $ this ->assertEquals (array (2 ), $ alg ->getVertices ()->getIds ());
135
+ }
136
+
119
137
public function testGraphTwoComponents ()
120
138
{
121
139
// 1 -[10]-> 2
Original file line number Diff line number Diff line change @@ -72,15 +72,15 @@ public function testLoopNegativeWeightIsCycle()
72
72
73
73
public function testNegativeComponentHasCycle ()
74
74
{
75
- // 1 -- 2 3 --[-1]--> 4
76
- // ^ |
77
- // \---[-2]----/
75
+ // 1 -[1]-> 2 3 --[-1]--> 4
76
+ // ^ |
77
+ // \---[-2]----/
78
78
$ graph = new Graph ();
79
79
$ v1 = $ graph ->createVertex (1 );
80
80
$ v2 = $ graph ->createVertex (2 );
81
81
$ v3 = $ graph ->createVertex (3 );
82
82
$ v4 = $ graph ->createVertex (4 );
83
- $ e1 = $ v1 ->createEdge ($ v2 );
83
+ $ e1 = $ v1 ->createEdgeTo ($ v2)-> setWeight ( 1 );
84
84
$ e2 = $ v3 ->createEdgeTo ($ v4 )->setWeight (-1 );
85
85
$ e3 = $ v4 ->createEdgeTo ($ v3 )->setWeight (-2 );
86
86
You can’t perform that action at this time.
0 commit comments