Graph-Undirected-Hamiltonicity
view release on metacpan or search on metacpan
t/graph_is_hamiltonian.t view on Meta::CPAN
#!perl
use Modern::Perl;
use Graph::Undirected::Hamiltonicity qw(:all);
use Graph::Undirected::Hamiltonicity::Transforms qw(&string_to_graph);
use Graph::Undirected::Hamiltonicity::Wolfram qw(:all);
use Test::More;
$ENV{HC_OUTPUT_FORMAT} = 'none';
my $url = get_url_from_config();
if ($url) {
plan tests => 28;
} else {
plan tests => 14;
print $ENV{HOME} . "/hamilton.ini doesn't exist. ";
say "Skipping Wolfram verification.";
}
while ( defined( my $line = <DATA> ) ) {
next if $line =~ /^\s*#/; ### skip comments
chomp $line;
if ( $line =~ /^([^|]+)\|([01])\|(\d+|\d+=\d+(,\d+=\d+)*)$/ ) {
my ( $label, $expected_result, $graph_text ) = ( $1, $2, $3 );
my $g = string_to_graph($graph_text);
my $is_hamiltonian = graph_is_hamiltonian($g);
is( $is_hamiltonian, $expected_result, $label );
if ($url) {
is( is_hamiltonian_per_wolfram($g),
$expected_result, "Wolfram: $label" );
}
}
}
1;
__DATA__
###
### This is where test cases for the subroutine Graph::Undirected::Hamiltonicity::graph_is_hamiltonian()
### are written, one per line,
### in the format: label|expected_result|graph_text
###
### label: can be any string not containing the pipe ( | ) character.
###
###
### expected_result: can be 1, or 0.
### where
### 1 means GRAPH_IS_HAMILTONIAN
### 0 means GRAPH_IS_NOT_HAMILTONIAN
###
###
### graph_text: is a string representation of the graph.
###
### Note: Every time you add a test case, remember to update the "plan tests => NUMBER";
# Here are some test cases:
a single vertex|1|8
( run in 0.783 second using v1.01-cache-2.11-cpan-ceb78f64989 )