1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use GGGGino\WarehousePath\Entity\Corridor; |
4
|
|
|
use GGGGino\WarehousePath\Entity\Location; |
5
|
|
|
use GGGGino\WarehousePath\Entity\Place; |
6
|
|
|
use GGGGino\WarehousePath\Entity\Wall; |
7
|
|
|
use GGGGino\WarehousePath\Warehouse; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
|
10
|
|
|
final class WarehouseTreeTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var Warehouse |
14
|
|
|
*/ |
15
|
|
|
protected $warehouse; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Simple warehouse structure |
19
|
|
|
* Lx = Location |
20
|
|
|
* Wx = Wall |
21
|
|
|
* Cx = Corridor |
22
|
|
|
* |
23
|
|
|
* L1|W1|L6 |
24
|
|
|
* L2|W2|L5 |
25
|
|
|
* L3|C1|L4 |
26
|
|
|
*/ |
27
|
|
|
protected function setUp() |
28
|
|
|
{ |
29
|
|
|
$loc1 = new Location('L1'); |
30
|
|
|
$loc2 = new Location('L2'); |
31
|
|
|
$loc3 = new Location('L3'); |
32
|
|
|
$loc4 = new Location('L4'); |
33
|
|
|
$loc5 = new Location('L5'); |
34
|
|
|
$loc6 = new Location('L6'); |
35
|
|
|
$loc7 = new Location('L7'); |
36
|
|
|
$loc8 = new Location('L8'); |
37
|
|
|
$corr1 = new Corridor('C1'); |
38
|
|
|
$wall1 = new Wall('W1'); |
39
|
|
|
$wall2 = new Wall('W2'); |
40
|
|
|
|
41
|
|
|
$loc1->setRightRef($wall1); |
42
|
|
|
$loc1->setBottomRef($loc2); |
43
|
|
|
|
44
|
|
|
$loc2->setRightRef($wall2); |
45
|
|
|
$loc2->setBottomRef($loc3); |
46
|
|
|
|
47
|
|
|
$loc3->setRightRef($corr1); |
48
|
|
|
|
49
|
|
|
$wall1->setBottomRef($wall2); |
50
|
|
|
$wall1->setRightRef($loc6); |
51
|
|
|
|
52
|
|
|
$wall2->setBottomRef($corr1); |
53
|
|
|
$wall2->setRightRef($loc5); |
54
|
|
|
|
55
|
|
|
$corr1->setRightRef($loc4); |
56
|
|
|
$loc6->setBottomRef($loc5); |
57
|
|
|
$loc6->setRightRef($loc7); |
58
|
|
|
$loc5->setBottomRef($loc4); |
59
|
|
|
$loc5->setRightRef($loc8); |
60
|
|
|
|
61
|
|
|
$loc7->setBottomRef($loc8); |
62
|
|
|
|
63
|
|
|
$arrayPlaces = array($loc1, $loc2, $loc3, $loc4, $loc5, $loc6, $loc7, $loc8, $corr1, $wall1, $wall2); |
64
|
|
|
|
65
|
|
|
$this->warehouse = Warehouse::createFromTree($arrayPlaces); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Test instance |
70
|
|
|
*/ |
71
|
|
|
public function testConstructor(): void |
72
|
|
|
{ |
73
|
|
|
$this->assertInstanceOf(Warehouse::class, $this->warehouse); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function testPath(): void |
77
|
|
|
{ |
78
|
|
|
/** @var Place $start */ |
79
|
|
|
$start = $this->warehouse->getPlaces()[0]; |
80
|
|
|
/** @var Place $end */ |
81
|
|
|
$end = $this->warehouse->getPlaces()[4]; |
82
|
|
|
|
83
|
|
|
$this->warehouse->getPath($start, $end); |
84
|
|
|
$this->assertEquals(7, $end->getCurrentWeight()); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function testPath2(): void |
88
|
|
|
{ |
89
|
|
|
/** @var Place $start */ |
90
|
|
|
$start = $this->warehouse->getPlaces()[0]; |
91
|
|
|
/** @var Place $end */ |
92
|
|
|
$end = $this->warehouse->getPlaces()[6]; |
93
|
|
|
|
94
|
|
|
$this->warehouse->getPath($start, $end); |
95
|
|
|
$this->assertEquals(9, $end->getCurrentWeight()); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function testPrintMatrix(): void |
99
|
|
|
{ |
100
|
|
|
/** @var Place[][] $matrix */ |
101
|
|
|
$matrix = $this->warehouse->createMatrix(); |
102
|
|
|
$this->assertEquals(3, count($matrix)); |
103
|
|
|
$this->assertEquals(4, count($matrix[0])); |
104
|
|
|
} |
105
|
|
|
} |