Algorithm-Functional-BFS
view release on metacpan or search on metacpan
t/tests/Test/ComplexGraph.pm view on Meta::CPAN
adjacent_nodes_func => $adjacent_nodes_func,
victory_func => $victory_func
);
# Start the search at the node named "A".
my $routes_ref = $bfs->search($haystack{A});
is(scalar(@$routes_ref), 1, 'correct number of routes');
my @route = @{$routes_ref->[0]};
my @expected_route = map { $haystack{$_} } qw(A I J K N O P);
is(scalar(@route), scalar(@expected_route), 'correct route length');
for (my $i = 0; $i < scalar(@route); ++$i)
{
is($route[$i], $expected_route[$i], "route node $i correct");
}
}
1;
t/tests/Test/ObjectsAsNodes.pm view on Meta::CPAN
my $victory_func = sub { shift->get_name() eq $end_node->get_name() };
my $bfs = Algorithm::Functional::BFS->new
(
adjacent_nodes_func => $adjacent_nodes_func,
victory_func => $victory_func,
);
my $routes_ref = $bfs->search($start_node);
is(scalar(@$routes_ref), 1, 'correct number of routes');
is(scalar(@{$routes_ref->[0]}), 6, 'route has correct length');
}
package Node;
use common::sense;
sub new
{
my ($class, %args) = @_;
t/tests/Test/StartNodeInclusion.pm view on Meta::CPAN
adjacent_nodes_func => $adjacent_nodes_func,
victory_func => $victory_func,
include_start_node => 1,
);
my $routes_ref = $bfs->search($haystack{$node_name});
is(scalar(@$routes_ref), 1, 'correct number of routes');
my @route = @{$routes_ref->[0]};
my @expected_route = map { $haystack{$_} } qw(A);
is(scalar(@route), scalar(@expected_route), 'correct route length');
for (my $i = 0; $i < scalar(@route); ++$i)
{
is($route[$i], $expected_route[$i], "route node $i correct");
}
}
# Search for the start node, exclusive of the start node.
sub start_node_exclude : Tests(1)
{
( run in 0.251 second using v1.01-cache-2.11-cpan-87723dcf8b7 )