]> git.eshelyaron.com Git - emacs.git/commitdiff
add bubble sort into to tests
authorAndrea Corallo <andrea_corallo@yahoo.it>
Tue, 11 Jun 2019 16:56:25 +0000 (18:56 +0200)
committerAndrea Corallo <akrl@sdf.org>
Wed, 1 Jan 2020 10:33:41 +0000 (11:33 +0100)
test/src/comp-tests.el

index e7d5ca67f473c68f25b2316fc36167f3082a22de..74ed33a43cfd7758d28876024dbc17ae73227261 100644 (file)
   (should (equal (comp-tests-setcar-f '(10 . 10) 3) '(3 . 10)))
   (should (equal (comp-tests-setcdr-f '(10 . 10) 3) '(10 . 3))))
 
+(defun comp-bubble-sort ()
+  "Run bubble sort."
+  (defun comp-bubble-sort-f (list)
+    (let ((i (length list)))
+      (while (> i 1)
+        (let ((b list))
+          (while (cdr b)
+            (when (< (cadr b) (car b))
+              (setcar b (prog1 (cadr b)
+                          (setcdr b (cons (car b) (cddr b))))))
+            (setq b (cdr b))))
+        (setq i (1- i)))
+      list))
+
+  (byte-compile #'comp-bubble-sort-f)
+  (native-compile #'comp-bubble-sort-f)
+
+  (let* ((list1 (mapcar 'random (make-list 1000 most-positive-fixnum)))
+         (list2 (copy-sequence list1)))
+    (should (equal (comp-bubble-sort-f list1)
+                   (sort list2 #'<)))))
+
 (ert-deftest comp-tests-gc ()
   "Try to do some longer computation to let the gc kick in."
   (dotimes (_ 100000)