File: u_te_ae.t

package info (click to toggle)
libgraph-perl 1%3A0.96-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,316 kB
  • ctags: 938
  • sloc: perl: 6,094; sh: 8; makefile: 2
file content (143 lines) | stat: -rw-r--r-- 3,472 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
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
141
142
143
use Graph;

use Test::More tests => 37;

print "# creating graph\n";
my $gr = Graph->new( multiedged => 1 );

my $A = { name => 'A' };
my $B = { name => 'B' };
my $C = { name => 'C' };

print "# adding A => B\n";
add_edge ($gr,$A,$B);
dumper2($gr);

my @ids;

is($gr->successors  ('A'), 1);
is($gr->predecessors('A'), 0);

@ids = sort $gr->get_multiedge_ids('A', 'B');
is(@ids,   1);
is("@ids", "0");

is($gr->successors  ('B'), 0);
is($gr->predecessors('B'), 1);

@ids = sort $gr->get_multiedge_ids('A', 'B');
is(@ids,   1);
is("@ids", "0");

@ids = sort $gr->get_multiedge_ids('B', 'C');
is(@ids,   0);
is("@ids", "");

print "# adding C => B\n";
add_edge( $gr, $C, $B );
dumper2($gr);

is($gr->successors  ('A'), 1);
is($gr->predecessors('A'), 0);

@ids = sort $gr->get_multiedge_ids('A', 'B');
is(@ids,   1);
is("@ids", "0");

is($gr->successors  ('B'), 0);
is($gr->predecessors('B'), 2);

@ids = sort $gr->get_multiedge_ids('A', 'B');
is(@ids,   1);
is("@ids", "0");

@ids = sort $gr->get_multiedge_ids('C', 'B');
is(@ids,   1);
is("@ids", "0");

is($gr->successors  ('C'), 1);
is($gr->predecessors('C'), 0);

@ids = sort $gr->get_multiedge_ids('C', 'B');
is(@ids,   1);
is("@ids", "0");

@ids = sort $gr->get_multiedge_ids('B', 'C');
is(@ids,   0);
is("@ids", "");

sub add_edge
  {
  my ($g,$x,$y) = @_;

  my $edge_id = $g->add_edge_get_id($x->{name}, $y->{name});

  # work around bug in Graph v0.65 returning something else instead of '0'
  # on first call
  $edge_id = '0' if ref($edge_id);

  # comment this line out, and the dump changes
  $g->set_edge_attribute_by_id( $x->{name}, $y->{name}, $edge_id, "OBJ", {});

  }

sub dumper2
  {
  my @nodes = $gr->vertices();
  for my $n (sort @nodes)
    {
    print "# $n:\n";
    print "# successors   : ", scalar $gr->successors($n),"\n";
    print "# predecessors : ", scalar $gr->predecessors($n),"\n";
    my @suc = $gr->successors($n);
    for my $s (@suc)
      {
      print "# multiedge_ids $n => $s: ", join (", ", $gr->get_multiedge_ids($n, $s)),"\n";
      }
    my @pre = $gr->predecessors($n);
    for my $p (@pre)
      {
      print "# multiedge_ids $p => $n: ", join (", ", $gr->get_multiedge_ids($p, $n)),"\n";
      }
    }
  }

{
    my $graph = Graph->new( undirected => 1 );

    $graph->add_vertex("Berlin");
    $graph->add_vertex("Bonn");
    $graph->add_edge("Berlin","Bonn");
    is ("$graph","Berlin=Bonn");
    $graph->set_edge_attributes("Berlin", "Bonn", { color => "red" });
    is($graph->get_edge_attribute("Bonn", "Berlin", "color"), "red");
    is($graph->get_edge_attribute("Berlin", "Bonn", "color"), "red");
    is ("$graph","Berlin=Bonn");

    $graph = Graph->new( undirected => 1 );

    #$graph->add_vertex("Berlin");
    #$graph->add_vertex("Bonn");
    $graph->add_edge("Bonn","Berlin");
    is ("$graph","Berlin=Bonn");
    $graph->set_edge_attributes("Bonn", "Berlin", { color => "red" });
    is($graph->get_edge_attribute("Bonn", "Berlin", "color"), "red");
    is($graph->get_edge_attribute("Berlin", "Bonn", "color"), "red");
    is ("$graph","Berlin=Bonn");
}

{
    my $graph = Graph->new( multiedged => 1, undirected => 1 );

    isnt ($graph->multiedged(), 0, 'is multiedged');

    my $from = 'Berlin'; my $to = 'Bonn';

    my $id = $graph->add_edge_get_id($from, $to);
    is ("$graph", "Berlin=Bonn", 'only one edge');

    $graph->set_edge_attributes_by_id($from, $to, $id, { color => 'silver' } );

    is ("$graph", "Berlin=Bonn", 'only one edge');
}