Algorithm-TravelingSalesman-BitonicTour

 view release on metacpan or  search on metacpan

t/01-setup.t  view on Meta::CPAN

        'with a nice error message';
}

# make sure we can retrieve coordinates correctly
is_deeply([ $b->coord( 0) ], [ 0, 0 ]);
is_deeply([ $b->coord( 1) ], [ 1, 1 ]);
is_deeply([ $b->coord( 2) ], [ 2, 1 ]);
is_deeply([ $b->coord( 3) ], [ 3, 0 ]);
is_deeply([ $b->coord(-1) ], [ 3, 0 ]);     # sweet

# verify that delta() returns the correct distances between points
{
    my $d = sub { return 0 + sprintf('%.3f', $b->delta(@_)) };
    is( $d->(0,0), 0.0);
    is( $d->(1,1), 0.0);
    is( $d->(0,1), 1.414);
    is( $d->(0,2), 2.236);
    is( $d->(0,3), 3.0);
    is( $d->(1,2), 1.0);
    is( $d->(1,3), 2.236);
    is( $d->(2,3), 1.414);

t/02-optimal-tours.t  view on Meta::CPAN


{
    my @tour = $b->optimal_open_tour(1,2);
    is (sprintf('%.2f',$tour[0]), 3.65);
}
{
    my @tour = $b->optimal_open_tour(0,2);
    is (sprintf('%.3f',$tour[0]), 2.414);
}

# verify calculated tours
{
    my @tests = (
        [ 0,1 => 1.41 => 0, 1 ],
        [ 0,2 => 2.41 => 0, 1, 2 ],
        [ 0,3 => 3.83 => 0, 1, 2, 3 ],
        [ 1,2 => 3.65 => 1, 0, 2 ],
        [ 1,3 => 5.06 => 1, 0, 2, 3 ],
        [ 2,3 => 5.41 => 2, 1, 0, 3 ],
    );



( run in 0.703 second using v1.01-cache-2.11-cpan-73692580452 )