Commits

barbasa  committed 0f4437e

assert just once in is_array_between

  • Participants
  • Parent commits a95994a

Comments (0)

Files changed (4)

File Statistics-Descriptive/Changes

 3.0603      May 15, 2012
     - Use in_between to compare decimal numbers
         - Smoothing tests were failing because of rounding problems
-        - Thanks to Andreas J. König to report it and to Fabio
-          Ponciroli to fix it.
+        - Thanks to Andreas J. König for reporting it and to
+          Fabio Ponciroli for fixing it.
 
 3.0602      May 12, 2012
     - Correct a typo:

File Statistics-Descriptive/t/lib/Utils.pm

     my ($have, $want_bottom, $want_top, $blurb) = @_;
 
     ok (
-        (($have >= $want_bottom) &&
-        ($want_top >= $have)),
+        _is_between($have, $want_bottom, $want_top),
         $blurb
     );
 }
 
     my ($got_array_ref, $expected_array_ref, $low_tolerance, $high_tolerance, $blurb) = @_;
 
-    my $i = 0;
-    foreach my $got_val (@$got_array_ref) {
-        is_between ($got_val,
-                    $expected_array_ref->[$i] - $low_tolerance,
-                    $expected_array_ref->[$i] + $high_tolerance,
-                    "$blurb - ".$expected_array_ref->[$i]
-        );
-        $i++;
+    my $success = 1;
+    if (scalar @$expected_array_ref != scalar @$got_array_ref) {
+        $success = 0;
+        diag('Arrays have different lengths');
     }
+    else {
+        for my $idx (0 .. $#$got_array_ref) {
+            my $expected_bottom = $expected_array_ref->[$idx] - $low_tolerance;
+            my $expected_top = $expected_array_ref->[$idx] + $high_tolerance;
+            unless (_is_between($got_array_ref->[$idx], $expected_bottom, $expected_top)) {
+                $success = 0;
+                diag(<<"EOF");
+Value $idx is out of range:
+Got: [$got_array_ref->[$idx]]
+Expected: [$expected_bottom, $expected_top, $expected_array_ref->[$idx]]
+EOF
+
+                last;
+            }
+        }
+    }
+    ok($success, $blurb);
 }
 
 sub compare_hash_by_ranges
     ok($success, $blurb);
 }
 
+sub _is_between {
+    my ($have, $want_bottom, $want_top,) = @_;
+
+    return (($have >= $want_bottom) && ($want_top >= $have));
+}
+
 1;
 
 =pod

File Statistics-Descriptive/t/smoother_exponential.t

 use lib 't/lib';
 use Utils qw/is_array_between/;
 
-use Test::More tests => 12;
+use Test::More tests => 3;
 
 use Statistics::Descriptive::Smoother;
 
           9.001953125,
     );
 
-    # TEST*10
+    # TEST
     is_array_between( \@smoothed_data, \@expected_values, 1E-13, 1E-13, 'Smoothing with C=0.5');
 }
 

File Statistics-Descriptive/t/smoother_weightedexponential.t

 use lib 't/lib';
 use Utils qw/is_array_between/;
 
-use Test::More tests => 13;
+use Test::More tests => 4;
 
 use Statistics::Descriptive::Smoother;
 
                     8.73457937329917,
     );
 
-    # TEST*10
+    # TEST
     is_array_between( \@smoothed_data, \@expected_values, 1E-13, 1E-13, 'Smoothing with C=0.5');
 }