From c4c4a60f71254b7f59010c5539545fc2fc49b855 Mon Sep 17 00:00:00 2001 From: Stefan Kangas <stefankangas@gmail.com> Date: Sun, 16 Oct 2022 08:23:35 +0200 Subject: [PATCH] Expand 'random' testsuite * test/src/fns-tests.el (ert): Require. (fns-tests-random): Expand test. --- test/src/fns-tests.el | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el index 5d5d497c997..fde5af38fc8 100644 --- a/test/src/fns-tests.el +++ b/test/src/fns-tests.el @@ -22,6 +22,7 @@ ;;; Code: (require 'cl-lib) +(require 'ert) (ert-deftest fns-tests-identity () (let ((num 12345)) (should (eq (identity num) num))) @@ -29,9 +30,22 @@ (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)) -- 2.39.5