File: re_layout.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 (112 lines) | stat: -rw-r--r-- 2,388 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/perl -w

# test layouts after setting attributes
use Test::More;
use strict;

BEGIN
   {
   plan tests => 12;
   chdir 't' if -d 't';
   use lib '../lib';
   use_ok ("Graph::Easy") or die($@);
   };

can_ok ('Graph::Easy', qw/
  new
  /);

#############################################################################
# setup a graph

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

is (ref($graph), 'Graph::Easy');

is ($graph->error(), '', 'no error yet');

my ($bonn,$berlin,$edge) = $graph->add_edge('Bonn','Berlin');

#############################################################################
# lay out as ascii

my $ascii = $graph->as_ascii();

is ($ascii, <<EOF
+------+     +--------+
| Bonn | --> | Berlin |
+------+     +--------+
EOF
, 'as_ascii');

#############################################################################
# change label of Bonn to be longer

$bonn->set_attribute('label', 'Frankfurt a. Main');

$ascii = $graph->as_ascii();

is ($ascii, <<EOF
+-------------------+     +--------+
| Frankfurt a. Main | --> | Berlin |
+-------------------+     +--------+
EOF
, 'as_ascii');

$bonn->set_attribute('label', 'Frankfurt\n(a. Main)');
$ascii = $graph->as_ascii();

is ($ascii, <<EOF
+-----------+     +--------+
| Frankfurt |     | Berlin |
| (a. Main) | --> |        |
+-----------+     +--------+
EOF
, 'as_ascii');

# Change label of Bonn to be shorter (and one line high, this also tests
# resetting the height of Berlin even though we did not change an attribute
# on Berlin itself:

$bonn->set_attribute('label', 'Frankfurt');

$ascii = $graph->as_ascii();

is ($ascii, <<EOF
+-----------+     +--------+
| Frankfurt | --> | Berlin |
+-----------+     +--------+
EOF
, 'as_ascii');

is ($bonn->{w}, 13, 'w is 13');
is ($bonn->{h}, 3, 'h is 2');

#############################################################################
# change edge label

$edge->set_attribute('label', 'Test');

$ascii = $graph->as_ascii();

is ($ascii, <<EOF
+-----------+  Test   +--------+
| Frankfurt | ------> | Berlin |
+-----------+         +--------+
EOF
, 'as_ascii');

$edge->set_attribute('label', 'Testtest');

$ascii = $graph->as_ascii();

is ($ascii, <<EOF
+-----------+  Testtest   +--------+
| Frankfurt | ----------> | Berlin |
+-----------+             +--------+
EOF
, 'as_ascii');

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