File: 56_neighbourhood.t

package info (click to toggle)
libgraph-perl 1%3A0.9726-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 996 kB
  • sloc: perl: 4,083; sh: 8; makefile: 2
file content (89 lines) | stat: -rw-r--r-- 2,085 bytes parent folder | download
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
use strict; use warnings;
use Test::More;

use Graph;
my $g0 = Graph->new;
my $g1 = Graph->new(undirected => 1);

my @E = ([1=>1], [1=>2], [1=>3], [2=>4], [5=>4]);
$g0->add_edge(@$_) for @E;
$g1->add_edge(@$_) for @E;
$g0->add_vertex(6);  $g1->add_vertex(6);  

is $g0, "1-1,1-2,1-3,2-4,5-4,6";
is $g1, "1=1,1=2,1=3,2=4,4=5,6";

my %methods = (
  neighbours => [
    [ [1], "1 2 3", "1 2 3" ],
    [ [2], "1 4", "1 4" ],
    [ [3], "1", "1" ],
    [ [4], "2 5", "2 5" ],
    [ [5], "4", "4" ],
    [ [6], "", "" ],
  ],
  neighbours_by_radius => [
    [ [1, 1], "1 2 3", "1 2 3" ],
    [ [2, 1], "1 4", "1 4" ],
    [ [3, 1], "1", "1" ],
    [ [4, 1], "2 5", "2 5" ],
    [ [5, 2], "2 4", "2 4" ],
    [ [6, 1], "", "" ],
  ],
  is_successorless_vertex => [
    [ [1], "", "" ],
    [ [2], "", "" ],
    [ [3], 1, "" ],
    [ [4], 1, "" ],
    [ [5], "", "" ],
    [ [6], 1, 1 ],
  ],
  is_successorful_vertex => [
    [ [1], 1, 1 ],
    [ [2], 1, 1 ],
    [ [3], "", 1 ],
    [ [4], "", 1 ],
    [ [5], 1, 1 ],
    [ [6], "", "" ],
  ],
  is_predecessorless_vertex => [
    [ [1], "", "" ],
    [ [2], "", "" ],
    [ [3], "", "" ],
    [ [4], "", "" ],
    [ [5], 1, "" ],
    [ [6], 1, 1 ],
  ],
  is_predecessorful_vertex => [
    [ [1], 1, 1 ],
    [ [2], 1, 1 ],
    [ [3], 1, 1 ],
    [ [4], 1, 1 ],
    [ [5], "", 1 ],
    [ [6], "", "" ],
  ],
  successorless_vertices => [
    [ [], "3 4 6", "6" ],
  ],
  successorful_vertices => [
    [ [], "1 2 5", "1 2 3 4 5" ],
  ],
  predecessorless_vertices => [
    [ [], "5 6", "6" ],
  ],
  predecessorful_vertices => [
    [ [], "1 2 3 4", "1 2 3 4 5" ],
  ],
);
for my $m (sort keys %methods) {
  for my $t ( @{ $methods{$m} } ) {
    my ($args, $expected0, $expected1) = @$t;
    my $got0_count = scalar $g0->$m(@$args);
    my $expected0_count = scalar split ' ', $expected0;
    is $got0_count+0, $expected0_count, "right number for scalar context $m";
    is( "@{[sort $g0->$m(@$args)]}", $expected0, "directed $m (@$args)" );
    is( "@{[sort $g1->$m(@$args)]}", $expected1, "undirected $m (@$args)" );
  }
}

done_testing;