emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

scratch/timsort 186ec2f8d8: Add another sorting unit test


From: Andrew G Cohen
Subject: scratch/timsort 186ec2f8d8: Add another sorting unit test
Date: Fri, 18 Mar 2022 09:23:46 -0400 (EDT)

branch: scratch/timsort
commit 186ec2f8d828559da3d53db9122a0be0848c03c3
Author: Andrew G Cohen <cohen@andy.bu.edu>
Commit: Andrew G Cohen <cohen@andy.bu.edu>

    Add another sorting unit test
    
    * test/src/fns-tests.el (fns-tests-sort): Check for corruption should
    garbage-collection occur during sorting.
---
 test/src/fns-tests.el | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el
index 2623b4c1b9..6e8f1a1da9 100644
--- a/test/src/fns-tests.el
+++ b/test/src/fns-tests.el
@@ -219,7 +219,7 @@
   (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)
@@ -231,7 +231,7 @@
     (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)
@@ -249,6 +249,30 @@
     (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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]