From e5a9aee46b328973ab84e0c675ddab5f53d44ab5 Mon Sep 17 00:00:00 2001 From: johnt Date: Fri, 18 Apr 2008 16:31:49 +0000 Subject: [PATCH] more test coverage git-svn-id: file:///Volumes/JJT 4GB/Apps/svn_repo/Algorithm-TravelingSalesman-BitonicTour/trunk@106 5bda1b4c-df04-11dc-9541-bd5b2d3e4f05 --- .../TravelingSalesman/BitonicTour.pm | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/Algorithm/TravelingSalesman/BitonicTour.pm b/lib/Algorithm/TravelingSalesman/BitonicTour.pm index 7ea1a2b..e8f8917 100644 --- a/lib/Algorithm/TravelingSalesman/BitonicTour.pm +++ b/lib/Algorithm/TravelingSalesman/BitonicTour.pm @@ -281,7 +281,7 @@ sub solve { croak "FAIL: you need to add some points!"; } elsif ($self->N == 1) { - $length = 0; + ($length, @points) = (0, 0); } else { ($length, @points) = $self->optimal_full_tour; @@ -448,9 +448,12 @@ sub tour_cost { unless $_[0] > 0; $self->tour($i,$j)->{cost} = $_[0]; } - croak "Don't know the cost of tour($i,$j)" - unless exists $self->tour($i,$j)->{cost}; - return $self->tour($i,$j)->{cost}; + if (exists $self->tour($i,$j)->{cost}) { + return $self->tour($i,$j)->{cost}; + } + else { + croak "Don't know the cost of tour($i,$j)"; + } } =head2 $b->tour_points($i,$j, [@points]) @@ -470,9 +473,12 @@ sub tour_points { unless $j == $_[-1]; $self->tour($i,$j)->{points} = [ @_ ]; } - croak "Don't know the points for tour($i,$j)" - unless exists $self->tour($i,$j)->{points}; - return @{ $self->tour($i,$j)->{points} }; + if (exists $self->tour($i,$j)->{points}) { + return @{ $self->tour($i,$j)->{points} }; + } + else { + croak "Don't know the points for tour($i,$j)"; + } } =head2 $b->delta($n1,$n2);