1#!/usr/bin/perl -w
2
3# test nodes with more than one cell
4
5use Test::More;
6use strict;
7
8BEGIN
9   {
10   plan tests => 30;
11   chdir 't' if -d 't';
12   use lib '../lib';
13   use_ok ("Graph::Easy::Node") or die($@);
14   use_ok ("Graph::Easy") or die($@);
15   };
16
17can_ok ("Graph::Easy::Node", qw/
18  new
19  /);
20
21#############################################################################
22
23my $node = Graph::Easy::Node->new();
24
25is (ref($node), 'Graph::Easy::Node');
26
27is ($node->error(), '', 'no error yet');
28
29is ($node->connections(), 0, 'no connections yet');
30
31my $other = Graph::Easy::Node->new();
32
33#############################################################################
34# connections() tests
35
36my $graph = Graph::Easy->new( );
37
38$other = Graph::Easy::Node->new( 'Name' );
39$graph->add_edge ($node, $other);
40
41is ($node->connections(), 1, 'one connection');
42
43#############################################################################
44# grow tests
45
46for (1..4)
47  {
48  my $o = Graph::Easy::Node->new( "Name $_" );
49  $graph->add_edge ($node, $o);
50  }
51
52is ($node->connections(), 5, '5 connections');
53
54$node->_grow();
55
56is ($node->connections(), 5, '5 connections');
57is ($node->columns(), 1, '1 column');
58is ($node->rows(), 3, '3 rows');
59is ($node->is_multicelled(), 1, 'is multicelled');
60
61#############################################################################
62# edges_to() tests
63
64# this will delete the old Graph::Easy object in graph, and clean out
65# the refs in the nodes/edges. Thus $node will have {edges} == undef.
66$graph = Graph::Easy->new();
67
68is ($node->{edges}, undef, 'cleanup worked');
69
70$other = Graph::Easy::Node->new( "other" );
71my @E;
72for (1..5)
73  {
74  push @E, scalar $graph->add_edge ($node, $other);
75  }
76
77@E = sort { $a->{id} <=> $b->{id} } @E;
78
79is ($node->connections(), 5, '5 connections');
80is (scalar $node->edges_to($other), 5, '5 edges from node to other');
81
82my @E2 = $node->edges_to($other);
83@E2 = sort { $a->{id} <=> $b->{id} } @E2;
84
85for (1..5)
86  {
87  is ($E[$_], $E2[$_], 'edges_to() worked');
88  }
89
90my @suc = $node->successors();
91
92is (scalar @suc, 1, 'one successor');
93is ($suc[0], $other, 'one successor');
94
95#use Data::Dumper; print Dumper(\@suc);
96
97#############################################################################
98# node placement (multi-cell)
99
100my $cells = { };
101my $parent = { cells => $cells };
102
103is ($node->_do_place(1,1,$parent), 1, 'node can be placed');
104
105is (scalar keys %$cells, 3, '3 entries (3 rows)');
106is ($cells->{"1,1"}, $node, 'node was really placed');
107my $filler = $cells->{"1,2"};
108is (ref($filler), 'Graph::Easy::Node::Cell', 'filler cell');
109is ($filler->node(), $node, 'filler associated with node');
110
111is ($node->_do_place(1,1,$parent), 0, 'node cannot be placed again');
112is ($cells->{"1,1"}, $node, 'node still there placed');
113is (scalar keys %$cells, 3, 'still three entries');
114
115
116