File: 08_naive_isomorphism_trap.t

package info (click to toggle)
libgraph-nauty-perl 0.5.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 160 kB
  • sloc: perl: 202; makefile: 3
file content (52 lines) | stat: -rw-r--r-- 1,663 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
use strict;
use warnings;
use Graph::Nauty qw(
    are_isomorphic
    canonical_order
    orbits
);
use Graph::Undirected;
use Test::More tests => 5;

my @v1 = ( { index => 0, type => 0 },
           { index => 1, type => 1 },
           { index => 2, type => 0 },
           { index => 3, type => 0 } );
my @v2 = ( { index => 0, type => 0 },
           { index => 1, type => 0 },
           { index => 2, type => 1 },
           { index => 3, type => 0 } );

my $g1 = Graph::Undirected->new;
my $g2 = Graph::Undirected->new;

$g1->add_edge( $v1[0], $v1[1] );
$g1->add_edge( $v1[0], $v1[3] );
$g1->add_edge( $v1[2], $v1[1] );
$g1->add_edge( $v1[2], $v1[3] );

$g2->add_edge( $v2[0], $v2[1] );
$g2->add_edge( $v2[0], $v2[3] );
$g2->add_edge( $v2[2], $v2[1] );
$g2->add_edge( $v2[2], $v2[3] );

is join( ',', map { scalar @$_ } orbits( $g1,
                                         sub { $_[0]->{type} },
                                         sub { $_[0]->{index} } ) ),
   '2,1,1';
is join( ',', map { scalar @$_ } orbits( $g2,
                                         sub { $_[0]->{type} },
                                         sub { $_[0]->{index} } ) ),
   '1,2,1';
ok are_isomorphic(  $g1, $g2, sub { $_[0]->{type} } );

is( join( ',', map { $_->{index} }
                   canonical_order( $g1,
                                    sub { $_[0]->{type} },
                                    sub { $_[0]->{index} } ) ),
    '3,0,2,1' );
is( join( ',', map { $_->{index} }
                   canonical_order( $g2,
                                    sub { $_[0]->{type} },
                                    sub { $_[0]->{index} } ) ),
    '0,1,3,2' );