File: edge.t

package info (click to toggle)
libgraph-easy-perl 0.71-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 4,284 kB
  • sloc: perl: 24,909; makefile: 2
file content (212 lines) | stat: -rw-r--r-- 5,398 bytes parent folder | download | duplicates (3)
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/usr/bin/perl -w

use Test::More;
use strict;

BEGIN
   {
   plan tests => 43;
   chdir 't' if -d 't';
   use lib '../lib';
   use_ok qw/Graph::Easy::Edge/;
   use_ok qw/Graph::Easy::Edge::Cell/;
   }

can_ok ("Graph::Easy::Edge", qw/
  new
  error
  label
  _cells
  _add_cell
  _clear_cells
  _unplace
  attribute
  undirected
  bidirectional
  has_ports
  flip

  set_attribute
  set_attributes

  group add_to_group
  background
  edge_flow flow port

  start_port end_port
  from to start_at

  to from nodes

  as_ascii
  as_txt
  /);
  
use Graph::Easy::Edge::Cell qw/EDGE_SHORT_E/;
use Graph::Easy;

#############################################################################

# We need a graph to insert the edge into it, so that the edge gets the
# default settings from it. 
# XXX TODO: should we change the above?

my $graph = Graph::Easy->new();

my $edge = Graph::Easy::Edge->new();

$edge->{graph} = $graph;

is (ref($edge), 'Graph::Easy::Edge');

is ($edge->error(), '', 'no error yet');
is ($edge->undirected(), undef, 'not undirected');
is ($edge->bidirectional(), undef, 'not bidiriectional');
is ($edge->has_ports(), 0, 'has no port restrictions');

use_ok ('Graph::Easy::As_txt');

is ($edge->as_txt(), ' --> ', 'default is "-->"');

#############################################################################
# different styles

$edge = Graph::Easy::Edge->new( style => 'double' );
$edge->{graph} = $graph;
is ($edge->as_txt(), ' ==> ', '"==>"');

$edge = Graph::Easy::Edge->new( style => 'dotted' );
$edge->{graph} = $graph;
is ($edge->as_txt(), ' ..> ', '"..>"');

$edge = Graph::Easy::Edge->new( style => 'dashed' );
$edge->{graph} = $graph;
is ($edge->as_txt(), ' - > ', '"- >"');

$edge = Graph::Easy::Edge->new( style => 'wave' );
$edge->{graph} = $graph;
is ($edge->as_txt(), ' ~~> ', '"~~>"');

$edge = Graph::Easy::Edge->new( style => 'dot-dash' );
$edge->{graph} = $graph;
is ($edge->as_txt(), ' .-> ', '".->"');

$edge = Graph::Easy::Edge->new( style => 'double-dash' );
$edge->{graph} = $graph;
is ($edge->as_txt(), ' = > ', '"= >"');

$edge = Graph::Easy::Edge->new( style => 'dot-dot-dash' );
$edge->{graph} = $graph;
is ($edge->as_txt(), ' ..-> ', '"= >"');

$edge = Graph::Easy::Edge->new( style => 'bold' );
$edge->{graph} = $graph;
is ($edge->as_txt(), ' --> { style: bold; } ', ' --> { style: bold; }');

#############################################################################

$edge = Graph::Easy::Edge->new( label => 'train' );
$edge->{graph} = $graph;
is ($edge->as_txt(), ' -- train --> ', ' -- train -->');

#############################################################################
# cells

is (scalar $edge->_cells(), 0, 'no cells');

my $c = Graph::Easy::Edge::Cell->new (
    edge => $edge,
    type => EDGE_SHORT_E,
    x => 1, y => 1,
    after => 0,
    );
is (scalar $edge->_cells(), 1, 'one cell');
my @cells = $edge->_cells();
is ($cells[0], $c, 'added this cell');

my $c_1 = Graph::Easy::Edge::Cell->new (
    edge => $edge,
    type => EDGE_SHORT_E,
    x => 2, y => 1,
    after => $c,
    );
is (scalar $edge->_cells(), 2, 'two cells');
@cells = $edge->_cells();
is ($cells[0], $c, 'first cell stayed');
is ($cells[1], $c_1, 'added after first cell');

$edge->_clear_cells();
is (scalar $edge->_cells(), 0, 'no cells');

#############################################################################
# undirected/bidirectional

is ($edge->undirected(2), 1, 'undirected');
is ($edge->undirected(), 1, 'undirected');
is ($edge->undirected(0), 0, 'not undirected');
is ($edge->bidirectional(2), 1, 'bidiriectional');
is ($edge->bidirectional(), 1, 'bidiriectional');
is ($edge->bidirectional(0), 0, 'not bidiriectional');

#############################################################################
# has_ports()

$edge->set_attribute('start', 'south');
is ($edge->has_ports(), 1, 'has port restrictions');

$edge->set_attribute('end', 'north');
is ($edge->has_ports(), 1, 'has port restrictions');

$edge->del_attribute('start');
is ($edge->has_ports(), 1, 'has port restrictions');

$edge->del_attribute('end');
is ($edge->has_ports(), 0, 'has no port restrictions');

#############################################################################
# port()

$edge->set_attribute('start', 'south');
my @u = $edge->port('start');
is_deeply (\@u, ['south'], "port('start')");

$edge->del_attribute('end');
$edge->del_attribute('start');

#############################################################################
# background()

is ($edge->background(), 'inherit', 'background()');

$graph = Graph::Easy->new();
my ($A,$B); ($A,$B,$edge) = $graph->add_edge('A','B');

my $group = $graph->add_group('G');
$group->add_member($edge);

my $cell = Graph::Easy::Edge::Cell->new( edge => $edge, graph => $graph );

# default group background
is ($cell->background(), '#a0d0ff', 'background() for group member');

$group->set_attribute('background', 'red');
is ($cell->background(), '#a0d0ff', 'background() for group member');

# now has the fill of the group as background
$group->set_attribute('fill', 'green');
is ($cell->background(), '#008000', 'background() for group member');

#############################################################################
# flip()

my $from = $edge->from();
my $to = $edge->to();

$edge->flip();

is ($from, $edge->to(), 'from/to flipped');
is ($to, $edge->from(), 'from/to flipped');