# New Ticket Created by  Cosimo Streppone 
# Please include the string:  [perl #50216]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=50216 >


Recently I've been working on the perl6 test suite
that lives in pugs/t/spec repository.

Several test scripts in the "math" category use
an `approx()' function to compare two floating point
numbers with approximation, but they defined it
every time in each test script.

So I wrote and tested this patch against r24953
which adds approx() to languages/perl6/Test.pm.

-- 
Cosimo



Index: Test.pm
===================================================================
--- Test.pm     (revisione 24953)
+++ Test.pm     (copia locale)
@@ -17,6 +17,13 @@
 
 ## test functions
 
+# Compare numeric values with approximation
+sub approx ($x, $y) {
+    my $epsilon = 0.0001;
+    my $diff = abs($x - $y);
+    ($diff < $epsilon);
+}
+
 sub plan($number_of_tests) {
     $testing_started      = 1;
     $num_of_tests_planned = $number_of_tests;

Reply via email to