diff options
author | Mattias Engdegård <mattiase@acm.org> | 2020-02-17 20:55:09 +0100 |
---|---|---|
committer | Mattias Engdegård <mattiase@acm.org> | 2020-02-20 22:00:44 +0100 |
commit | 41450a8ea5a156a34f6641a0768cadb174fa261c (patch) | |
tree | 727305f837fe2512f0b79324e3a371c6522884a0 /test/lisp/emacs-lisp | |
parent | 398afbaf6f31d89b5cb813b75a28b98cf7b1acd2 (diff) | |
download | emacs-41450a8ea5a156a34f6641a0768cadb174fa261c.tar.gz emacs-41450a8ea5a156a34f6641a0768cadb174fa261c.tar.bz2 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.
Diffstat (limited to 'test/lisp/emacs-lisp')
-rw-r--r-- | test/lisp/emacs-lisp/regexp-opt-tests.el | 29 |
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 @@ (require 'regexp-opt) -(defun regexp-opt-test--permutation (n list) - "The Nth permutation of LIST, 0 ≤ N < (length LIST)!." - (let ((len (length list)) - (perm-list nil)) - (dotimes (i len) - (let* ((d (- len i)) - (k (mod n d))) - (push (nth k list) perm-list) - (setq list (append (butlast list (- (length list) k)) - (nthcdr (1+ k) list))) - (setq n (/ n d)))) - (nreverse perm-list))) - -(defun regexp-opt-test--factorial (n) - "N!" - (apply #'* (number-sequence 1 n))) - -(defun regexp-opt-test--permutations (list) - "All permutations of LIST." - (mapcar (lambda (i) (regexp-opt-test--permutation i list)) - (number-sequence 0 (1- (regexp-opt-test--factorial (length list)))))) +(defun regexp-opt-test--permutations (l) + "All permutations of L, assuming no duplicates." + (if (cdr l) + (mapcan (lambda (x) + (mapcar (lambda (p) (cons x p)) + (perm (remove x l)))) + l) + (list l))) (ert-deftest regexp-opt-longest-match () "Check that the regexp always matches as much as possible." |