From a06fdec52c8d436db925ec158d231627773f5bf9 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 27 Sep 2021 06:55:43 -0700 Subject: quantile: fix test needing nonportable amount of precision. * tests/common.tl (sstest): New macro. Like stest, but the right hand side is an object which the macro turns to a string, rather than expecting a string. * tests/016/arith.tl: Use the sstest macro for the main quantile test to compare the result and expected value as character strings rather than objects. Specify the expected values using no more than 14 decimal digits of precision, and over the scope of the test case, restrict floating-point printing to 14 digits. Thus, we effectively have quick and dirty epsilon comparison to 14 digits that recurses over the list, without having to write that as a function. --- tests/016/arith.tl | 22 +++++++++++----------- tests/common.tl | 3 +++ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/tests/016/arith.tl b/tests/016/arith.tl index d785afb2..ad919e6b 100644 --- a/tests/016/arith.tl +++ b/tests/016/arith.tl @@ -223,17 +223,17 @@ (< '(1 2 3) #(1 2 3 4)) t (< '(1 2 3) #(1 2 4)) t) -(test - (let ((q (quantile 0.5))) - [q 0.02 0.5 0.74 3.39 0.83] - [mapcar q '(22.37 10.15 15.43 38.62 15.92 - 34.60 10.28 1.47 0.40 0.05 11.39 - 0.27 0.42 0.09 11.37)]) - (0.73999999999999999 0.73999999999999999 2.0616666666666665 - 4.5517592592592591 4.5517592592592591 9.1519618055555547 - 9.1519618055555547 9.1519618055555547 9.1519618055555547 - 6.1797614914021164 6.1797614914021164 6.1797614914021164 - 6.1797614914021164 4.2462394088036453 4.2462394088036453)) +(let ((*print-flo-precision* 14)) + (sstest + (let ((q (quantile 0.5))) + [q 0.02 0.5 0.74 3.39 0.83] + [mapcar q '(22.37 10.15 15.43 38.62 15.92 + 34.60 10.28 1.47 0.40 0.05 11.39 + 0.27 0.42 0.09 11.37)]) + (0.74 0.74 2.0616666666667 4.5517592592593 4.5517592592593 9.1519618055556 + 9.1519618055556 9.1519618055556 9.1519618055556 6.1797614914021 + 6.1797614914021 6.1797614914021 6.1797614914021 4.2462394088036 + 4.2462394088036))) (test (let ((q (quantile 0))) diff --git a/tests/common.tl b/tests/common.tl index 5ad35935..dbd4ef24 100644 --- a/tests/common.tl +++ b/tests/common.tl @@ -56,6 +56,9 @@ (defmacro stest (expr expected) ^(vtest ,^(tostring ,expr) ,expected)) +(defmacro sstest (expr expected) + ^(vtest ,^(tostring ,expr) ,(tostring expected))) + (defmacro mtest (. pairs) ^(progn ,*(mapcar (op cons 'test) (tuples 2 pairs)))) -- cgit v1.2.3