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
|
use Test::More tests => 49;
use Graph;
my $g0 = Graph->new;
my $g1a = Graph->new(refvertexed => 1);
my $g1b = Graph->new(refvertexed => 0);
ok( !$g0 ->refvertexed() );
ok( $g1a->refvertexed() );
ok( !$g1b->refvertexed() );
my $g2a = Graph->new(countvertexed => 1);
my $g2b = Graph->new(countvertexed => 0);
ok( !$g0 ->countvertexed() );
ok( $g2a->countvertexed() );
ok( !$g2b->countvertexed() );
my $g3a = Graph->new(hypervertexed => 1);
my $g3b = Graph->new(hypervertexed => 0);
ok( !$g0 ->hypervertexed() );
ok( $g3a->hypervertexed() );
ok( !$g3b->hypervertexed() );
my $g4a = Graph->new(omnidirected => 1);
my $g4b = Graph->new(omnidirected => 0);
ok( !$g0 ->omnidirected() );
ok( $g4a->omnidirected() );
ok( !$g4b->omnidirected() );
ok( $g4a->undirected() );
ok( !$g4b->undirected() );
ok( !$g4a->directed() );
ok( $g4b->directed() );
my $g5a = Graph->new(undirected => 1);
my $g5b = Graph->new(undirected => 0);
ok( $g5a->omnidirected() );
ok( !$g5b->omnidirected() );
ok( !$g0 ->undirected() );
ok( $g5a->undirected() );
ok( !$g5b->undirected() );
ok( !$g5a->directed() );
ok( $g5b->directed() );
my $g6a = Graph->new(directed => 1);
my $g6b = Graph->new(directed => 0);
ok( !$g6a->omnidirected() );
ok( $g6b->omnidirected() );
ok( !$g6a->undirected() );
ok( $g6b->undirected() );
ok( $g0 ->directed() ); # The default is directed.
ok( $g6a->directed() );
ok( !$g6b->directed() );
my $g7a = Graph->new(countedged => 1);
my $g7b = Graph->new(countedged => 0);
ok( !$g0 ->countedged() );
ok( $g7a->countedged() );
ok( !$g7b->countedged() );
{
local $SIG{__DIE__} = sub { $@ = shift };
eval { my $gna = Graph->new(foobar => 1) };
like($@, qr/Graph::new: Unknown option: 'foobar' /);
eval { my $gna = Graph->new(foobar => 0) };
like($@, qr/Graph::new: Unknown option: 'foobar' /);
eval { my $gna = Graph->new(foobar => 1, barfoo => 1) };
like($@, qr/Graph::new: Unknown options: 'barfoo' 'foobar' /);
}
{
my $g = Graph->new(vertices => [0, 1, 2]);
ok($g->has_vertex(0));
ok($g->has_vertex(1));
ok($g->has_vertex(2));
}
{
my $g = Graph->new(edges => [[0, 1], [2, 3]]);
ok($g->has_edge(0, 1));
ok($g->has_edge(2, 3));
}
{
my $g = Graph->new(vertices => [0], edges => [[1, 2], [2, 3]]);
ok($g->has_vertex(0));
ok($g->has_edge(1, 2));
ok($g->has_edge(2, 3));
}
{
my $g = Graph->new(compat02 => 1, hypervertexed => 1, multiedged => 1);
my $h = $g->new; # The flags should be inherited.
ok($h->is_compat02);
ok($h->is_hypervertexed);
ok($h->is_multiedged);
}
use Graph::Directed;
my $d = Graph::Directed->new;
is(ref $d, 'Graph::Directed');
use Graph::Undirected;
my $u = Graph::Undirected->new;
is(ref $u, 'Graph::Undirected');
|