diff options
Diffstat (limited to 'test/src')
| -rw-r--r-- | test/src/fns-tests.el | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el index 844000cdc76..1b13785a9fc 100644 --- a/test/src/fns-tests.el +++ b/test/src/fns-tests.el | |||
| @@ -375,6 +375,49 @@ | |||
| 375 | (should (equal (should-error (sort "cba" #'<) :type 'wrong-type-argument) | 375 | (should (equal (should-error (sort "cba" #'<) :type 'wrong-type-argument) |
| 376 | '(wrong-type-argument list-or-vector-p "cba")))) | 376 | '(wrong-type-argument list-or-vector-p "cba")))) |
| 377 | 377 | ||
| 378 | (defun fns-tests--shuffle-vector (vect) | ||
| 379 | "Shuffle VECT in place." | ||
| 380 | (let ((n (length vect))) | ||
| 381 | (dotimes (i (1- n)) | ||
| 382 | (let* ((j (+ i (random (- n i)))) | ||
| 383 | (vi (aref vect i))) | ||
| 384 | (aset vect i (aref vect j)) | ||
| 385 | (aset vect j vi))))) | ||
| 386 | |||
| 387 | (ert-deftest fns-tests-sort-kw () | ||
| 388 | ;; Test the `sort' keyword calling convention by comparing with | ||
| 389 | ;; the results from using the old (positional) style tested above. | ||
| 390 | (random "my seed") | ||
| 391 | (dolist (size '(0 1 2 3 10 100 1000)) | ||
| 392 | ;; Use a vector with both positive and negative numbers (asymmetric). | ||
| 393 | (let ((numbers (vconcat | ||
| 394 | (number-sequence (- (/ size 3)) (- size 1 (/ size 3)))))) | ||
| 395 | (fns-tests--shuffle-vector numbers) | ||
| 396 | ;; Test both list and vector input. | ||
| 397 | (dolist (input (list (append numbers nil) numbers)) | ||
| 398 | (dolist (in-place '(nil t)) | ||
| 399 | (dolist (reverse '(nil t)) | ||
| 400 | (dolist (key '(nil abs)) | ||
| 401 | (dolist (lessp '(nil >)) | ||
| 402 | (let* ((seq (copy-sequence input)) | ||
| 403 | (res (sort seq :key key :lessp lessp | ||
| 404 | :in-place in-place :reverse reverse)) | ||
| 405 | (pred (or lessp #'value<)) | ||
| 406 | (exp-in (copy-sequence input)) | ||
| 407 | (exp-out | ||
| 408 | (sort (if reverse (reverse exp-in) exp-in) | ||
| 409 | (if key | ||
| 410 | (lambda (a b) | ||
| 411 | (funcall pred | ||
| 412 | (funcall key a) (funcall key b))) | ||
| 413 | pred))) | ||
| 414 | (expected (if reverse (reverse exp-out) exp-out))) | ||
| 415 | (should (equal res expected)) | ||
| 416 | (if in-place | ||
| 417 | (should (eq res seq)) | ||
| 418 | (should-not (and (> size 0) (eq res seq))) | ||
| 419 | (should (equal seq input)))))))))))) | ||
| 420 | |||
| 378 | (defvar w32-collate-ignore-punctuation) | 421 | (defvar w32-collate-ignore-punctuation) |
| 379 | 422 | ||
| 380 | (ert-deftest fns-tests-collate-sort () | 423 | (ert-deftest fns-tests-collate-sort () |