Algorithm-Functional-BFS

 view release on metacpan or  search on metacpan

t/tests/Test/ComplexGraph.pm  view on Meta::CPAN

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
        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

57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
    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;
 
 
sub new
{
    my ($class, %args) = @_;

t/tests/Test/StartNodeInclusion.pm  view on Meta::CPAN

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
        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.424 second using v1.01-cache-2.11-cpan-87723dcf8b7 )