diff options
| author | Stefan Kangas | 2025-02-17 04:52:49 +0100 |
|---|---|---|
| committer | Stefan Kangas | 2025-02-17 05:37:10 +0100 |
| commit | 5ce746c3b0fa3a0b73796182960ff06cf3f31473 (patch) | |
| tree | da6a18b124a472af60562dbd82253c55d5eec78a /test | |
| parent | 657f4658a7141708adb7f3ca594145f2df569d4c (diff) | |
| download | emacs-5ce746c3b0fa3a0b73796182960ff06cf3f31473.tar.gz emacs-5ce746c3b0fa3a0b73796182960ff06cf3f31473.zip | |
Prefer oddp/evenp to free-coding them in tests
* test/lisp/emacs-lisp/bindat-tests.el (bindat-test--sint):
* test/lisp/emacs-lisp/seq-tests.el (test-seq-drop-while)
(test-seq-take-while, test-seq-filter, test-seq-remove)
(test-seq-count, test-seq-some, test-seq-find, test-seq-every-p)
(test-seq-group-by):
* test/lisp/eshell/em-pred-tests.el (eshell-with-file-attributes-from-name):
* test/lisp/filenotify-tests.el (file-notify-test07-many-events)
(file-notify-test09-watched-file-in-watched-dir):
* test/src/floatfns-tests.el (bignum-expt, bignum-round):
* test/src/undo-tests.el (undo-test4): Prefer oddp/evenp to free-coding
them.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/emacs-lisp/bindat-tests.el | 2 | ||||
| -rw-r--r-- | test/lisp/emacs-lisp/seq-tests.el | 60 | ||||
| -rw-r--r-- | test/lisp/eshell/em-pred-tests.el | 2 | ||||
| -rw-r--r-- | test/lisp/filenotify-tests.el | 4 | ||||
| -rw-r--r-- | test/src/floatfns-tests.el | 4 | ||||
| -rw-r--r-- | test/src/undo-tests.el | 2 |
6 files changed, 33 insertions, 41 deletions
diff --git a/test/lisp/emacs-lisp/bindat-tests.el b/test/lisp/emacs-lisp/bindat-tests.el index f5dacfeaa77..78021f0bc14 100644 --- a/test/lisp/emacs-lisp/bindat-tests.el +++ b/test/lisp/emacs-lisp/bindat-tests.el | |||
| @@ -125,7 +125,7 @@ | |||
| 125 | (ert-deftest bindat-test--sint () | 125 | (ert-deftest bindat-test--sint () |
| 126 | (dotimes (kind 32) | 126 | (dotimes (kind 32) |
| 127 | (let ((bitlen (* 8 (/ kind 2))) | 127 | (let ((bitlen (* 8 (/ kind 2))) |
| 128 | (r (zerop (% kind 2)))) | 128 | (r (evenp kind))) |
| 129 | (dotimes (_ 100) | 129 | (dotimes (_ 100) |
| 130 | (let* ((n (random (ash 1 bitlen))) | 130 | (let* ((n (random (ash 1 bitlen))) |
| 131 | (i (- n (ash 1 (1- bitlen)))) | 131 | (i (- n (ash 1 (1- bitlen)))) |
diff --git a/test/lisp/emacs-lisp/seq-tests.el b/test/lisp/emacs-lisp/seq-tests.el index ddca2d7ed93..a8ed51e8e70 100644 --- a/test/lisp/emacs-lisp/seq-tests.el +++ b/test/lisp/emacs-lisp/seq-tests.el | |||
| @@ -49,14 +49,6 @@ Evaluate BODY for each created sequence. | |||
| 49 | "Return t if SEQ1 and SEQ2 have the same contents, nil otherwise." | 49 | "Return t if SEQ1 and SEQ2 have the same contents, nil otherwise." |
| 50 | (equal (append seq1 '()) (append seq2 '()))) | 50 | (equal (append seq1 '()) (append seq2 '()))) |
| 51 | 51 | ||
| 52 | (defun test-sequences-evenp (integer) | ||
| 53 | "Return t if INTEGER is even." | ||
| 54 | (eq (logand integer 1) 0)) | ||
| 55 | |||
| 56 | (defun test-sequences-oddp (integer) | ||
| 57 | "Return t if INTEGER is odd." | ||
| 58 | (not (test-sequences-evenp integer))) | ||
| 59 | |||
| 60 | (ert-deftest test-setf-seq-elt () | 52 | (ert-deftest test-setf-seq-elt () |
| 61 | (with-test-sequences (seq '(1 2 3)) | 53 | (with-test-sequences (seq '(1 2 3)) |
| 62 | (setf (seq-elt seq 1) 4) | 54 | (setf (seq-elt seq 1) 4) |
| @@ -83,22 +75,22 @@ Evaluate BODY for each created sequence. | |||
| 83 | 75 | ||
| 84 | (ert-deftest test-seq-drop-while () | 76 | (ert-deftest test-seq-drop-while () |
| 85 | (with-test-sequences (seq '(1 3 2 4)) | 77 | (with-test-sequences (seq '(1 3 2 4)) |
| 86 | (should (equal (seq-drop-while #'test-sequences-oddp seq) | 78 | (should (equal (seq-drop-while #'oddp seq) |
| 87 | (seq-drop seq 2))) | 79 | (seq-drop seq 2))) |
| 88 | (should (equal (seq-drop-while #'test-sequences-evenp seq) | 80 | (should (equal (seq-drop-while #'evenp seq) |
| 89 | seq)) | 81 | seq)) |
| 90 | (should (seq-empty-p (seq-drop-while #'numberp seq)))) | 82 | (should (seq-empty-p (seq-drop-while #'numberp seq)))) |
| 91 | (with-test-sequences (seq '()) | 83 | (with-test-sequences (seq '()) |
| 92 | (should (seq-empty-p (seq-drop-while #'test-sequences-oddp seq))))) | 84 | (should (seq-empty-p (seq-drop-while #'oddp seq))))) |
| 93 | 85 | ||
| 94 | (ert-deftest test-seq-take-while () | 86 | (ert-deftest test-seq-take-while () |
| 95 | (with-test-sequences (seq '(1 3 2 4)) | 87 | (with-test-sequences (seq '(1 3 2 4)) |
| 96 | (should (equal (seq-take-while #'test-sequences-oddp seq) | 88 | (should (equal (seq-take-while #'oddp seq) |
| 97 | (seq-take seq 2))) | 89 | (seq-take seq 2))) |
| 98 | (should (seq-empty-p (seq-take-while #'test-sequences-evenp seq))) | 90 | (should (seq-empty-p (seq-take-while #'evenp seq))) |
| 99 | (should (equal (seq-take-while #'numberp seq) seq))) | 91 | (should (equal (seq-take-while #'numberp seq) seq))) |
| 100 | (with-test-sequences (seq '()) | 92 | (with-test-sequences (seq '()) |
| 101 | (should (seq-empty-p (seq-take-while #'test-sequences-oddp seq))))) | 93 | (should (seq-empty-p (seq-take-while #'oddp seq))))) |
| 102 | 94 | ||
| 103 | (ert-deftest test-seq-map-indexed () | 95 | (ert-deftest test-seq-map-indexed () |
| 104 | (should (equal (seq-map-indexed (lambda (elt i) | 96 | (should (equal (seq-map-indexed (lambda (elt i) |
| @@ -123,19 +115,19 @@ Evaluate BODY for each created sequence. | |||
| 123 | 115 | ||
| 124 | (ert-deftest test-seq-filter () | 116 | (ert-deftest test-seq-filter () |
| 125 | (with-test-sequences (seq '(6 7 8 9 10)) | 117 | (with-test-sequences (seq '(6 7 8 9 10)) |
| 126 | (should (equal (seq-filter #'test-sequences-evenp seq) '(6 8 10))) | 118 | (should (equal (seq-filter #'evenp seq) '(6 8 10))) |
| 127 | (should (equal (seq-filter #'test-sequences-oddp seq) '(7 9))) | 119 | (should (equal (seq-filter #'oddp seq) '(7 9))) |
| 128 | (should (equal (seq-filter (lambda (_) nil) seq) '()))) | 120 | (should (equal (seq-filter (lambda (_) nil) seq) '()))) |
| 129 | (with-test-sequences (seq '()) | 121 | (with-test-sequences (seq '()) |
| 130 | (should (equal (seq-filter #'test-sequences-evenp seq) '())))) | 122 | (should (equal (seq-filter #'evenp seq) '())))) |
| 131 | 123 | ||
| 132 | (ert-deftest test-seq-remove () | 124 | (ert-deftest test-seq-remove () |
| 133 | (with-test-sequences (seq '(6 7 8 9 10)) | 125 | (with-test-sequences (seq '(6 7 8 9 10)) |
| 134 | (should (equal (seq-remove #'test-sequences-evenp seq) '(7 9))) | 126 | (should (equal (seq-remove #'evenp seq) '(7 9))) |
| 135 | (should (equal (seq-remove #'test-sequences-oddp seq) '(6 8 10))) | 127 | (should (equal (seq-remove #'oddp seq) '(6 8 10))) |
| 136 | (should (same-contents-p (seq-remove (lambda (_) nil) seq) seq))) | 128 | (should (same-contents-p (seq-remove (lambda (_) nil) seq) seq))) |
| 137 | (with-test-sequences (seq '()) | 129 | (with-test-sequences (seq '()) |
| 138 | (should (equal (seq-remove #'test-sequences-evenp seq) '())))) | 130 | (should (equal (seq-remove #'evenp seq) '())))) |
| 139 | 131 | ||
| 140 | (ert-deftest test-seq-remove-at-position () | 132 | (ert-deftest test-seq-remove-at-position () |
| 141 | (with-test-sequences (seq '(1 2 3 4)) | 133 | (with-test-sequences (seq '(1 2 3 4)) |
| @@ -147,11 +139,11 @@ Evaluate BODY for each created sequence. | |||
| 147 | 139 | ||
| 148 | (ert-deftest test-seq-count () | 140 | (ert-deftest test-seq-count () |
| 149 | (with-test-sequences (seq '(6 7 8 9 10)) | 141 | (with-test-sequences (seq '(6 7 8 9 10)) |
| 150 | (should (equal (seq-count #'test-sequences-evenp seq) 3)) | 142 | (should (equal (seq-count #'evenp seq) 3)) |
| 151 | (should (equal (seq-count #'test-sequences-oddp seq) 2)) | 143 | (should (equal (seq-count #'oddp seq) 2)) |
| 152 | (should (equal (seq-count (lambda (_) nil) seq) 0))) | 144 | (should (equal (seq-count (lambda (_) nil) seq) 0))) |
| 153 | (with-test-sequences (seq '()) | 145 | (with-test-sequences (seq '()) |
| 154 | (should (equal (seq-count #'test-sequences-evenp seq) 0)))) | 146 | (should (equal (seq-count #'evenp seq) 0)))) |
| 155 | 147 | ||
| 156 | (ert-deftest test-seq-reduce () | 148 | (ert-deftest test-seq-reduce () |
| 157 | (with-test-sequences (seq '(1 2 3 4)) | 149 | (with-test-sequences (seq '(1 2 3 4)) |
| @@ -163,17 +155,17 @@ Evaluate BODY for each created sequence. | |||
| 163 | 155 | ||
| 164 | (ert-deftest test-seq-some () | 156 | (ert-deftest test-seq-some () |
| 165 | (with-test-sequences (seq '(4 3 2 1)) | 157 | (with-test-sequences (seq '(4 3 2 1)) |
| 166 | (should (seq-some #'test-sequences-evenp seq)) | 158 | (should (seq-some #'evenp seq)) |
| 167 | (should (seq-some #'test-sequences-oddp seq)) | 159 | (should (seq-some #'oddp seq)) |
| 168 | (should-not (seq-some (lambda (elt) (> elt 10)) seq))) | 160 | (should-not (seq-some (lambda (elt) (> elt 10)) seq))) |
| 169 | (with-test-sequences (seq '()) | 161 | (with-test-sequences (seq '()) |
| 170 | (should-not (seq-some #'test-sequences-oddp seq))) | 162 | (should-not (seq-some #'oddp seq))) |
| 171 | (should (seq-some #'null '(1 nil 2)))) | 163 | (should (seq-some #'null '(1 nil 2)))) |
| 172 | 164 | ||
| 173 | (ert-deftest test-seq-find () | 165 | (ert-deftest test-seq-find () |
| 174 | (with-test-sequences (seq '(4 3 2 1)) | 166 | (with-test-sequences (seq '(4 3 2 1)) |
| 175 | (should (= 4 (seq-find #'test-sequences-evenp seq))) | 167 | (should (= 4 (seq-find #'evenp seq))) |
| 176 | (should (= 3 (seq-find #'test-sequences-oddp seq))) | 168 | (should (= 3 (seq-find #'oddp seq))) |
| 177 | (should-not (seq-find (lambda (elt) (> elt 10)) seq))) | 169 | (should-not (seq-find (lambda (elt) (> elt 10)) seq))) |
| 178 | (should-not (seq-find #'null '(1 nil 2))) | 170 | (should-not (seq-find #'null '(1 nil 2))) |
| 179 | (should-not (seq-find #'null '(1 nil 2) t)) | 171 | (should-not (seq-find #'null '(1 nil 2) t)) |
| @@ -209,14 +201,14 @@ Evaluate BODY for each created sequence. | |||
| 209 | (ert-deftest test-seq-every-p () | 201 | (ert-deftest test-seq-every-p () |
| 210 | (with-test-sequences (seq '(43 54 22 1)) | 202 | (with-test-sequences (seq '(43 54 22 1)) |
| 211 | (should (seq-every-p (lambda (_) t) seq)) | 203 | (should (seq-every-p (lambda (_) t) seq)) |
| 212 | (should-not (seq-every-p #'test-sequences-oddp seq)) | 204 | (should-not (seq-every-p #'oddp seq)) |
| 213 | (should-not (seq-every-p #'test-sequences-evenp seq))) | 205 | (should-not (seq-every-p #'evenp seq))) |
| 214 | (with-test-sequences (seq '(42 54 22 2)) | 206 | (with-test-sequences (seq '(42 54 22 2)) |
| 215 | (should (seq-every-p #'test-sequences-evenp seq)) | 207 | (should (seq-every-p #'evenp seq)) |
| 216 | (should-not (seq-every-p #'test-sequences-oddp seq))) | 208 | (should-not (seq-every-p #'oddp seq))) |
| 217 | (with-test-sequences (seq '()) | 209 | (with-test-sequences (seq '()) |
| 218 | (should (seq-every-p #'identity seq)) | 210 | (should (seq-every-p #'identity seq)) |
| 219 | (should (seq-every-p #'test-sequences-evenp seq)))) | 211 | (should (seq-every-p #'evenp seq)))) |
| 220 | 212 | ||
| 221 | (ert-deftest test-seq-set-equal-p () | 213 | (ert-deftest test-seq-set-equal-p () |
| 222 | (with-test-sequences (seq1 '(1 2 3)) | 214 | (with-test-sequences (seq1 '(1 2 3)) |
| @@ -340,7 +332,7 @@ Evaluate BODY for each created sequence. | |||
| 340 | 332 | ||
| 341 | (ert-deftest test-seq-group-by () | 333 | (ert-deftest test-seq-group-by () |
| 342 | (with-test-sequences (seq '(1 2 3 4)) | 334 | (with-test-sequences (seq '(1 2 3 4)) |
| 343 | (should (equal (seq-group-by #'test-sequences-oddp seq) | 335 | (should (equal (seq-group-by #'oddp seq) |
| 344 | '((t 1 3) (nil 2 4))))) | 336 | '((t 1 3) (nil 2 4))))) |
| 345 | (should (equal (seq-group-by #'car '((a 1) (b 3) (c 4) (a 2))) | 337 | (should (equal (seq-group-by #'car '((a 1) (b 3) (c 4) (a 2))) |
| 346 | '((b (b 3)) (c (c 4)) (a (a 1) (a 2)))))) | 338 | '((b (b 3)) (c (c 4)) (a (a 1) (a 2)))))) |
diff --git a/test/lisp/eshell/em-pred-tests.el b/test/lisp/eshell/em-pred-tests.el index db8ce2c45a3..a050c6426e9 100644 --- a/test/lisp/eshell/em-pred-tests.el +++ b/test/lisp/eshell/em-pred-tests.el | |||
| @@ -142,7 +142,7 @@ behavior for real files. | |||
| 142 | (let ((attrs (eshell-parse-file-name-attributes file))) | 142 | (let ((attrs (eshell-parse-file-name-attributes file))) |
| 143 | ;; For simplicity, just return whether the file is | 143 | ;; For simplicity, just return whether the file is |
| 144 | ;; world-executable. | 144 | ;; world-executable. |
| 145 | (= (logand (or (alist-get 'modes attrs) 0) 1) 1))))) | 145 | (oddp (or (alist-get 'modes attrs) 0)))))) |
| 146 | ,@body)) | 146 | ,@body)) |
| 147 | 147 | ||
| 148 | ;;; Tests: | 148 | ;;; Tests: |
diff --git a/test/lisp/filenotify-tests.el b/test/lisp/filenotify-tests.el index 4b4f054bb33..8744dc4987a 100644 --- a/test/lisp/filenotify-tests.el +++ b/test/lisp/filenotify-tests.el | |||
| @@ -1241,7 +1241,7 @@ delivered." | |||
| 1241 | ;; It matters which direction we rename, at least for | 1241 | ;; It matters which direction we rename, at least for |
| 1242 | ;; kqueue. This backend parses directories in alphabetic | 1242 | ;; kqueue. This backend parses directories in alphabetic |
| 1243 | ;; order (x%d before y%d). So we rename into both directions. | 1243 | ;; order (x%d before y%d). So we rename into both directions. |
| 1244 | (if (zerop (mod i 2)) | 1244 | (if (evenp i) |
| 1245 | (progn | 1245 | (progn |
| 1246 | (push (expand-file-name (format "x%d" i)) source-file-list) | 1246 | (push (expand-file-name (format "x%d" i)) source-file-list) |
| 1247 | (push (expand-file-name (format "y%d" i)) target-file-list)) | 1247 | (push (expand-file-name (format "y%d" i)) target-file-list)) |
| @@ -1469,7 +1469,7 @@ the file watch." | |||
| 1469 | (make-list (/ n 2) 'created))) | 1469 | (make-list (/ n 2) 'created))) |
| 1470 | (dotimes (i n) | 1470 | (dotimes (i n) |
| 1471 | (file-notify--test-wait-event) | 1471 | (file-notify--test-wait-event) |
| 1472 | (if (zerop (mod i 2)) | 1472 | (if (evenp i) |
| 1473 | (write-region | 1473 | (write-region |
| 1474 | "any text" nil file-notify--test-tmpfile1 t 'no-message) | 1474 | "any text" nil file-notify--test-tmpfile1 t 'no-message) |
| 1475 | (let ((file-notify--test-tmpdir file-notify--test-tmpfile)) | 1475 | (let ((file-notify--test-tmpdir file-notify--test-tmpfile)) |
diff --git a/test/src/floatfns-tests.el b/test/src/floatfns-tests.el index 6820130a017..04ee97a6137 100644 --- a/test/src/floatfns-tests.el +++ b/test/src/floatfns-tests.el | |||
| @@ -120,7 +120,7 @@ | |||
| 120 | -2 -1 0 1 2)) | 120 | -2 -1 0 1 2)) |
| 121 | (should (or (<= n 0) (= (expt 0 n) 0))) | 121 | (should (or (<= n 0) (= (expt 0 n) 0))) |
| 122 | (should (= (expt 1 n) 1)) | 122 | (should (= (expt 1 n) 1)) |
| 123 | (should (or (< n 0) (= (expt -1 n) (if (zerop (logand n 1)) 1 -1)))) | 123 | (should (or (< n 0) (= (expt -1 n) (if (evenp n) 1 -1)))) |
| 124 | (should (= (expt n 0) 1)) | 124 | (should (= (expt n 0) 1)) |
| 125 | (should (= (expt n 1) n)) | 125 | (should (= (expt n 1) n)) |
| 126 | (should (= (expt n 2) (* n n))) | 126 | (should (= (expt n 2) (* n n))) |
| @@ -167,7 +167,7 @@ | |||
| 167 | (should (if (zerop r) | 167 | (should (if (zerop r) |
| 168 | (= 0 cdelta fdelta rdelta) | 168 | (= 0 cdelta fdelta rdelta) |
| 169 | (or (/= cdelta fdelta) | 169 | (or (/= cdelta fdelta) |
| 170 | (zerop (% (round n d) 2))))))))))) | 170 | (evenp (round n d))))))))))) |
| 171 | 171 | ||
| 172 | (ert-deftest special-round () | 172 | (ert-deftest special-round () |
| 173 | (dolist (f '(ceiling floor round truncate)) | 173 | (dolist (f '(ceiling floor round truncate)) |
diff --git a/test/src/undo-tests.el b/test/src/undo-tests.el index 6150e09c52e..c0984c13ea6 100644 --- a/test/src/undo-tests.el +++ b/test/src/undo-tests.el | |||
| @@ -150,7 +150,7 @@ | |||
| 150 | (with-temp-buffer | 150 | (with-temp-buffer |
| 151 | (buffer-enable-undo) | 151 | (buffer-enable-undo) |
| 152 | (dotimes (i 1048576) | 152 | (dotimes (i 1048576) |
| 153 | (if (zerop (% i 2)) | 153 | (if (evenp i) |
| 154 | (insert "Evenses") | 154 | (insert "Evenses") |
| 155 | (insert "Oddses"))) | 155 | (insert "Oddses"))) |
| 156 | (undo-boundary) | 156 | (undo-boundary) |