/
EdgeTest.php
111 lines (89 loc) · 2.74 KB
/
EdgeTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
namespace Graphp\Graph\Tests;
use Graphp\Graph\Edge;
use Graphp\Graph\Graph;
use Graphp\Graph\Vertex;
abstract class EdgeTest extends EntityTest
{
/**
* @var Graph
*/
protected $graph;
/**
* @var Vertex
*/
protected $v1;
/**
* @var Vertex
*/
protected $v2;
/**
* @var Edge
*/
protected $edge;
abstract protected function createEdge(array $attributes = array());
/**
* @return Edge
*/
abstract protected function createEdgeLoop();
public function setUp()
{
$this->graph = new Graph();
$this->v1 = $this->graph->createVertex();
$this->v2 = $this->graph->createVertex();
$this->edge = $this->createEdge();
}
public function testEdgeConstructorDefaultHasNoAttributes()
{
$this->assertNull($this->edge->getAttribute('hello'));
$this->assertEquals('default', $this->edge->getAttribute('hello', 'default'));
$this->assertEquals(array(), $this->edge->getAttributes());
}
public function testEdgeConstructorWithAttributeReturnsAttributes()
{
$edge = $this->createEdge(array('hello' => 'wörld'));
$this->assertEquals('wörld', $edge->getAttribute('hello'));
$this->assertEquals(array('hello' => 'wörld'), $edge->getAttributes());
}
public function testEdgeVertices()
{
$this->assertEquals(array($this->v1, $this->v2), $this->edge->getVertices()->getVector());
$this->assertSame($this->graph, $this->edge->getGraph());
}
public function testEdgeStartVertex()
{
$this->assertTrue($this->edge->hasVertexStart($this->v1));
$this->assertTrue($this->edge->hasVertexTarget($this->v2));
$v3 = $this->graph->createVertex();
$this->assertFalse($this->edge->hasVertexStart($v3));
$this->assertFalse($this->edge->hasVertexTarget($v3));
}
/**
* @expectedException InvalidArgumentException
*/
public function testEdgeFromInvalid()
{
$v3 = $this->graph->createVertex();
$this->edge->getVertexFromTo($v3);
}
/**
* @expectedException InvalidArgumentException
*/
public function testEdgeToInvalid()
{
$v3 = $this->graph->createVertex();
$this->edge->getVertexToFrom($v3);
}
public function testLoop()
{
$edge = $this->createEdgeLoop();
$this->assertTrue($edge->isLoop());
$this->assertEquals(array($this->v1, $this->v1), $edge->getVertices()->getVector());
$this->assertSame($this->v1, $edge->getVertexFromTo($this->v1));
$this->assertSame($this->v1, $edge->getVertexToFrom($this->v1));
}
protected function createEntity()
{
return $this->createEdge();
}
}