File: 45_add_cycle.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 (29 lines) | stat: -rw-r--r-- 711 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
use strict; use warnings;
use Test::More tests => 13;

use Graph;
my $g = Graph->new;

$g->add_cycle("a", "b", "c", "d", "e");
is $g, "a-b,b-c,c-d,d-e,e-a";

ok(   $g->has_cycle(qw(a b c d e)) );
ok( ! $g->has_cycle(qw(a c b d e)) );
ok( ! $g->has_cycle(qw(b a c d e)) );
ok(   $g->has_cycle(qw(e a b c d)) );
ok( ! $g->has_cycle(qw(e d a b c)) );

$g->delete_cycle("a", "b", "c");
is $g, "c-d,d-e,e-a,b";

my $h = Graph->new(undirected => 1);
$h->add_cycle("a", "b", "c", "d", "e");
is $h, "a=b,a=e,b=c,c=d,d=e";
ok(   $h->has_cycle(qw(a b c d e)) );
ok(   $h->has_cycle(qw(e a b c d)) );
ok( ! $h->has_cycle(qw(a b d c e)) );

$h->delete_cycle("a", "b", "c");
is $h, "a=e,c=d,d=e,b";

ok(!  $g->has_cycle());