File: nesting.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 (114 lines) | stat: -rw-r--r-- 2,982 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
#!/usr/bin/perl -w

# Test nesting of groups

use Test::More;
use strict;

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

#############################################################################
# $group->add_member($inner);

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

my $group = $graph->add_group('Outer');

is (ref($group), 'Graph::Easy::Group');
is ($group->error(), '', 'no error yet');

my $inner = $graph->add_group('Inner');
$group->add_member($inner);

check_groups($group,$inner);

#############################################################################
# groups_within():

is ($graph->groups_within(), 2, '2 groups');
is ($graph->groups_within(-1), 2, '2 groups');
is ($graph->groups_within(0), 1, '1 group in outer');
is ($graph->groups_within(1), 2, '2 groups in outer+inner');
is ($graph->groups_within(2), 2, 'no more groups');

#############################################################################
# $inner->add_to_group($group);

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

$group = $graph->add_group('Outer');

is (ref($group), 'Graph::Easy::Group');
is ($group->error(), '', 'no error yet');

$inner = $graph->add_group('Inner');

$inner->add_to_group($group);

check_groups($group,$inner);

#############################################################################
# groups_within():

my $inner_2 = $graph->add_group('Inner 2');
my $inner_3 = $graph->add_group('Inner 3');

# Level		Groups			Sum
#  0:		Outer			1
#  1:		Inner     Inner 3	3
#  2:		Inner 2			4

$inner_2->add_to_group($inner);
$inner_3->add_to_group($group);

is ($graph->groups_within(), 4, '4 groups');
is ($graph->groups_within(-1), 4, '4 groups');
is ($graph->groups_within(0), 1, '1 group in outer');
is ($graph->groups_within(1), 3, '3 groups in outer+inner');
is ($graph->groups_within(2), 4, '4 groups in total');

# also test calling add_group() with a scalar on another group:
my $inner_4 = $group->add_group('Inner 4');

# Level		Groups					Sum
#  0:		Outer					1
#  1:		Inner     Inner 3	Inner 4		4
#  2:		Inner 2					5

is ($graph->groups_within(), 5, '5 groups');
is ($graph->groups_within(-1), 5, '5 groups');
is ($graph->groups_within(0), 1, '1 group in outer');
is ($graph->groups_within(1), 4, '4 groups in outer+inner');
is ($graph->groups_within(2), 5, '5 groups in total');

# all tests done
1;

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

sub check_groups
  {
  my ($group,$inner) = @_;

  is ($inner->{group}, $group, 'inner is in outer');

  my @groups = $group->groups();

  is (@groups, 1, 'one group in outer');
  is ($groups[0], $inner, 'and it is "Inner"');

  @groups = $inner->groups();

  is (@groups, 0, 'no group in Inner');
 
  is ($inner->attribute('group'), 'Outer', 'attribute("group")');
  is ($group->attribute('group'), '', 'attribute("group")');
  }