Debian Codegraph @

paths_test.go

raw symbols SCIP
1 package graph
2
3 import (
4 "reflect"
5 "sort"
6 "testing"
7 )
8
9 func TestDirectedCreatesCycle(t *testing.T) {
10 tests := map[string]struct {
11 vertices []int
12 edges []Edge[int]
13 sourceHash int
14 targetHash int
15 createsCycle bool
16 }{
17 "directed 2-4-7-5 cycle": {
18 vertices: []int{1, 2, 3, 4, 5, 6, 7},
19 edges: []Edge[int]{
20 {Source: 1, Target: 2},
21 {Source: 1, Target: 3},
22 {Source: 2, Target: 4},
23 {Source: 3, Target: 6},
24 {Source: 4, Target: 7},
25 {Source: 5, Target: 2},
26 },
27 sourceHash: 7,
28 targetHash: 5,
29 createsCycle: true,
30 },
31 "undirected 2-4-7-5 'cycle'": {
32 vertices: []int{1, 2, 3, 4, 5, 6, 7},
33 edges: []Edge[int]{
34 {Source: 1, Target: 2},
35 {Source: 1, Target: 3},
36 {Source: 2, Target: 4},
37 {Source: 3, Target: 6},
38 {Source: 4, Target: 7},
39 {Source: 5, Target: 2},
40 },
41 sourceHash: 5,
42 targetHash: 7,
43 // The direction of the edge (57 instead of 75) doesn't create a directed cycle.
44 createsCycle: false,
45 },
46 "no cycle": {
47 vertices: []int{1, 2, 3, 4, 5, 6, 7},
48 edges: []Edge[int]{
49 {Source: 1, Target: 2},
50 {Source: 1, Target: 3},
51 {Source: 2, Target: 4},
52 {Source: 3, Target: 6},
53 {Source: 4, Target: 7},
54 {Source: 5, Target: 2},
55 },
56 sourceHash: 5,
57 targetHash: 6,
58 createsCycle: false,
59 },
60 }
61
62 for name, test := range tests {
63 graph := New(IntHash, Directed())
64
65 for _, vertex := range test.vertices {
66 _ = graph.AddVertex(vertex)
67 }
68
69 for _, edge := range test.edges {
70 if err := graph.AddEdge(edge.Source, edge.Target); err != nil {
71 t.Fatalf("%s: failed to add edge: %s", name, err.Error())
72 }
73 }
74
75 createsCycle, err := CreatesCycle(graph, test.sourceHash, test.targetHash)
76 if err != nil {
77 t.Fatalf("%s: failed to add edge: %s", name, err.Error())
78 }
79
80 if createsCycle != test.createsCycle {
81 t.Errorf("%s: cycle expectancy doesn't match: expected %v, got %v", name, test.createsCycle, createsCycle)
82 }
83 }
84 }
85
86 func TestUndirectedCreatesCycle(t *testing.T) {
87 tests := map[string]struct {
88 vertices []int
89 edges []Edge[int]
90 sourceHash int
91 targetHash int
92 createsCycle bool
93 }{
94 "undirected 2-4-7-5 cycle": {
95 vertices: []int{1, 2, 3, 4, 5, 6, 7},
96 edges: []Edge[int]{
97 {Source: 1, Target: 2},
98 {Source: 1, Target: 3},
99 {Source: 2, Target: 4},
100 {Source: 3, Target: 6},
101 {Source: 4, Target: 7},
102 {Source: 5, Target: 7},
103 },
104 sourceHash: 2,
105 targetHash: 5,
106 createsCycle: true,
107 },
108 "undirected 5-6-3-1-2-7 cycle": {
109 vertices: []int{1, 2, 3, 4, 5, 6, 7},
110 edges: []Edge[int]{
111 {Source: 1, Target: 2},
112 {Source: 1, Target: 3},
113 {Source: 2, Target: 4},
114 {Source: 3, Target: 6},
115 {Source: 4, Target: 7},
116 {Source: 5, Target: 7},
117 },
118 sourceHash: 5,
119 targetHash: 6,
120 createsCycle: true,
121 },
122 "no cycle": {
123 vertices: []int{1, 2, 3, 4, 5, 6, 7},
124 edges: []Edge[int]{
125 {Source: 1, Target: 2},
126 {Source: 1, Target: 3},
127 {Source: 2, Target: 4},
128 {Source: 3, Target: 6},
129 {Source: 4, Target: 7},
130 },
131 sourceHash: 5,
132 targetHash: 7,
133 createsCycle: false,
134 },
135 }
136
137 for name, test := range tests {
138 graph := New(IntHash)
139
140 for _, vertex := range test.vertices {
141 _ = graph.AddVertex(vertex)
142 }
143
144 for _, edge := range test.edges {
145 if err := graph.AddEdge(edge.Source, edge.Target); err != nil {
146 t.Fatalf("%s: failed to add edge: %s", name, err.Error())
147 }
148 }
149
150 createsCycle, err := CreatesCycle(graph, test.sourceHash, test.targetHash)
151 if err != nil {
152 t.Fatalf("%s: failed to add edge: %s", name, err.Error())
153 }
154
155 if createsCycle != test.createsCycle {
156 t.Errorf("%s: cycle expectancy doesn't match: expected %v, got %v", name, test.createsCycle, createsCycle)
157 }
158 }
159 }
160
161 func TestDirectedShortestPath(t *testing.T) {
162 tests := map[string]struct {
163 vertices []string
164 edges []Edge[string]
165 isWeighted bool
166 sourceHash string
167 targetHash string
168 expectedShortestPath []string
169 shouldFail bool
170 }{
171 "graph as on img/dijkstra.svg": {
172 vertices: []string{"A", "B", "C", "D", "E", "F", "G"},
173 edges: []Edge[string]{
174 {Source: "A", Target: "C", Properties: EdgeProperties{Weight: 3}},
175 {Source: "A", Target: "F", Properties: EdgeProperties{Weight: 2}},
176 {Source: "C", Target: "D", Properties: EdgeProperties{Weight: 4}},
177 {Source: "C", Target: "E", Properties: EdgeProperties{Weight: 1}},
178 {Source: "C", Target: "F", Properties: EdgeProperties{Weight: 2}},
179 {Source: "D", Target: "B", Properties: EdgeProperties{Weight: 1}},
180 {Source: "E", Target: "B", Properties: EdgeProperties{Weight: 2}},
181 {Source: "E", Target: "F", Properties: EdgeProperties{Weight: 3}},
182 {Source: "F", Target: "G", Properties: EdgeProperties{Weight: 5}},
183 {Source: "G", Target: "B", Properties: EdgeProperties{Weight: 2}},
184 },
185 isWeighted: true,
186 sourceHash: "A",
187 targetHash: "B",
188 expectedShortestPath: []string{"A", "C", "E", "B"},
189 },
190 "diamond-shaped graph": {
191 vertices: []string{"A", "B", "C", "D"},
192 edges: []Edge[string]{
193 {Source: "A", Target: "B", Properties: EdgeProperties{Weight: 2}},
194 {Source: "A", Target: "C", Properties: EdgeProperties{Weight: 4}},
195 {Source: "B", Target: "D", Properties: EdgeProperties{Weight: 2}},
196 {Source: "C", Target: "D", Properties: EdgeProperties{Weight: 2}},
197 },
198 isWeighted: true,
199 sourceHash: "A",
200 targetHash: "D",
201 expectedShortestPath: []string{"A", "B", "D"},
202 },
203 "unweighted graph": {
204 vertices: []string{"A", "B", "C", "D", "E", "F", "G"},
205 edges: []Edge[string]{
206 {Source: "A", Target: "B", Properties: EdgeProperties{}},
207 {Source: "A", Target: "C", Properties: EdgeProperties{}},
208 {Source: "B", Target: "D", Properties: EdgeProperties{}},
209 {Source: "C", Target: "F", Properties: EdgeProperties{}},
210 {Source: "D", Target: "G", Properties: EdgeProperties{}},
211 {Source: "E", Target: "G", Properties: EdgeProperties{}},
212 {Source: "F", Target: "E", Properties: EdgeProperties{}},
213 },
214 sourceHash: "A",
215 targetHash: "G",
216 expectedShortestPath: []string{"A", "B", "D", "G"},
217 },
218 "source equal to target": {
219 vertices: []string{"A", "B", "C", "D"},
220 edges: []Edge[string]{
221 {Source: "A", Target: "B", Properties: EdgeProperties{Weight: 2}},
222 {Source: "A", Target: "C", Properties: EdgeProperties{Weight: 4}},
223 {Source: "B", Target: "D", Properties: EdgeProperties{Weight: 2}},
224 {Source: "C", Target: "D", Properties: EdgeProperties{Weight: 2}},
225 },
226 isWeighted: true,
227 sourceHash: "B",
228 targetHash: "B",
229 expectedShortestPath: []string{"B"},
230 },
231 "target not reachable in a disconnected graph": {
232 vertices: []string{"A", "B", "C", "D"},
233 edges: []Edge[string]{
234 {Source: "A", Target: "B", Properties: EdgeProperties{Weight: 2}},
235 {Source: "A", Target: "C", Properties: EdgeProperties{Weight: 4}},
236 },
237 isWeighted: true,
238 sourceHash: "A",
239 targetHash: "D",
240 expectedShortestPath: []string{},
241 shouldFail: true,
242 },
243 "target not reachable in a connected graph": {
244 vertices: []string{"A", "B", "C"},
245 edges: []Edge[string]{
246 {Source: "A", Target: "B", Properties: EdgeProperties{Weight: 0}},
247 {Source: "A", Target: "C", Properties: EdgeProperties{Weight: 0}},
248 },
249 sourceHash: "B",
250 targetHash: "C",
251 expectedShortestPath: []string{},
252 shouldFail: true,
253 },
254 "graph from issue 88": {
255 vertices: []string{"A", "B", "C", "D"},
256 edges: []Edge[string]{
257 {Source: "A", Target: "B", Properties: EdgeProperties{Weight: 2}},
258 {Source: "A", Target: "C", Properties: EdgeProperties{Weight: 6}},
259 {Source: "B", Target: "C", Properties: EdgeProperties{Weight: 3}},
260 {Source: "B", Target: "D", Properties: EdgeProperties{Weight: 5}},
261 {Source: "C", Target: "D", Properties: EdgeProperties{Weight: 1}},
262 },
263 isWeighted: true,
264 sourceHash: "A",
265 targetHash: "D",
266 expectedShortestPath: []string{"A", "B", "C", "D"},
267 },
268 }
269
270 for name, test := range tests {
271 graph := New(StringHash, Directed())
272 graph.(*directed[string, string]).traits.IsWeighted = test.isWeighted
273
274 for _, vertex := range test.vertices {
275 _ = graph.AddVertex(vertex)
276 }
277
278 for _, edge := range test.edges {
279 if err := graph.AddEdge(edge.Source, edge.Target, EdgeWeight(edge.Properties.Weight)); err != nil {
280 t.Fatalf("%s: failed to add edge: %s", name, err.Error())
281 }
282 }
283
284 shortestPath, err := ShortestPath(graph, test.sourceHash, test.targetHash)
285
286 if test.shouldFail != (err != nil) {
287 t.Fatalf("%s: error expectancy doesn't match: expected %v, got %v (error: %v)", name, test.shouldFail, (err != nil), err)
288 }
289
290 if len(shortestPath) != len(test.expectedShortestPath) {
291 t.Fatalf("%s: path length expectancy doesn't match: expected %v, got %v", name, len(test.expectedShortestPath), len(shortestPath))
292 }
293
294 for i, expectedVertex := range test.expectedShortestPath {
295 if shortestPath[i] != expectedVertex {
296 t.Errorf("%s: path vertex expectancy doesn't match: expected %v at index %d, got %v", name, expectedVertex, i, shortestPath[i])
297 }
298 }
299 }
300 }
301
302 func TestUndirectedShortestPath(t *testing.T) {
303 tests := map[string]struct {
304 vertices []string
305 edges []Edge[string]
306 sourceHash string
307 targetHash string
308 isWeighted bool
309 expectedShortestPath []string
310 shouldFail bool
311 }{
312 "graph as on img/dijkstra.svg": {
313 vertices: []string{"A", "B", "C", "D", "E", "F", "G"},
314 edges: []Edge[string]{
315 {Source: "A", Target: "C", Properties: EdgeProperties{Weight: 3}},
316 {Source: "A", Target: "F", Properties: EdgeProperties{Weight: 2}},
317 {Source: "C", Target: "D", Properties: EdgeProperties{Weight: 4}},
318 {Source: "C", Target: "E", Properties: EdgeProperties{Weight: 1}},
319 {Source: "C", Target: "F", Properties: EdgeProperties{Weight: 2}},
320 {Source: "D", Target: "B", Properties: EdgeProperties{Weight: 1}},
321 {Source: "E", Target: "B", Properties: EdgeProperties{Weight: 2}},
322 {Source: "E", Target: "F", Properties: EdgeProperties{Weight: 3}},
323 {Source: "F", Target: "G", Properties: EdgeProperties{Weight: 5}},
324 {Source: "G", Target: "B", Properties: EdgeProperties{Weight: 2}},
325 },
326 isWeighted: true,
327 sourceHash: "A",
328 targetHash: "B",
329 expectedShortestPath: []string{"A", "C", "E", "B"},
330 },
331 "diamond-shaped graph": {
332 vertices: []string{"A", "B", "C", "D"},
333 edges: []Edge[string]{
334 {Source: "A", Target: "B", Properties: EdgeProperties{Weight: 2}},
335 {Source: "A", Target: "C", Properties: EdgeProperties{Weight: 4}},
336 {Source: "B", Target: "D", Properties: EdgeProperties{Weight: 2}},
337 {Source: "C", Target: "D", Properties: EdgeProperties{Weight: 2}},
338 },
339 isWeighted: true,
340 sourceHash: "A",
341 targetHash: "D",
342 expectedShortestPath: []string{"A", "B", "D"},
343 },
344 "unweighted graph": {
345 vertices: []string{"A", "B", "C", "D", "E", "F", "G"},
346 edges: []Edge[string]{
347 {Source: "A", Target: "B", Properties: EdgeProperties{}},
348 {Source: "A", Target: "C", Properties: EdgeProperties{}},
349 {Source: "B", Target: "D", Properties: EdgeProperties{}},
350 {Source: "C", Target: "F", Properties: EdgeProperties{}},
351 {Source: "D", Target: "G", Properties: EdgeProperties{}},
352 {Source: "E", Target: "G", Properties: EdgeProperties{}},
353 {Source: "F", Target: "E", Properties: EdgeProperties{}},
354 },
355 sourceHash: "A",
356 targetHash: "G",
357 expectedShortestPath: []string{"A", "B", "D", "G"},
358 },
359 "source equal to target": {
360 vertices: []string{"A", "B", "C", "D"},
361 edges: []Edge[string]{
362 {Source: "A", Target: "B", Properties: EdgeProperties{Weight: 2}},
363 {Source: "A", Target: "C", Properties: EdgeProperties{Weight: 4}},
364 {Source: "B", Target: "D", Properties: EdgeProperties{Weight: 2}},
365 {Source: "C", Target: "D", Properties: EdgeProperties{Weight: 2}},
366 },
367 isWeighted: true,
368 sourceHash: "B",
369 targetHash: "B",
370 expectedShortestPath: []string{"B"},
371 },
372 "target not reachable in a disconnected graph": {
373 vertices: []string{"A", "B", "C", "D"},
374 edges: []Edge[string]{
375 {Source: "A", Target: "B", Properties: EdgeProperties{Weight: 2}},
376 {Source: "A", Target: "C", Properties: EdgeProperties{Weight: 4}},
377 },
378 isWeighted: true,
379 sourceHash: "A",
380 targetHash: "D",
381 expectedShortestPath: []string{},
382 shouldFail: true,
383 },
384 }
385
386 for name, test := range tests {
387 graph := New(StringHash)
388 graph.(*undirected[string, string]).traits.IsWeighted = test.isWeighted
389
390 for _, vertex := range test.vertices {
391 _ = graph.AddVertex(vertex)
392 }
393
394 for _, edge := range test.edges {
395 if err := graph.AddEdge(edge.Source, edge.Target, EdgeWeight(edge.Properties.Weight)); err != nil {
396 t.Fatalf("%s: failed to add edge: %s", name, err.Error())
397 }
398 }
399
400 shortestPath, err := ShortestPath(graph, test.sourceHash, test.targetHash)
401
402 if test.shouldFail != (err != nil) {
403 t.Fatalf("%s: error expectancy doesn't match: expected %v, got %v (error: %v)", name, test.shouldFail, (err != nil), err)
404 }
405
406 if len(shortestPath) != len(test.expectedShortestPath) {
407 t.Fatalf("%s: path length expectancy doesn't match: expected %v, got %v", name, len(test.expectedShortestPath), len(shortestPath))
408 }
409
410 for i, expectedVertex := range test.expectedShortestPath {
411 if shortestPath[i] != expectedVertex {
412 t.Errorf("%s: path vertex expectancy doesn't match: expected %v at index %d, got %v", name, expectedVertex, i, shortestPath[i])
413 }
414 }
415 }
416 }
417
418 func TestDirectedStronglyConnectedComponents(t *testing.T) {
419 tests := map[string]struct {
420 vertices []int
421 edges []Edge[int]
422 expectedSCCs [][]int
423 }{
424 "graph with SCCs as on img/scc.svg": {
425 vertices: []int{1, 2, 3, 4, 5, 6, 7, 8},
426 edges: []Edge[int]{
427 {Source: 1, Target: 2},
428 {Source: 2, Target: 3},
429 {Source: 2, Target: 5},
430 {Source: 2, Target: 6},
431 {Source: 3, Target: 4},
432 {Source: 3, Target: 7},
433 {Source: 4, Target: 3},
434 {Source: 4, Target: 8},
435 {Source: 5, Target: 1},
436 {Source: 5, Target: 6},
437 {Source: 6, Target: 7},
438 {Source: 7, Target: 6},
439 {Source: 8, Target: 4},
440 {Source: 8, Target: 7},
441 },
442 expectedSCCs: [][]int{{1, 2, 5}, {3, 4, 8}, {6, 7}},
443 },
444 }
445
446 for name, test := range tests {
447 graph := New(IntHash, Directed())
448
449 for _, vertex := range test.vertices {
450 _ = graph.AddVertex(vertex)
451 }
452
453 for _, edge := range test.edges {
454 if err := graph.AddEdge(edge.Source, edge.Target); err != nil {
455 t.Fatalf("%s: failed to add edge: %s", name, err.Error())
456 }
457 }
458
459 sccs, _ := StronglyConnectedComponents(graph)
460 matchedSCCs := 0
461
462 for _, scc := range sccs {
463 for _, expectedSCC := range test.expectedSCCs {
464 if slicesAreEqual(scc, expectedSCC) {
465 matchedSCCs++
466 }
467 }
468 }
469
470 if matchedSCCs != len(test.expectedSCCs) {
471 t.Errorf("%s: expected SCCs don't match: expected %v, got %v", name, test.expectedSCCs, sccs)
472 }
473 }
474 }
475
476 func TestUndirectedStronglyConnectedComponents(t *testing.T) {
477 tests := map[string]struct {
478 expectedSCCs [][]int
479 shouldFail bool
480 }{
481 "return error": {
482 expectedSCCs: nil,
483 shouldFail: true,
484 },
485 }
486
487 for name, test := range tests {
488 graph := New(IntHash)
489
490 sccs, err := StronglyConnectedComponents(graph)
491
492 if test.shouldFail != (err != nil) {
493 t.Errorf("%s: error expectancy doesn't match: expected %v, got %v (error: %v)", name, test.shouldFail, (err != nil), err)
494 }
495
496 if test.expectedSCCs == nil && sccs != nil {
497 t.Errorf("%s: SCC expectancy doesn't match: expcted %v, got %v", name, test.expectedSCCs, sccs)
498 }
499 }
500 }
501
502 func TestAllPathsBetween(t *testing.T) {
503 type args[K comparable, T any] struct {
504 g Graph[K, T]
505 start K
506 end K
507 }
508 type testCase[K comparable, T any] struct {
509 name string
510 args args[K, T]
511 want [][]K
512 wantErr bool
513 }
514 tests := []testCase[int, int]{
515 {
516 name: "directed",
517 args: args[int, int]{
518 g: func() Graph[int, int] {
519 g := New(IntHash, Directed())
520 for i := 0; i <= 8; i++ {
521 _ = g.AddVertex(i)
522 }
523 _ = g.AddEdge(0, 2)
524 _ = g.AddEdge(1, 0)
525 _ = g.AddEdge(1, 4)
526 _ = g.AddEdge(2, 6)
527 _ = g.AddEdge(3, 1)
528 _ = g.AddEdge(3, 7)
529 _ = g.AddEdge(4, 5)
530 _ = g.AddEdge(5, 2)
531 _ = g.AddEdge(5, 6)
532 _ = g.AddEdge(6, 8)
533 _ = g.AddEdge(7, 4)
534 return g
535 }(),
536 start: 3,
537 end: 6,
538 },
539 want: [][]int{
540 {3, 1, 0, 2, 6},
541 {3, 1, 4, 5, 6},
542 {3, 1, 4, 5, 2, 6},
543 {3, 7, 4, 5, 2, 6},
544 {3, 7, 4, 5, 6},
545 },
546 wantErr: false,
547 },
548 {
549 name: "undirected",
550 args: args[int, int]{
551 g: func() Graph[int, int] {
552 g := New(IntHash)
553 for i := 0; i <= 8; i++ {
554 _ = g.AddVertex(i)
555 }
556 _ = g.AddEdge(0, 1)
557 _ = g.AddEdge(0, 2)
558 _ = g.AddEdge(1, 3)
559 _ = g.AddEdge(1, 4)
560 _ = g.AddEdge(2, 5)
561 _ = g.AddEdge(2, 6)
562 _ = g.AddEdge(3, 7)
563 _ = g.AddEdge(4, 5)
564 _ = g.AddEdge(4, 7)
565 _ = g.AddEdge(5, 6)
566 _ = g.AddEdge(6, 8)
567 return g
568 }(),
569 start: 3,
570 end: 6,
571 },
572 want: [][]int{
573 {3, 1, 0, 2, 6},
574 {3, 1, 0, 2, 5, 6},
575 {3, 1, 4, 5, 6},
576 {3, 1, 4, 5, 2, 6},
577 {3, 7, 4, 5, 2, 6},
578 {3, 7, 4, 5, 6},
579 {3, 7, 4, 1, 0, 2, 6},
580 {3, 7, 4, 1, 0, 2, 5, 6},
581 },
582 wantErr: false,
583 },
584 {
585 name: "undirected (complex)",
586 args: args[int, int]{
587 g: func() Graph[int, int] {
588 g := New(IntHash)
589 for i := 0; i <= 9; i++ {
590 _ = g.AddVertex(i)
591 }
592 _ = g.AddEdge(0, 1)
593 _ = g.AddEdge(0, 2)
594 _ = g.AddEdge(0, 3)
595 _ = g.AddEdge(2, 3)
596 _ = g.AddEdge(2, 6)
597 _ = g.AddEdge(3, 4)
598 _ = g.AddEdge(4, 8)
599 _ = g.AddEdge(5, 6)
600 _ = g.AddEdge(5, 8)
601 _ = g.AddEdge(5, 9)
602 _ = g.AddEdge(6, 7)
603 _ = g.AddEdge(7, 9)
604 _ = g.AddEdge(8, 9)
605 return g
606 }(),
607 start: 0,
608 end: 9,
609 },
610 want: [][]int{
611 {0, 2, 3, 4, 8, 5, 6, 7, 9},
612 {0, 2, 3, 4, 8, 5, 9},
613 {0, 2, 3, 4, 8, 9},
614 {0, 2, 6, 5, 8, 9},
615 {0, 2, 6, 5, 9},
616 {0, 2, 6, 7, 9},
617 {0, 3, 2, 6, 5, 8, 9},
618 {0, 3, 2, 6, 5, 9},
619 {0, 3, 2, 6, 7, 9},
620 {0, 3, 4, 8, 5, 6, 7, 9},
621 {0, 3, 4, 8, 5, 9},
622 {0, 3, 4, 8, 9},
623 },
624 wantErr: false,
625 },
626 }
627 for _, tt := range tests {
628 t.Run(tt.name, func(t *testing.T) {
629 got, err := AllPathsBetween(tt.args.g, tt.args.start, tt.args.end)
630 if (err != nil) != tt.wantErr {
631 t.Errorf("AllPathsBetween() error = %v, wantErr %v", err, tt.wantErr)
632 return
633 }
634
635 toStr := func(s []int) string {
636 var num string
637 for _, n := range s {
638 num = num + string(rune(n))
639 }
640 return num
641 }
642
643 sort.Slice(got, func(i, j int) bool {
644 return toStr(got[i]) < toStr(got[j])
645 })
646
647 sort.Slice(tt.want, func(i, j int) bool {
648 return toStr(tt.want[i]) < toStr(tt.want[j])
649 })
650
651 if !reflect.DeepEqual(got, tt.want) {
652 t.Errorf("AllPathsBetween() got = %v, want %v", got, tt.want)
653 }
654 })
655 }
656 }