Skip to content

Commit

Permalink
moving problem solutions into their own files
Browse files Browse the repository at this point in the history
git-svn-id: file:///Volumes/JJT 4GB/Apps/svn_repo/Algorithm-TravelingSalesman-BitonicTour/trunk@102 5bda1b4c-df04-11dc-9541-bd5b2d3e4f05
  • Loading branch information
johnt committed Apr 18, 2008
1 parent 7bce33b commit f3af6c4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
16 changes: 16 additions & 0 deletions t/03-solve-0.t
@@ -0,0 +1,16 @@
use strict;
use warnings;
use Algorithm::TravelingSalesman::BitonicTour;
use Data::Dumper;
use Test::More 'no_plan';
use Test::Exception;

use_ok('Algorithm::TravelingSalesman::BitonicTour');

# make sure an attempt to solve a problem with no points dies
{
my $b = Algorithm::TravelingSalesman::BitonicTour->new;
throws_ok { $b->solve } qr/need to add some points/,
'bad problem throws exception';
}

19 changes: 19 additions & 0 deletions t/04-solve-1.t
@@ -0,0 +1,19 @@
use strict;
use warnings;
use Algorithm::TravelingSalesman::BitonicTour;
use Data::Dumper;
use Test::More 'no_plan';
use Test::Exception;

use_ok('Algorithm::TravelingSalesman::BitonicTour');

# make sure a problem with exactly one point "works"
for (1 .. 10) {
my $b = Algorithm::TravelingSalesman::BitonicTour->new;
my ($x, $y) = map { 10 - rand(20) } 1, 2;
$b->add_point($x,$y);
my @solution;
lives_ok { @solution = $b->solve };
is_deeply(\@solution, [0,0]) or diag(Dumper($b));
}

20 changes: 1 addition & 19 deletions t/03-solve.t → t/05-solve-N.t
Expand Up @@ -7,25 +7,7 @@ use Test::Exception;

use_ok('Algorithm::TravelingSalesman::BitonicTour');

# make sure an attempt to solve a problem with no points dies
{
my $b = Algorithm::TravelingSalesman::BitonicTour->new;
throws_ok { $b->solve } qr/need to add some points/,
'bad problem throws exception';
}

# make sure a problem with exactly one point "works"
for (1 .. 10) {
my $b = Algorithm::TravelingSalesman::BitonicTour->new;
my ($x, $y) = map { 10 - rand(20) } 1, 2;
$b->add_point($x,$y);
my @solution;
lives_ok { @solution = $b->solve };
is_deeply(\@solution, [0,0]) or diag(Dumper($b));
}


# now solve a real problem (simple trapezoid)
# solve a real problem (simple trapezoid)
{
my $b = Algorithm::TravelingSalesman::BitonicTour->new;
$b->add_point(0,0);
Expand Down

0 comments on commit f3af6c4

Please sign in to comment.