diff options
| author | Pip Cet | 2025-06-20 06:01:41 +0000 |
|---|---|---|
| committer | Pip Cet | 2025-06-20 06:09:24 +0000 |
| commit | b6cf7c094293589c6180fe5cee7405285d9a545d (patch) | |
| tree | 7059f2beb60581ae81e57cf341fba0dc3e17e2ca /test/lisp | |
| parent | 6181e0cec5158c5b66bf861c32e49674b2a110e9 (diff) | |
| download | emacs-b6cf7c094293589c6180fe5cee7405285d9a545d.tar.gz emacs-b6cf7c094293589c6180fe5cee7405285d9a545d.zip | |
Make cl-random behave consistently for unusual arguments (bug#75105)
The old behavior was for (cl-random -1.0e+INF) to return NaN in about
one in eight million calls, and -1.0e+INF otherwise. Other unusual
arguments were handled inconsistently as well.
* lisp/emacs-lisp/cl-extra.el (cl-random): Handle positive finite
arguments consistently, error for nonpositive or infinite arguments.
* test/lisp/emacs-lisp/cl-extra-tests.el (cl-extra-test-random): New
test.
Diffstat (limited to 'test/lisp')
| -rw-r--r-- | test/lisp/emacs-lisp/cl-extra-tests.el | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/test/lisp/emacs-lisp/cl-extra-tests.el b/test/lisp/emacs-lisp/cl-extra-tests.el index 6280be06cbb..5290ed9d04e 100644 --- a/test/lisp/emacs-lisp/cl-extra-tests.el +++ b/test/lisp/emacs-lisp/cl-extra-tests.el | |||
| @@ -438,6 +438,15 @@ | |||
| 438 | (my-foo most-positive-fixnum))) | 438 | (my-foo most-positive-fixnum))) |
| 439 | ) | 439 | ) |
| 440 | 440 | ||
| 441 | (ert-deftest cl-extra-test-random () | ||
| 442 | (should-error (cl-random -1)) | ||
| 443 | (should-error (cl-random -0.5)) | ||
| 444 | (should-error (cl-random -1.0e+INF)) | ||
| 445 | (should-error (cl-random 0)) | ||
| 446 | (should-error (cl-random 0.0)) | ||
| 447 | (should-error (cl-random -0.0)) | ||
| 448 | (should-error (cl-random 1.0e+INF)) | ||
| 449 | (should (eql (cl-random 1) 0))) | ||
| 441 | 450 | ||
| 442 | 451 | ||
| 443 | ;;; cl-extra-tests.el ends here | 452 | ;;; cl-extra-tests.el ends here |