|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @file |
|
5
|
|
|
* Grafizzi\Graph\Tests\IG05Test: a component of the Grafizzi library. |
|
6
|
|
|
* |
|
7
|
|
|
* (c) 2012 Frédéric G. MARAND <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* Grafizzi is free software: you can redistribute it and/or modify it under the |
|
10
|
|
|
* terms of the GNU Lesser General Public License as published by the Free |
|
11
|
|
|
* Software Foundation, either version 3 of the License, or (at your option) any |
|
12
|
|
|
* later version. |
|
13
|
|
|
* |
|
14
|
|
|
* Grafizzi is distributed in the hope that it will be useful, but WITHOUT ANY |
|
15
|
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
|
16
|
|
|
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
|
17
|
|
|
* details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
|
20
|
|
|
* along with Grafizzi, in the COPYING.LESSER.txt file. If not, see |
|
21
|
|
|
* <http://www.gnu.org/licenses/> |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
namespace Grafizzi\Graph\Tests; |
|
25
|
|
|
|
|
26
|
|
|
use Grafizzi\Graph\Attribute; |
|
27
|
|
|
use Grafizzi\Graph\Edge; |
|
28
|
|
|
use Grafizzi\Graph\Node; |
|
29
|
|
|
|
|
30
|
|
|
require 'vendor/autoload.php'; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* A recreation of Image_GraphViz test5.phpt |
|
34
|
|
|
* |
|
35
|
|
|
* Image_GraphViz version author: Philippe Jausions <[email protected]> |
|
36
|
|
|
* |
|
37
|
|
|
* Test 5: "Unit test for Graph with polygonal shape" |
|
38
|
|
|
* |
|
39
|
|
|
* "Graph definition taken from GraphViz documentation" |
|
40
|
|
|
*/ |
|
41
|
|
|
class IG05Test extends BaseGraphTest { |
|
42
|
|
|
|
|
43
|
|
|
public function setUp() : void { |
|
44
|
|
|
parent::setUpExtended(); |
|
|
|
|
|
|
45
|
|
|
$this->Graph->setDirected(true); |
|
46
|
|
|
$this->Graph->addChild($a = new Node($this->dic, 'a', array( |
|
47
|
|
|
new Attribute($this->dic, 'shape', 'polygon'), |
|
48
|
|
|
new Attribute($this->dic, 'sides', 5), |
|
49
|
|
|
new Attribute($this->dic, 'peripheries', 3), |
|
50
|
|
|
new Attribute($this->dic, 'color', 'lightblue'), |
|
51
|
|
|
new Attribute($this->dic, 'style', 'filled'), |
|
52
|
|
|
))); |
|
53
|
|
|
|
|
54
|
|
|
// TODO : support automatic (undeclared) nodes in edges, to remove $b |
|
55
|
|
|
$this->Graph->addChild($b = new Node($this->dic, 'b', Node::implicit())); |
|
56
|
|
|
$this->Graph->addChild($c = new Node($this->dic, 'c', array( |
|
57
|
|
|
new Attribute($this->dic, 'shape', 'polygon'), |
|
58
|
|
|
new Attribute($this->dic, 'sides', 4), |
|
59
|
|
|
new Attribute($this->dic, 'skew', .4), |
|
60
|
|
|
new Attribute($this->dic, 'label', 'hello world'), |
|
61
|
|
|
))); |
|
62
|
|
|
$this->Graph->addChild($d = new Node($this->dic, 'd', array( |
|
63
|
|
|
new Attribute($this->dic, 'shape', 'invtriangle'), |
|
64
|
|
|
))); |
|
65
|
|
|
$this->Graph->addChild($e = new Node($this->dic, 'e', array( |
|
66
|
|
|
new Attribute($this->dic, 'shape', 'polygon'), |
|
67
|
|
|
new Attribute($this->dic, 'sides', 4), |
|
68
|
|
|
new Attribute($this->dic, 'distortion', .7), |
|
69
|
|
|
))); |
|
70
|
|
|
$this->Graph->addChild(new Edge($this->dic, $a, $b)); |
|
71
|
|
|
$this->Graph->addChild(new Edge($this->dic, $b, $c)); |
|
72
|
|
|
$this->Graph->addChild(new Edge($this->dic, $b, $d)); |
|
73
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Tests Graph->build() |
|
78
|
|
|
*/ |
|
79
|
|
|
public function testBuild() { |
|
80
|
|
|
$expected = <<<EOT |
|
81
|
|
|
digraph G { |
|
82
|
|
|
a [ shape=polygon, sides=5, peripheries=3, color=lightblue, style=filled ]; |
|
83
|
|
|
c [ shape=polygon, sides=4, skew=0.4, label="hello world" ]; |
|
84
|
|
|
d [ shape=invtriangle ]; |
|
85
|
|
|
e [ shape=polygon, sides=4, distortion=0.7 ]; |
|
86
|
|
|
a -> b; |
|
87
|
|
|
b -> c; |
|
88
|
|
|
b -> d; |
|
89
|
|
|
} /* /digraph G */ |
|
90
|
|
|
|
|
91
|
|
|
EOT; |
|
92
|
|
|
$this->check($expected, "Image_GraphViz test 5 passed."); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.