From 34e75c144efe54dd6063fbb65d5a40176952422c Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 13 Aug 2018 09:36:11 -0700 Subject: [PATCH] Add comment about floating point test * test/src/data-tests.el (data-tests--float-greater-than-fixnums): New constant. (data-tests-=, data-tests-<, data-tests->, data-tests-<=) (data-tests->=, data-tests-min): Use it. --- test/src/data-tests.el | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/test/src/data-tests.el b/test/src/data-tests.el index 91463db113c..b444dc70f17 100644 --- a/test/src/data-tests.el +++ b/test/src/data-tests.el @@ -23,13 +23,21 @@ (require 'cl-lib) +(defconst data-tests--float-greater-than-fixnums (+ 1.0 most-positive-fixnum) + "A floating-point value that is greater than all fixnums. +It is also as small as conveniently possible, to make the tests sharper. +Adding 1.0 to most-positive-fixnum should suffice on all +practical Emacs platforms, since the result is a power of 2 and +this is exactly representable and is greater than +most-positive-fixnum, which is just less than a power of 2.") + (ert-deftest data-tests-= () (should-error (=)) (should (= 1)) (should (= 2 2)) (should (= 9 9 9 9 9 9 9 9 9)) (should (= most-negative-fixnum (float most-negative-fixnum))) - (should-not (= most-positive-fixnum (+ 1.0 most-positive-fixnum))) + (should-not (= most-positive-fixnum data-tests--float-greater-than-fixnums)) (should-not (apply #'= '(3 8 3))) (should-error (= 9 9 'foo)) ;; Short circuits before getting to bad arg @@ -40,7 +48,7 @@ (should (< 1)) (should (< 2 3)) (should (< -6 -1 0 2 3 4 8 9 999)) - (should (< 0.5 most-positive-fixnum (+ 1.0 most-positive-fixnum))) + (should (< 0.5 most-positive-fixnum data-tests--float-greater-than-fixnums)) (should-not (apply #'< '(3 8 3))) (should-error (< 9 10 'foo)) ;; Short circuits before getting to bad arg @@ -51,7 +59,7 @@ (should (> 1)) (should (> 3 2)) (should (> 6 1 0 -2 -3 -4 -8 -9 -999)) - (should (> (+ 1.0 most-positive-fixnum) most-positive-fixnum 0.5)) + (should (> data-tests--float-greater-than-fixnums most-positive-fixnum 0.5)) (should-not (apply #'> '(3 8 3))) (should-error (> 9 8 'foo)) ;; Short circuits before getting to bad arg @@ -62,7 +70,7 @@ (should (<= 1)) (should (<= 2 3)) (should (<= -6 -1 -1 0 0 0 2 3 4 8 999)) - (should (<= 0.5 most-positive-fixnum (+ 1.0 most-positive-fixnum))) + (should (<= 0.5 most-positive-fixnum data-tests--float-greater-than-fixnums)) (should-not (apply #'<= '(3 8 3 3))) (should-error (<= 9 10 'foo)) ;; Short circuits before getting to bad arg @@ -73,7 +81,7 @@ (should (>= 1)) (should (>= 3 2)) (should (>= 666 1 0 0 -2 -3 -3 -3 -4 -8 -8 -9 -999)) - (should (>= (+ 1.0 most-positive-fixnum) most-positive-fixnum)) + (should (>= data-tests--float-greater-than-fixnums most-positive-fixnum)) (should-not (apply #'>= '(3 8 3))) (should-error (>= 9 8 'foo)) ;; Short circuits before getting to bad arg @@ -97,7 +105,7 @@ (should (= 2 (min 3 2))) (should (= -999 (min 666 1 0 0 -2 -3 -3 -3 -4 -8 -8 -9 -999))) (should (= most-positive-fixnum - (min (+ 1.0 most-positive-fixnum) most-positive-fixnum))) + (min data-tests--float-greater-than-fixnums most-positive-fixnum))) (should (= 3 (apply #'min '(3 8 3)))) (should-error (min 9 8 'foo)) (should-error (min (make-marker))) -- 2.39.2