File: cluster.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 (55 lines) | stat: -rw-r--r-- 1,454 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
#!/usr/bin/perl -w

use Test::More;
use strict;

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

#############################################################################
# basic tests

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

my ($first, $second, $edge) = $graph->add_edge('first', 'second');

$second->set_attribute('origin', $first->{name});

is (join(",", $second->offset()), '0,0', 'offset is 0,0');
is ($second->origin(), $first, 'origin is $first');

#############################################################################
# graph tests
# node placement (clustered)

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

$first = $graph->add_node('A');
$second = $graph->add_node('B');

$second->relative_to($first, 1,0);

is (scalar $graph->nodes(), 2, 'two nodes');

my $cells = { };
my $parent = { cells => $cells };

is ($first->_do_place(1,1,$parent), 1, 'node can be placed');

is ($cells->{"1,1"}, $first, 'first was really placed');
is ($cells->{"2,1"}, $second, 'second node was placed, too');
is (scalar keys %$cells, 2, 'two nodes placed');

# 1,0 and 2,0 are blocked, so 0,0+1,0; 1,0+2,0 and 2,0+3,0 are blocked, too:
is ($first->_do_place(0,1,$parent), 0, 'node cannot be placed again');
is ($first->_do_place(1,1,$parent), 0, 'node cannot be placed again');
is ($first->_do_place(2,1,$parent), 0, 'node cannot be placed again');

is (scalar keys %$cells, 2, 'two nodes placed');