aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Engdegård2020-02-17 20:55:09 +0100
committerMattias Engdegård2020-02-20 22:00:44 +0100
commit41450a8ea5a156a34f6641a0768cadb174fa261c (patch)
tree727305f837fe2512f0b79324e3a371c6522884a0
parent398afbaf6f31d89b5cb813b75a28b98cf7b1acd2 (diff)
downloademacs-41450a8ea5a156a34f6641a0768cadb174fa261c.tar.gz
emacs-41450a8ea5a156a34f6641a0768cadb174fa261c.zip
Less bad permutation generator in regexp-opt test
* test/lisp/emacs-lisp/regexp-opt-tests.el (regexp-opt-test--permutation, regexp-opt-test--factorial): Remove. (regexp-opt-test--permutations): Rewrite.
-rw-r--r--test/lisp/emacs-lisp/regexp-opt-tests.el29
1 files changed, 8 insertions, 21 deletions
diff --git a/test/lisp/emacs-lisp/regexp-opt-tests.el b/test/lisp/emacs-lisp/regexp-opt-tests.el
index 0179ac4f1f4..2d316b5829f 100644
--- a/test/lisp/emacs-lisp/regexp-opt-tests.el
+++ b/test/lisp/emacs-lisp/regexp-opt-tests.el
@@ -25,27 +25,14 @@
25 25
26(require 'regexp-opt) 26(require 'regexp-opt)
27 27
28(defun regexp-opt-test--permutation (n list) 28(defun regexp-opt-test--permutations (l)
29 "The Nth permutation of LIST, 0 ≤ N < (length LIST)!." 29 "All permutations of L, assuming no duplicates."
30 (let ((len (length list)) 30 (if (cdr l)
31 (perm-list nil)) 31 (mapcan (lambda (x)
32 (dotimes (i len) 32 (mapcar (lambda (p) (cons x p))
33 (let* ((d (- len i)) 33 (perm (remove x l))))
34 (k (mod n d))) 34 l)
35 (push (nth k list) perm-list) 35 (list l)))
36 (setq list (append (butlast list (- (length list) k))
37 (nthcdr (1+ k) list)))
38 (setq n (/ n d))))
39 (nreverse perm-list)))
40
41(defun regexp-opt-test--factorial (n)
42 "N!"
43 (apply #'* (number-sequence 1 n)))
44
45(defun regexp-opt-test--permutations (list)
46 "All permutations of LIST."
47 (mapcar (lambda (i) (regexp-opt-test--permutation i list))
48 (number-sequence 0 (1- (regexp-opt-test--factorial (length list))))))
49 36
50(ert-deftest regexp-opt-longest-match () 37(ert-deftest regexp-opt-longest-match ()
51 "Check that the regexp always matches as much as possible." 38 "Check that the regexp always matches as much as possible."