File: copy.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 (140 lines) | stat: -rw-r--r-- 3,694 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
#!/usr/bin/perl -w

# Test the copy() method

use Test::More;
use strict;

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

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

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

check_graph($graph);
my $copy = $graph->copy();
check_graph($copy);

my $bonn = Graph::Easy::Node->new( name => 'Bonn' );
my $berlin = Graph::Easy::Node->new( 'Berlin' );
my $edge = $graph->add_edge ($bonn, $berlin);
my $group = $graph->add_group ('Cities');
is (ref($edge), 'Graph::Easy::Edge', 'add_edge() returns the new edge');
$bonn->set_attribute('color','red');
$edge->set_attribute('fill','blue');
$graph->set_attribute('graph','fill','purple');

check_members($graph);
$copy = $graph->copy();
check_members($copy);

#############################################################################
# settings on the graph object itself

$graph->fatal_errors();
$graph->catch_warnings(1);
$graph->catch_errors(1);
 
check_settings($graph);
$copy = $graph->copy();
check_settings($copy);

#############################################################################
# groups with nodes

$graph = Graph::Easy->new('( Cities [ Bonn ] -> [ Berlin ] )' );
$copy = $graph->copy();

$group = $graph->group('Cities');
is (scalar $group->nodes(), 2, '2 nodesi in original group');

$group = $copy->group('Cities');
is (scalar $group->nodes(), 2, '2 nodes in copied group');

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

sub check_settings
  {
  my $graph = shift;

  is ($graph->{_catch_warnings}, 1, 'catch warnings');
  is ($graph->{_catch_errors}, 1, 'catch errors');
  is ($graph->{fatal_errors}, 1, 'fatal errors');
  }

sub check_members
  {
  my $graph = shift;

#  use Data::Dumper; print Dumper($graph);

  is ($graph->nodes(), 2, '2 nodes added');
  is ($graph->edges(), 1, '1 edge');

  is ($graph->as_txt(), <<EOF
graph { fill: purple; }

[ Bonn ] { color: red; }

( Cities )

[ Bonn ] --> { fill: blue; } [ Berlin ]
EOF
, 'as_txt for 2 nodes');

  is (ref($graph->edge($bonn,$berlin)), 'Graph::Easy::Edge', 'edge from objects');
  is ($graph->edge($berlin,$bonn), undef, 'berlin not connecting to bonn');

  is (ref($graph->edge('Bonn', 'Berlin')), 'Graph::Easy::Edge', 'edge from names');

  my @E = $graph->edges();

  my $en = '';
  for my $e (@E)
    {
    $en .= $e->style() . '.';
    }

  is ($en, 'solid.', 'edges() in list context');

  is( $graph->node('Bonn')->attribute('color'),'red', 'Bonn is red');
  is( $graph->edge('Bonn','Berlin')->attribute('fill'),'blue', 'Bonn->Berlin is blue');
  is( $graph->get_attribute('fill'), 'purple', 'graph is purple');
  }

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

sub check_graph
  {
  my $graph = shift;

#  use Data::Dumper; print Dumper($graph);
  is (ref($graph), 'Graph::Easy');
  is ($graph->error(), '', 'no error yet');
  is ($graph->output_format(), 'html', 'default output format is html');

  is ($graph->timeout(), 5, '5 seconds');
  is ($graph->strict(), 1, 'is strict');
  is ($graph->nodes(), 0, '0 nodes');
  is ($graph->edges(), 0, '0 edges');
  is ($graph->border_attribute('graph'), 'none', 'graph border is none');
  is ($graph->border_attribute('group'), 'dashed', 'group border is dashed 1px black');
  is ($graph->border_attribute('node'), 'solid', 'node border is solid 1px black');

  is (join (',', $graph->edges()), '', '0 edges');

  like ($graph->output(), qr/table/, 'default output worked');
  }