1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Mado\QueryBundle\Component\Meta\Dijkstra; |
4
|
|
|
use PHPUnit\Framework\TestCase as TestCase; |
5
|
|
|
|
6
|
|
|
class DijkstraTest extends TestCase |
7
|
|
|
{ |
8
|
|
View Code Duplication |
public function testFindShortestPath() |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
$this->samepleJson = [ |
|
|
|
|
11
|
|
|
"AppBundle\\Entity\\a" => [ |
12
|
|
|
"relations" => [ |
13
|
|
|
"item" => "AppBundle\\Entity\\Fizz", |
14
|
|
|
] |
15
|
|
|
], |
16
|
|
|
"AppBundle\\Entity\\mood" => [ |
17
|
|
|
"relations" => [ |
18
|
|
|
"item" => "AppBundle\\Entity\\b", |
19
|
|
|
] |
20
|
|
|
], |
21
|
|
|
"AppBundle\\Entity\\Fizz" => [ |
22
|
|
|
"relations" => [ |
23
|
|
|
"item" => "AppBundle\\Entity\\mood", |
24
|
|
|
"item" => "AppBundle\\Entity\\b", |
25
|
|
|
] |
26
|
|
|
], |
27
|
|
|
"AppBundle\\Entity\\b" => [ |
28
|
|
|
"relations" => [ |
29
|
|
|
"item" => "AppBundle\\Entity\\Fizz", |
30
|
|
|
"icdsatem" => "AppBundle\\Entity\\a", |
31
|
|
|
] |
32
|
|
|
], |
33
|
|
|
]; |
34
|
|
|
|
35
|
|
|
$dijkstra = new Dijkstra(); |
36
|
|
|
$dijkstra->setMap($this->samepleJson); |
37
|
|
|
|
38
|
|
|
$paths = $dijkstra->shortestPaths( |
39
|
|
|
'AppBundle\\Entity\\a', |
40
|
|
|
'AppBundle\\Entity\\b' |
41
|
|
|
); |
42
|
|
|
|
43
|
|
|
$this->assertEquals( |
44
|
|
|
[[ |
45
|
|
|
'AppBundle\\Entity\\a', |
46
|
|
|
'AppBundle\\Entity\\Fizz', |
47
|
|
|
'AppBundle\\Entity\\b', |
48
|
|
|
]], |
49
|
|
|
$paths |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
View Code Duplication |
public function testFindAlternativePaths() |
|
|
|
|
54
|
|
|
{ |
55
|
|
|
$this->samepleJson = [ |
|
|
|
|
56
|
|
|
"AppBundle\\Entity\\a" => [ |
57
|
|
|
"relations" => [ |
58
|
|
|
"item" => "AppBundle\\Entity\\Fizz", |
59
|
|
|
] |
60
|
|
|
], |
61
|
|
|
"AppBundle\\Entity\\mood" => [ |
62
|
|
|
"relations" => [ |
63
|
|
|
"item" => "AppBundle\\Entity\\b", |
64
|
|
|
] |
65
|
|
|
], |
66
|
|
|
"AppBundle\\Entity\\Fizz" => [ |
67
|
|
|
"relations" => [ |
68
|
|
|
"item" => "AppBundle\\Entity\\mood", |
69
|
|
|
"item" => "AppBundle\\Entity\\b", |
70
|
|
|
] |
71
|
|
|
], |
72
|
|
|
"AppBundle\\Entity\\b" => [ |
73
|
|
|
"relations" => [ |
74
|
|
|
"item" => "AppBundle\\Entity\\Fizz", |
75
|
|
|
"icdsatem" => "AppBundle\\Entity\\a", |
76
|
|
|
] |
77
|
|
|
], |
78
|
|
|
]; |
79
|
|
|
|
80
|
|
|
$dijkstra = new Dijkstra(); |
81
|
|
|
$dijkstra->setMap($this->samepleJson); |
82
|
|
|
|
83
|
|
|
$paths = $dijkstra->shortestPaths( |
84
|
|
|
'AppBundle\\Entity\\a', |
85
|
|
|
'AppBundle\\Entity\\b', |
86
|
|
|
$excluded = [ |
87
|
|
|
'AppBundle\\Entity\\mood', |
88
|
|
|
] |
89
|
|
|
); |
90
|
|
|
|
91
|
|
|
$this->assertEquals( |
92
|
|
|
[ |
93
|
|
|
'AppBundle\\Entity\\a', |
94
|
|
|
'AppBundle\\Entity\\Fizz', |
95
|
|
|
'AppBundle\\Entity\\b', |
96
|
|
|
], |
97
|
|
|
$paths[0] |
98
|
|
|
); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.