|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the prooph/php-ddd-cargo-sample. |
|
4
|
|
|
* (c) Alexander Miertsch <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
* |
|
9
|
|
|
* Date: 29.03.14 - 20:39 |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace CodelinerTest\GraphTraversalService; |
|
13
|
|
|
|
|
14
|
|
|
use Codeliner\GraphTraversalBackend\GraphTraversalService; |
|
15
|
|
|
|
|
16
|
|
|
class GraphTraversalServiceTest extends \PHPUnit_Framework_TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @test |
|
20
|
|
|
*/ |
|
21
|
|
|
public function it_finds_a_list_of_transit_paths() |
|
22
|
|
|
{ |
|
23
|
|
|
$routes = array( |
|
24
|
|
|
array( |
|
25
|
|
|
'origin' => 'DEHAM', |
|
26
|
|
|
'destination' => 'USNYC', |
|
27
|
|
|
'duration' => 10, |
|
28
|
|
|
'stops' => array( |
|
29
|
|
|
'NLRTM' => 1, |
|
30
|
|
|
'SESTO' => 2 |
|
31
|
|
|
) |
|
32
|
|
|
) |
|
33
|
|
|
); |
|
34
|
|
|
|
|
35
|
|
|
$graphTraversalService = new GraphTraversalService($routes); |
|
36
|
|
|
|
|
37
|
|
|
$transitPaths = $graphTraversalService->findShortestPath('DEHAM', 'USNYC'); |
|
38
|
|
|
|
|
39
|
|
|
$this->assertEquals(1, count($transitPaths)); |
|
40
|
|
|
|
|
41
|
|
|
$transitPath = $transitPaths[0]; |
|
42
|
|
|
|
|
43
|
|
|
$this->assertInstanceOf('Codeliner\GraphTraversalBackend\Dto\TransitPathDto', $transitPath); |
|
44
|
|
|
|
|
45
|
|
|
$edges = $transitPath->getEdges(); |
|
46
|
|
|
|
|
47
|
|
|
$this->assertEquals(3, count($edges)); |
|
48
|
|
|
|
|
49
|
|
|
$this->assertInstanceOf('Codeliner\GraphTraversalBackend\Dto\EdgeDto', $edges[0]); |
|
50
|
|
|
|
|
51
|
|
|
$this->assertEquals('DEHAM', $edges[0]->getFromUnLocode()); |
|
52
|
|
|
$this->assertEquals('NLRTM', $edges[0]->getToUnLocode()); |
|
53
|
|
|
|
|
54
|
|
|
$now = new \DateTime(); |
|
55
|
|
|
$fromDateFirstEdge = new \DateTime($edges[0]->getFromDate()); |
|
56
|
|
|
$toDateFirstEdge = new \DateTime($edges[0]->getToDate()); |
|
57
|
|
|
|
|
58
|
|
|
$this->assertGreaterThan($now->getTimestamp(), $fromDateFirstEdge->getTimestamp()); |
|
59
|
|
|
$this->assertGreaterThan($fromDateFirstEdge->getTimestamp(), $toDateFirstEdge->getTimestamp()); |
|
60
|
|
|
|
|
61
|
|
|
$this->assertEquals('NLRTM', $edges[1]->getFromUnLocode()); |
|
62
|
|
|
$this->assertEquals('SESTO', $edges[1]->getToUnLocode()); |
|
63
|
|
|
|
|
64
|
|
|
$fromDateSecondEdge = new \DateTime($edges[1]->getFromDate()); |
|
65
|
|
|
$toDateSecondEdge = new \DateTime($edges[1]->getToDate()); |
|
66
|
|
|
|
|
67
|
|
|
$this->assertGreaterThan($toDateFirstEdge->getTimestamp(), $fromDateSecondEdge->getTimestamp()); |
|
68
|
|
|
$this->assertGreaterThan($fromDateSecondEdge->getTimestamp(), $toDateSecondEdge->getTimestamp()); |
|
69
|
|
|
|
|
70
|
|
|
$this->assertEquals('SESTO', $edges[2]->getFromUnLocode()); |
|
71
|
|
|
$this->assertEquals('USNYC', $edges[2]->getToUnLocode()); |
|
72
|
|
|
|
|
73
|
|
|
$fromDateThirdEdge = new \DateTime($edges[2]->getFromDate()); |
|
74
|
|
|
$toDateThirdEdge = new \DateTime($edges[2]->getToDate()); |
|
75
|
|
|
|
|
76
|
|
|
$this->assertGreaterThan($toDateSecondEdge->getTimestamp(), $fromDateThirdEdge->getTimestamp()); |
|
77
|
|
|
$this->assertGreaterThan($fromDateThirdEdge->getTimestamp(), $toDateThirdEdge->getTimestamp()); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|