]> git.eshelyaron.com Git - emacs.git/commitdiff
Expand 'random' testsuite
authorStefan Kangas <stefankangas@gmail.com>
Sun, 16 Oct 2022 06:23:35 +0000 (08:23 +0200)
committerStefan Kangas <stefankangas@gmail.com>
Sun, 16 Oct 2022 06:23:55 +0000 (08:23 +0200)
* test/src/fns-tests.el (ert): Require.
(fns-tests-random): Expand test.

test/src/fns-tests.el

index 5d5d497c99782d174044c853162419076607b5c0..fde5af38fc81cd9a28a8cb0ad0be543548715c2e 100644 (file)
@@ -22,6 +22,7 @@
 ;;; Code:
 
 (require 'cl-lib)
+(require 'ert)
 
 (ert-deftest fns-tests-identity ()
   (let ((num 12345)) (should (eq (identity num) num)))
   (let ((lst '(11))) (should (eq (identity lst) lst))))
 
 (ert-deftest fns-tests-random ()
-  (should (integerp (random)))
-  (should (>= (random 10) 0))
-  (should (< (random 10) 10)))
+  (unwind-protect
+      (progn
+        (should-error (random -1) :type 'args-out-of-range)
+        (should-error (random 0) :type 'args-out-of-range)
+        (should (integerp (random)))
+        (should (= (random 1) 0))
+        (should (>= (random 10) 0))
+        (should (< (random 10) 10))
+        (should (equal (random "seed") (random "seed")))
+        ;; The probability of four calls being the same is low.
+        ;; This makes sure that the value isn't constant.
+        (should (not (= (random t) (random t) (random t) (random t))))
+        ;; Handle bignums.
+        (should (integerp (random (1+ most-positive-fixnum)))))
+    ;; Reset the PRNG seed after testing.
+    (random t)))
 
 (ert-deftest fns-tests-length ()
   (should (= (length nil) 0))