summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-09-27 06:55:43 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-09-27 06:55:43 -0700
commit105b8332668b44ca065afcea66828f64d6c58bbb (patch)
tree8aa8314f4bd26fff0404e3ae7b371c3ec496f11f
parentaeef2ca20147a8518e95b5e531bd29af31932c2d (diff)
downloadtxr-105b8332668b44ca065afcea66828f64d6c58bbb.tar.gz
txr-105b8332668b44ca065afcea66828f64d6c58bbb.tar.bz2
txr-105b8332668b44ca065afcea66828f64d6c58bbb.zip
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.
-rw-r--r--tests/016/arith.tl22
-rw-r--r--tests/common.tl3
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))))