|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use GGGGino\WarehousePath\Breadcrumb\FastBreadthFirstBreadcrumb; |
|
4
|
|
|
use GGGGino\WarehousePath\Calculator\FastCalculator; |
|
5
|
|
|
use GGGGino\WarehousePath\Entity\Place; |
|
6
|
|
|
use GGGGino\WarehousePath\Parser\JsonMatrixParser; |
|
7
|
|
|
use GGGGino\WarehousePath\PlacesCollector; |
|
8
|
|
|
use GGGGino\WarehousePath\Warehouse; |
|
9
|
|
|
use PHPUnit\Framework\TestCase; |
|
10
|
|
|
|
|
11
|
|
|
final class WarehouseTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* |
|
15
|
|
|
*/ |
|
16
|
|
|
public function testTransformToTreeConstructor(): void |
|
17
|
|
|
{ |
|
18
|
|
|
/** @var Warehouse $testMatrix */ |
|
19
|
|
|
$testMatrix = Warehouse::createFromJson(getcwd() . "/resources/simpleWarehouse.json"); |
|
20
|
|
|
|
|
21
|
|
|
$calculatedArray = $testMatrix->getPlacesCollector()->getPlaces(); |
|
22
|
|
|
|
|
23
|
|
|
/** @var Place $nodeStart */ |
|
24
|
|
|
$nodeStart = $calculatedArray[4]; |
|
25
|
|
|
/** @var Place $nodeEnd */ |
|
26
|
|
|
$nodeEnd = $calculatedArray[20]; |
|
27
|
|
|
|
|
28
|
|
|
$this->assertEquals('04', $nodeStart->getName()); |
|
29
|
|
|
$this->assertEquals('26', $nodeEnd->getName()); |
|
30
|
|
|
$testMatrix->getPath($nodeStart, $nodeEnd); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* |
|
35
|
|
|
*/ |
|
36
|
|
|
public function testBigConstructor(): void |
|
37
|
|
|
{ |
|
38
|
|
|
/** @var Warehouse $testMatrix */ |
|
39
|
|
|
$testMatrix = Warehouse::createFromJson(getcwd() . "/resources/biggerWarehouse.json"); |
|
40
|
|
|
|
|
41
|
|
|
$calculatedArray = $testMatrix->getPlacesCollector()->getPlaces(); |
|
42
|
|
|
|
|
43
|
|
|
/** @var Place $nodeStart */ |
|
44
|
|
|
$nodeStart = $calculatedArray[4]; |
|
45
|
|
|
/** @var Place $nodeEnd */ |
|
46
|
|
|
$nodeEnd = $calculatedArray[20]; |
|
47
|
|
|
|
|
48
|
|
|
$this->assertEquals('04', $nodeStart->getName()); |
|
49
|
|
|
$this->assertEquals('22', $nodeEnd->getName()); |
|
50
|
|
|
$testMatrix->getPath($nodeStart, $nodeEnd); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* |
|
55
|
|
|
*/ |
|
56
|
|
|
public function testBigMultiplePath(): void |
|
57
|
|
|
{ |
|
58
|
|
|
/** @var Warehouse $testMatrix */ |
|
59
|
|
|
$testMatrix = Warehouse::createFromJson(getcwd() . "/resources/biggerWarehouse.json"); |
|
60
|
|
|
|
|
61
|
|
|
$calculatedArray = $testMatrix->getPlacesCollector()->getPlaces(); |
|
62
|
|
|
|
|
63
|
|
|
/** @var Place[] $nodes */ |
|
64
|
|
|
$nodes = array( |
|
65
|
|
|
$calculatedArray[4], |
|
66
|
|
|
$calculatedArray[20], |
|
67
|
|
|
$calculatedArray[48], |
|
68
|
|
|
$calculatedArray[62], |
|
69
|
|
|
$calculatedArray[10], |
|
70
|
|
|
$calculatedArray[49], |
|
71
|
|
|
$calculatedArray[14], |
|
72
|
|
|
$calculatedArray[100], |
|
73
|
|
|
$calculatedArray[120], |
|
74
|
|
|
$calculatedArray[122], |
|
75
|
|
|
$calculatedArray[60], |
|
76
|
|
|
$calculatedArray[15] |
|
77
|
|
|
); |
|
78
|
|
|
|
|
79
|
|
|
$matrix = $testMatrix->getMultiplePath($nodes); |
|
80
|
|
|
$this->assertEquals(12, count($matrix)); |
|
81
|
|
|
|
|
82
|
|
|
$testMatrix->setPathCalculator(new FastCalculator()); |
|
83
|
|
|
|
|
84
|
|
|
$arrayOrdered = $testMatrix->calculate($nodes, $matrix); |
|
85
|
|
|
$this->assertEquals(12, count($arrayOrdered)); |
|
86
|
|
|
|
|
87
|
|
|
$resultExpectedJoined = "04-2, 15-1, 54-2, 53-1, 11-1, 111-1, 133-1, 135-1, 68-2, 22-100, 66-100, 16-100"; |
|
88
|
|
|
$resultActualJoined = join(", ", $arrayOrdered); |
|
89
|
|
|
$this->assertEquals($resultExpectedJoined, $resultActualJoined); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* |
|
94
|
|
|
*/ |
|
95
|
|
|
public function testBigFastMultiplePath(): void |
|
96
|
|
|
{ |
|
97
|
|
|
$path = getcwd() . "/resources/biggerWarehouse.json"; |
|
98
|
|
|
$placesCollector = new PlacesCollector(); |
|
99
|
|
|
$placesCollector->addBasePlaceTypes(); |
|
100
|
|
|
|
|
101
|
|
|
$breadcrumbBuilder = new FastBreadthFirstBreadcrumb($placesCollector); |
|
102
|
|
|
|
|
103
|
|
|
$wm = new JsonMatrixParser($path, $placesCollector); |
|
104
|
|
|
|
|
105
|
|
|
$wh = new Warehouse($placesCollector, $wm, $breadcrumbBuilder); |
|
106
|
|
|
$wh->getPlacesCollector()->setPlaces($wm->parse()); |
|
107
|
|
|
|
|
108
|
|
|
$calculatedArray = $wh->getPlacesCollector()->getPlaces(); |
|
109
|
|
|
|
|
110
|
|
|
/** @var Place[] $nodes */ |
|
111
|
|
|
$nodes = array( |
|
112
|
|
|
$calculatedArray[4], |
|
113
|
|
|
$calculatedArray[20], |
|
114
|
|
|
$calculatedArray[48], |
|
115
|
|
|
$calculatedArray[62], |
|
116
|
|
|
$calculatedArray[10], |
|
117
|
|
|
$calculatedArray[49], |
|
118
|
|
|
$calculatedArray[14], |
|
119
|
|
|
$calculatedArray[100], |
|
120
|
|
|
$calculatedArray[120], |
|
121
|
|
|
$calculatedArray[122], |
|
122
|
|
|
$calculatedArray[60], |
|
123
|
|
|
$calculatedArray[15] |
|
124
|
|
|
); |
|
125
|
|
|
|
|
126
|
|
|
$matrix = $wh->getMultiplePath($nodes); |
|
127
|
|
|
$this->assertEquals(12, count($matrix)); |
|
128
|
|
|
|
|
129
|
|
|
$wh->setPathCalculator(new FastCalculator()); |
|
130
|
|
|
|
|
131
|
|
|
$arrayOrdered = $wh->calculate($nodes, $matrix); |
|
132
|
|
|
$this->assertEquals(12, count($arrayOrdered)); |
|
133
|
|
|
|
|
134
|
|
|
$resultExpectedJoined = "04-2, 15-1, 54-2, 53-1, 11-1, 111-1, 133-1, 135-1, 68-2, 22-100, 66-100, 16-100"; |
|
135
|
|
|
$resultActualJoined = join(", ", $arrayOrdered); |
|
136
|
|
|
$this->assertEquals($resultExpectedJoined, $resultActualJoined); |
|
137
|
|
|
} |
|
138
|
|
|
} |