diff options
author | Damien Cassou <damien@cassou.me> | 2016-10-21 07:53:08 +0200 |
---|---|---|
committer | Nicolas Petton <nicolas@petton.fr> | 2016-10-25 12:32:57 +0200 |
commit | bd22beb6e4054c659e8c31931c421f60e9719c65 (patch) | |
tree | c9afbd41266dc8c13a9807bf825d68cdbc148687 /test/lisp/emacs-lisp | |
parent | 26ccd19269c040ad5960a7567aa5fc88f142c709 (diff) | |
download | emacs-bd22beb6e4054c659e8c31931c421f60e9719c65.tar.gz emacs-bd22beb6e4054c659e8c31931c421f60e9719c65.tar.bz2 emacs-bd22beb6e4054c659e8c31931c421f60e9719c65.zip |
Add seq-random-elt to seq.el
* lisp/emacs-lisp/seq.el (seq-random-elt): Add function to return a
random element from it's sequence parameter.
* test/lisp/emacs-lisp/seq-tests.el (test-seq-random-elt-take-all
test-seq-random-elt-return-nil): Test the new function
* doc/lispref/sequences.texi: Document the new function
Diffstat (limited to 'test/lisp/emacs-lisp')
-rw-r--r-- | test/lisp/emacs-lisp/seq-tests.el | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/test/lisp/emacs-lisp/seq-tests.el b/test/lisp/emacs-lisp/seq-tests.el index c2065c6718f..6d17b7c7c97 100644 --- a/test/lisp/emacs-lisp/seq-tests.el +++ b/test/lisp/emacs-lisp/seq-tests.el @@ -28,6 +28,7 @@ (require 'ert) (require 'seq) +(require 'map) (defmacro with-test-sequences (spec &rest body) "Successively bind VAR to a list, vector, and string built from SEQ. @@ -371,5 +372,21 @@ Evaluate BODY for each created sequence. (should (equal (seq-sort-by #'seq-length #'> seq) ["xxx" "xx" "x"])))) +(ert-deftest test-seq-random-elt-take-all () + (let ((seq '(a b c d e)) + (count '())) + (should (= 0 (map-length count))) + (dotimes (_ 1000) + (let ((random-elt (seq-random-elt seq))) + (map-put count + random-elt + (map-elt count random-elt 0)))) + (should (= 5 (map-length count))))) + +(ert-deftest test-seq-random-elt-signal-on-empty () + (should-error (seq-random-elt nil)) + (should-error (seq-random-elt [])) + (should-error (seq-random-elt ""))) + (provide 'seq-tests) ;;; seq-tests.el ends here |