]> git.eshelyaron.com Git - emacs.git/commitdiff
Add another sorting unit test
authorAndrew G Cohen <cohen@andy.bu.edu>
Fri, 18 Mar 2022 13:21:29 +0000 (21:21 +0800)
committerAndrew G Cohen <cohen@andy.bu.edu>
Fri, 18 Mar 2022 13:21:29 +0000 (21:21 +0800)
* test/src/fns-tests.el (fns-tests-sort): Check for corruption should
garbage-collection occur during sorting.

test/src/fns-tests.el

index 2623b4c1b93b03a10df9308460ccb29bfc01c2dc..6e8f1a1da9b7b09f6bed47f70e79497cbbd3c11f 100644 (file)
   (should (equal
            (sort (append (make-vector 100 1) nil) (lambda (x y) (> x y)))
            (append (make-vector 100 1) nil)))
-  ;; sort a long list and vector with every pair reversed.
+  ;; Sort a long list and vector with every pair reversed.
   (let ((vec (make-vector 100000 nil))
         (logxor-vec (make-vector 100000 nil)))
     (dotimes (i 100000)
     (should (equal
              (sort (append logxor-vec nil) (lambda (x y) (< x y)))
              (append vec nil))))
-  ;; sort a list and vector with seven swaps
+  ;; Sort a list and vector with seven swaps.
   (let ((vec (make-vector 100 nil))
         (swap-vec (make-vector 100 nil)))
     (dotimes (i 100)
     (should (equal
              (sort (append swap-vec nil) (lambda (x y) (< x y)))
              (append vec nil))))
+  ;; Check for possible corruption after GC.
+  (let* ((size 3000)
+         (complex-vec (make-vector size nil))
+         (vec (make-vector size nil))
+         (counter 0)
+         (my-counter (lambda ()
+                       (if (< counter 500)
+                           (cl-incf counter)
+                         (setq counter 0)
+                         (garbage-collect))))
+         (rand 1)
+         (generate-random
+         (lambda () (setq rand
+                           (logand (+ (* rand 1103515245) 12345)  2147483647)))))
+    ;; Make a complex vector and its sorted version.
+    (dotimes (i size)
+      (let ((r (funcall generate-random)))
+        (aset complex-vec i (cons r "a"))
+        (aset vec i (cons r "a"))))
+    ;; Sort it.
+    (should (equal
+             (sort complex-vec
+                   (lambda (x y) (funcall my-counter) (< (car x) (car y))))
+             (sort complex-vec 'car-less-than-car))))
   ;; Check for sorting stability.
   (should (equal
           (sort