Subject: [PATCH] New unit-tests for cl-lib

From: Ahmed Khanzada <[email-masked]>
Date: Fri, 17 Jan 2025 09:52:32 -0500

Tags: patch

In response to the concerns about cl-lib last year (or was it the year
before that?), I have written new unit tests that cover almost all cl-lib
functions without tests in the cl-lib.el, cl-extra.el, and cl-seq.el
files, with the notable exception of the tree functions. (I'll probably
do those later).

In GNU Emacs 29.4 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.41,
cairo version 1.18.0)
Windowing system distributor 'The X.Org Foundation', version 11.0.12101012
System Description: Guix System

Configured using:
 'configure
 CONFIG_SHELL=/gnu/store/6nqyia3ra10sgd1ppzk2047ncbzjwhff-bash-minimal-5.1.16/bin/bash
 SHELL=/gnu/store/6nqyia3ra10sgd1ppzk2047ncbzjwhff-bash-minimal-5.1.16/bin/bash
 --prefix=/gnu/store/i4cnvwb1hm21yd27mwb03hqwd14hck99-emacs-29.4
 --enable-fast-install --with-cairo --with-modules
 --with-native-compilation=aot --disable-build-details'

>From 5073dfd1f9812ca591068e8e39b0f1e8c0c379de Mon Sep 17 00:00:00 2001
From: Ahmed Khanzada <[email-masked]>
Date: Fri, 17 Jan 2025 09:48:57 -0500
Subject: [PATCH] New unit-tests for cl-lib

---
 test/lisp/emacs-lisp/cl-extra-tests.el | 177 +++++++
 test/lisp/emacs-lisp/cl-lib-tests.el   | 112 ++++
 test/lisp/emacs-lisp/cl-seq-tests.el   | 708 ++++++++++++++++++++++++-
 3 files changed, 996 insertions(+), 1 deletion(-)

diff --git a/test/lisp/emacs-lisp/cl-extra-tests.el b/test/lisp/emacs-lisp/cl-extra-tests.el
index b74e79aa9e0..dc1a52c9716 100644
--- a/test/lisp/emacs-lisp/cl-extra-tests.el
+++ b/test/lisp/emacs-lisp/cl-extra-tests.el
@@ -29,6 +29,33 @@
   (should (eq (cl-get 'cl-get-test 'y :none) nil))
   (should (eq (cl-get 'cl-get-test 'z :none) :none)))
 
+(ert-deftest cl-extra-test-coerce ()
+  (should (equal (cl-coerce "abc" 'list) '(?a ?b ?c)))
+  (should (equal (cl-coerce ["a" "b" "c"] 'list) '("a" "b" "c")))
+  (should (equal (cl-coerce "abc" 'vector) [97 98 99]))
+  (should (equal (cl-coerce '("a" "b" "c") 'vector) ["a" "b" "c"]))
+  (should (equal (cl-coerce '(3 4) 'bool-vector) #&2""))
+  (should (equal (cl-coerce "abc" 'bool-vector) #&3""))
+  (should (equal (cl-coerce [1] 'string) (char-to-string 1)))
+  (should (equal (cl-coerce '(1) 'string) (char-to-string 1)))
+  (should (equal (cl-coerce '(1 2 3) 'array) [1 2 3]))
+  (should (equal (cl-coerce "abc" 'array) "abc"))
+  (should-error (cl-coerce (list 1 2 3) 'character))
+  (should-error (cl-coerce [1 2 3] 'character))
+  (should-error (cl-coerce "abc" 'character))
+  (should (equal (cl-coerce "a" 'character) 97))
+  (should (equal (cl-coerce 'a 'character) 97)))
+
+(ert-deftest cl-extra-test-equalp ()
+  (should (cl-equalp "Test" "test"))
+  (should (cl-equalp 1 1.0))
+  (should (cl-equalp '(1 2 3) '(1 2 3)))
+  (should (cl-equalp [1 2 3] [1 2 3]))
+  (should-not (cl-equalp "Test1" "Test2"))
+  (should-not (cl-equalp 1 2))
+  (should-not (cl-equalp '(1 2 3) '(4 5 6)))
+  (should-not (cl-equalp [1 2 3] [4 5 6])))
+
 (ert-deftest cl-getf ()
   (let ((plist '(x 1 y nil)))
     (should (eq (cl-getf plist 'x) 1))
@@ -127,4 +154,154 @@
   (should (equal (cl-concatenate 'string "123" "456")
                  "123456")))
 
+(ert-deftest cl-extra-test-mapcan ()
+  (should (equal (cl-mapcan #'list '(1 2 3)) '(1 2 3)))
+  (should (equal (cl-mapcan #'list '(1 2 3) '(4 5 6)) '(1 4 2 5 3 6)))
+  (should (equal (cl-mapcan #'list '(1 2) '(3 4 5)) '(1 3 2 4)))
+  (should (equal (cl-mapcan #'list '(1 2 3) "#$%") '(1 ?# 2 ?$ 3 ?%)))
+  (should (equal (cl-mapcan #'list '()) '()))
+  (should (equal (cl-mapcan #'list '() '()) '())))
+
+(ert-deftest cl-extra-test-mapcon ()
+  (should (equal (cl-mapcon #'list '(1 2 3)) '((1 2 3) (2 3) (3))))
+  (should (equal (cl-mapcon #'list '()) nil))
+  (should (equal (cl-mapcon #'list '() '()) nil)))
+
+(ert-deftest cl-extra-test-some ()
+  (should (equal (cl-some #'identity (list nil nil "foo")) "foo"))
+  (should (equal (cl-some #'identity [nil nil nil]) nil))
+  (should (equal (cl-some (lambda (a b) (> (+ a b) 198)) (list ?a ?b ?c) "abcz") nil))
+  (should (equal (cl-some (lambda (a b) (> (+ a b) 198)) (list ?a ?b ?c) "abz") t)))
+
+(ert-deftest cl-extra-test-every ()
+  (should (equal (cl-every #'identity (list t 42 "foo")) t))
+  (should (equal (cl-every #'identity [t nil "foo"]) nil))
+  (should (equal (cl-every (lambda (a b) (<= (+ a b) 198))
+                           (list ?a ?b ?c) "abcz")
+                 t))
+  (should (equal (cl-every (lambda (a b) (<= (+ a b) 198))
+                           (list ?a ?b ?c) "abz")
+                 nil)))
+
+(ert-deftest cl-extra-test-notany ()
+  (should (equal (cl-notany #'oddp '(1 3 5)) nil))
+  (should (equal (cl-notany #'oddp '(2 4 6)) t))
+  (should (equal (cl-notany #'oddp '(1 2 3 4 5)) nil)))
+
+(ert-deftest cl-extra-test-notevery ()
+  (should (equal (cl-notevery #'oddp '(1 3 5)) nil))
+  (should (equal (cl-notevery #'oddp '(2 4 6)) t))
+  (should (equal (cl-notevery #'oddp '(1 2 3 4 5)) t)))
+
+(ert-deftest cl-extra-test-gcd ()
+  (should (equal (cl-gcd 4) 4))
+  (should (equal (cl-gcd 3 5) 1))
+  (should (equal (cl-gcd 4 8) 4))
+  (should (equal (cl-gcd 3 5 7) 1))
+  (should (equal (cl-gcd 4 8 12) 4))
+  (should (equal (cl-gcd 0) 0))
+  (should (equal (cl-gcd 4 0) 4))
+  (should (equal (cl-gcd 0 0) 0)))
+
+(ert-deftest cl-extra-test-lcm ()
+  (should (equal (cl-lcm 4) 4))
+  (should (equal (cl-lcm 3 5) 15))
+  (should (equal (cl-lcm 4 8) 8))
+  (should (equal (cl-lcm 3 5 7) 105))
+  (should (equal (cl-lcm 4 8 12) 24))
+  (should (equal (cl-lcm 0 4) 0))
+  (should (equal (cl-lcm 0 0) 0))
+  (should (equal (cl-lcm) 1)))
+
+(ert-deftest cl-extra-test-isqrt ()
+  (should (equal (cl-isqrt 4) 2))
+  (should (equal (cl-isqrt 100) 10))
+  (should (equal (cl-isqrt 1) 1))
+  (should (equal (cl-isqrt 0) 0))
+  (should (equal (cl-isqrt 3) 1))
+  (should (equal (cl-isqrt 10) 3))
+  (should-error (cl-isqrt -4))
+  (should-error (cl-isqrt 2.5)))
+
+(ert-deftest cl-extra-test-floor ()
+  (should (equal (cl-floor 4.5) '(4 0.5)))
+  (should (equal (cl-floor 10 3) '(3 1))))
+
+(ert-deftest cl-extra-test-ceiling ()
+  (should (equal (cl-ceiling 4.5) '(5 -0.5)))
+  (should (equal (cl-ceiling 10 3) '(4 -2))))
+
+(ert-deftest cl-extra-test-truncate ()
+  (should (equal (cl-truncate 4.5) '(4 0.5)))
+  (should (equal (cl-truncate 10 3) '(3 1))))
+
+(ert-deftest cl-extra-test-round ()
+  (should (equal (cl-round 4.5) '(4 0.5)))
+  (should (equal (cl-round 10 3) '(3 1)))
+  (should (equal (cl-round 1.5) '(2 -0.5)))
+  (should (equal (cl-round 2.5) '(2 0.5))))
+
+(ert-deftest cl-extra-test-mod ()
+  (should (equal (cl-mod 10 3) 1))
+  (should (equal (cl-mod -10 -3) -1))
+  (should (equal (cl-mod -10 3) 2))
+  (should (equal (cl-mod 10 -3) -2)))
+
+(ert-deftest cl-extra-test-rem ()
+  (should (equal (cl-rem 10 3) 1))
+  (should (equal (cl-rem -10 -3) -1))
+  (should (equal (cl-rem -10 3) -1))
+  (should (equal (cl-rem 10 -3) 1)))
+
+(ert-deftest cl-extra-test-signum ()
+  (should (equal (cl-signum 10) 1))
+  (should (equal (cl-signum -10) -1))
+  (should (equal (cl-signum 0) 0)))
+
+(ert-deftest cl-extra-test-parse-integer ()
+  (should (equal (cl-parse-integer "10") 10))
+  (should (equal (cl-parse-integer "-10") -10))
+  (should (equal (cl-parse-integer "+10") 10))
+  (should (equal (cl-parse-integer "ff" :radix 16) 255))
+  (should (equal (cl-parse-integer "11" :start 1) 1))
+  (should (equal (cl-parse-integer "abc def" :end 3 :junk-allowed t) nil)))
+
+(ert-deftest cl-extra-test-subseq ()
+  (should (equal (cl-subseq "hello" 1) "ello"))
+  (should (equal (cl-subseq "hello" 1 4) "ell"))
+  (should (equal (cl-subseq "hello" -1) "o"))
+  (should (equal (cl-subseq "hello world" -5 -1) "worl"))
+  (should (equal (cl-subseq '(1 2 3 4 5) 2) '(3 4 5)))
+  (should (equal (cl-subseq '(1 2 3 4 5) 1 3) '(2 3))))
+
+(ert-deftest cl-extra-test-concatenate ()
+  (should (equal (cl-concatenate 'string "hello " "world") "hello world"))
+  (should (equal (cl-concatenate 'list '(1 2) '(3 4) '(5 6)) '(1 2 3 4 5 6))))
+
+(ert-deftest cl-extra-test-revappend ()
+  (should (equal (cl-revappend '(1 2 3) '(4 5 6)) '(3 2 1 4 5 6))))
+
+(ert-deftest cl-extra-test-nreconc ()
+  (should (equal (cl-nreconc '(1 2 3) '(4 5 6)) '(3 2 1 4 5 6))))
+
+(ert-deftest cl-extra-test-list-length ()
+  (should (equal (cl-list-length '(1 2 3)) 3))
+  (should (equal (cl-list-length '()) 0))
+  (let ((xl (number-sequence 1 100)))
+    (setcdr (nthcdr 99 xl) xl)
+    (should (equal (cl-list-length xl) nil))))
+
+(ert-deftest cl-extra-test-tailp ()
+  (let ((l '(1 2 3 4 5)))
+    (should (cl-tailp (nthcdr 2 l) l))
+    (should (cl-tailp l l))
+    (should (not (cl-tailp '(4 5) l)))))
+
+(ert-deftest cl-extra-test-remprop ()
+  (let ((sym (make-symbol "test")))
+    (put sym 'foo 'bar)
+    (should (equal (cl-get sym 'foo) 'bar))
+    (cl-remprop sym 'foo)
+    (should (equal (cl-get sym 'foo 'default) 'default))))
+
 ;;; cl-extra-tests.el ends here
diff --git a/test/lisp/emacs-lisp/cl-lib-tests.el b/test/lisp/emacs-lisp/cl-lib-tests.el
index a9c71fa5808..ff860d94468 100644
--- a/test/lisp/emacs-lisp/cl-lib-tests.el
+++ b/test/lisp/emacs-lisp/cl-lib-tests.el
@@ -242,6 +242,42 @@
     (should (= (cl-the integer (cl-incf side-effect)) 1))
     (should (= side-effect 1))))
 
+(ert-deftest cl-lib-test-pushnew ()
+  (let ((list '(1 2 3)))
+    (cl-pushnew 0 list)
+    (should (equal list '(0 1 2 3))))
+  (let ((list '((1 2) (3 4))))
+    (cl-pushnew '(3 7) list :key #'cdr)
+    (should (equal list '((3 7) (1 2) (3 4)) )))
+  (let ((list '((1 2) (3 4))))
+    (cl-pushnew '(3 7) list :key #'car)
+    (should (equal list '((1 2) (3 4)))))
+  (let ((list '((1 2) (3 4))))
+    (cl-pushnew '(3 4) list :test #'equal)
+    (should (equal list '((1 2) (3 4)))))
+  (let ((list '((1 2) (3 4))))
+    (cl-pushnew '(3 5) list :test #'equal)
+    (should (equal list '((3 5) (1 2) (3 4)))))
+  (let ((list '((1 2) (3 4))))
+    (cl-pushnew '(3 4) list :test-not #'equal)
+    (should (equal list '((1 2) (3 4)))))
+  (let ((list '((1 2) (3 4))))
+    (cl-pushnew '(3 5) list :test-not #'equal)
+    (should (equal list '((1 2) (3 4))))))
+
+(ert-deftest cl-lib-test-values-list ()
+  (let ((list '(:a :b :c)))
+    (should (equal (cl-values-list list) '(:a :b :c))))
+  (let ((not-a-list :a))
+    (should-error (cl-values-list not-a-list) :type 'wrong-type-argument)))
+
+(ert-deftest cl-lib-multiple-value-list ()
+  (should (equal (cl-multiple-value-list 1) 1))
+  (should (equal (cl-multiple-value-list '(1 2 3)) '(1 2 3)))
+  (should (equal (cl-multiple-value-list "string") "string"))
+  (should (equal (cl-multiple-value-list nil) nil))
+  (should (equal (cl-multiple-value-list (list 1 2 3)) '(1 2 3))))
+
 (ert-deftest cl-lib-test-incf ()
   (let ((var 0))
     (should (= (cl-incf var) 1))
@@ -388,6 +424,50 @@
   (should (= 10 (cl-tenth '(1 2 3 4 5 6 7 8 9 10 11))))
   (should-error (cl-tenth "1234567890") :type 'wrong-type-argument))
 
+(ert-deftest cl-lib-test-mapcar ()
+  (should (equal (cl-mapcar #'1+ '(1 2 3)) '(2 3 4)))
+  (should (equal (cl-mapcar #'+ '(1 2 3) '(4 5 6)) '(5 7 9)))
+  (should (equal (cl-mapcar #'+ '(1 2 3) '(4 5)) '(5 7)))
+  (should (equal (cl-mapcar #'+ '() '()) '()))
+  (should-error (cl-mapcar #'+ 1 '(4 5 6)))
+  (should-error (cl-mapcar #'+ '(1 2 3) 4)))
+
+(ert-deftest cl-lib-test-list* ()
+  (should (equal (cl-list* 'a) 'a))
+  (should (equal (cl-list* 'a 'b) '(a . b)))
+  (should (equal (cl-list* 'a 'b 'c 'd) '(a b c . d)))
+  (should (equal (cl-list* 'a 'b '(c d)) '(a b c d))))
+
+(ert-deftest cl-lib-test-copy-list ()
+  (let ((original '(1 2 . 3))
+        (result (cl-copy-list '(1 2 . 3))))
+    (and (should (equal original result))
+         (not (eq original result)))))
+
+(ert-deftest cl-lib-test-subst ()
+  (should (equal (cl-subst 'x 'a '(a b c)) '(x b c)))
+  (should (equal (cl-subst 'x 'a '(a b a c)) '(x b x c)))
+  (should (equal (cl-subst 'x 'a '(b c d)) '(b c d)))
+  (should (equal (cl-subst 'x 'a '(a b (a c) d)) '(x b (x c) d)))
+  (should (equal (cl-subst "a" "A" '("a" "b" "c" "a") :test #'equal) '("a" "b" "c" "a"))))
+
+(ert-deftest cl-lib-test-acons ()
+  (should (equal (cl-acons 'key 'value '()) '((key . value))))
+  (should (equal (cl-acons 'key 'value '((a . 1) (b . 2))) '((key . value) (a . 1) (b . 2))))
+  (should (equal (cl-acons 'a 1 '((a . 1) (b . 2))) '((a . 1) (a . 1) (b . 2))))
+  (should (equal (cl-acons nil 'value '((a . 1) (b . 2))) '((nil . value) (a . 1) (b . 2))))
+  (should (equal (cl-acons 'key nil '((a . 1) (b . 2))) '((key . nil) (a . 1) (b . 2)))))
+
+(ert-deftest cl-lib-test-pairlis ()
+  (should (equal (cl-pairlis '(a b c) '(1 2 3)) '((a . 1) (b . 2) (c . 3))))
+  (should (equal (cl-pairlis '(a b c d) '(1 2 3)) '((a . 1) (b . 2) (c . 3))))
+  (should (equal (cl-pairlis '(a b c) '(1 2 3 4)) '((a . 1) (b . 2) (c . 3))))
+  (should (equal (cl-pairlis '(a b c) '(1 2 3) '((d . 4) (e . 5))) '((a . 1) (b . 2) (c . 3) (d . 4) (e . 5))))
+  (should (equal (cl-pairlis '() '(1 2 3)) '()))
+  (should (equal (cl-pairlis '(a b c) '()) '()))
+  (should (equal (cl-pairlis '(a nil c) '(1 2 3)) '((a . 1) (nil . 2) (c . 3))))
+  (should (equal (cl-pairlis '(a b c) '(1 nil 3)) '((a . 1) (b) (c . 3)))))
+
 (ert-deftest cl-lib-test-endp ()
   (should (cl-endp '()))
   (should-not (cl-endp '(1)))
@@ -558,5 +638,37 @@
   (should (equal (mapcar (cl-constantly 3) '(a b c d))
                  '(3 3 3 3))))
 
+(ert-deftest cl-lib-set-difference ()
+  ;; our set-difference preserves order, though it is not required to
+  ;; by cl standards. Nevertheless better keep that invariant
+  (should (equal (cl-set-difference '(1 2 3 4) '(3 4 5 6))
+                 '(1 2))))
+
+(ert-deftest cl-nset-difference ()
+  ;; our nset-difference doesn't
+  (let* ((l1 (list 1 2 3 4)) (l2 '(3 4 5 6))
+         (diff (cl-nset-difference l1 l2)))
+    (should (memq 1 diff))
+    (should (memq 2 diff))
+    (should (= (length diff) 2))
+    (should (equal l2 '(3 4 5 6))))
+  (let* ((l1 (list "1" "2" "3" "4")) (l2 '("3" "4" "5" "6"))
+         (diff (cl-nset-difference l1 l2 :test #'equal)))
+    (should (member "1" diff))
+    (should (member "2" diff))
+    (should (= (length diff) 2))
+    (should (equal l2 '("3" "4" "5" "6"))))
+  (let* ((l1 (list '(a . 1) '(b . 2) '(c . 3) '(d . 4)))
+         (l2 (list '(c . 3) '(d . 4) '(e . 5) '(f . 6)))
+         (diff (cl-nset-difference l1 l2 :key #'car)))
+    (should (member '(a . 1) diff))
+    (should (member '(b . 2) diff))
+    (should (= (length diff) 2)))
+  (let* ((l1 (list '("a" . 1) '("b" . 2) '("c" . 3) '("d" . 4)))
+         (l2 (list '("c" . 3) '("d" . 4) '("e" . 5) '("f" . 6)))
+         (diff (cl-nset-difference l1 l2 :key #'car :test #'string=)))
+    (should (member '("a" . 1) diff))
+    (should (member '("b" . 2) diff))
+    (should (= (length diff) 2))))
 
 ;;; cl-lib-tests.el ends here
diff --git a/test/lisp/emacs-lisp/cl-seq-tests.el b/test/lisp/emacs-lisp/cl-seq-tests.el
index 9c62379d857..59ece0e4006 100644
--- a/test/lisp/emacs-lisp/cl-seq-tests.el
+++ b/test/lisp/emacs-lisp/cl-seq-tests.el
@@ -59,6 +59,22 @@ Body are forms defining the test."
          (when ,list2
            (setq cl-seq--test-list2 ,orig2))))))
 
+(ert-deftest cl-seq-endp-test ()
+  (should (cl-endp '()))
+  (should (not (cl-endp '(1 2 3))))
+  (should-error (cl-endp 42) :type 'wrong-type-argument))
+
+(ert-deftest cl-seq-reduce-test ()
+  (should (equal 6 (cl-reduce #'+ '(1 2 3))))
+  (should (equal 5 (cl-reduce #'+ '(1 2 3 4) :start 1 :end 3)))
+  (should (equal 10 (cl-reduce #'+ '(1 2 3 4) :from-end t)))
+  (should (equal 10 (cl-reduce #'+ '(1 2 3 4) :initial-value 0)))
+  (should (equal 24 (cl-reduce #'* '(1 2 3 4) :initial-value 1)))
+  (should (equal 0 (cl-reduce #'+ '())))
+  (should (equal 0 (cl-reduce #'+ '() :initial-value 0)))
+  (should (equal 1 (cl-reduce #'+ '(1))))
+  (should (equal 0 (cl-reduce #'+ '() :initial-value 0))))
+
 ;; keywords supported:  :start :end
 (ert-deftest cl-seq-fill-test ()
   (let* ((cl-seq--test-list '(1 2 3 4 5 2 6))
@@ -116,6 +132,25 @@ Body are forms defining the test."
     (should (equal '(1 3 4 5 2 6) (cl-remove 2 list :from-end nil :count 1)))
     (should (equal '(1 2 3 4 5 6) (cl-remove 2 list :from-end t :count 1)))))
 
+(ert-deftest cl-remove-if-test ()
+  (should (equal '(1 3) (cl-remove-if 'evenp '(1 2 3 4))))
+  (should (equal '(1 3) (cl-remove-if 'evenp '(1 2 3 4) :count 2)))
+  (should (equal '(1 3 4) (cl-remove-if 'evenp '(1 2 3 4) :start 1 :end 3)))
+  (should (equal '(1 3) (cl-remove-if 'evenp '(1 2 3 4) :from-end t)))
+  (should (equal '(2 4) (cl-remove-if 'oddp '(1 2 3 4))))
+  (should (equal '() (cl-remove-if 'evenp '())))
+  (should (equal '() (cl-remove-if 'evenp '(2)))))
+
+(ert-deftest cl-remove-if-not-test ()
+  (should (equal '(2 4) (cl-remove-if-not 'evenp '(1 2 3 4))))
+  (should (equal '(2 4) (cl-remove-if-not 'evenp '(1 2 3 4) :count 2)))
+  (should (equal '(1 2 4) (cl-remove-if-not 'evenp '(1 2 3 4) :start 1 :end 3)))
+  (should (equal '(2 4) (cl-remove-if-not 'evenp '(1 2 3 4) :from-end t)))
+  (should (equal '(1 3) (cl-remove-if-not 'oddp '(1 2 3 4))))
+  (should (equal '() (cl-remove-if-not 'evenp '())))
+  (should (equal '(2) (cl-remove-if-not 'evenp '(2))))
+  (should (equal '(2) (cl-remove-if-not 'evenp '(2) :key #'(lambda (x) (- x))))))
+
 ;; keywords supported:  :test :test-not :key :count :start :end :from-end
 (ert-deftest cl-seq-delete-test ()
   (let* ((cl-seq--test-list '(1 2 3 4 5 2 6))
@@ -139,6 +174,27 @@ Body are forms defining the test."
         (cl-seq--with-side-effects orig nil
           test)))))
 
+(ert-deftest cl-delete-if-test ()
+  (let ((list (list 1 2 3 4 5)))
+    (cl-delete-if 'evenp list)
+    (should (equal '(1 3 5) list))
+    (should (equal '(1 3 5) (cl-delete-if 'evenp (list 1 2 3 4 5) :start 0 :end 4)))
+    (should (equal '(1 3 5) (cl-delete-if 'evenp (list 1 2 3 4 5) :from-end t)))
+    (should (equal '(2 4) (cl-delete-if 'oddp (list 1 2 3 4 5))))
+    (should (equal '() (cl-delete-if 'evenp '())))
+    (should (equal '() (cl-delete-if 'evenp (list 2))))))
+
+(ert-deftest cl-delete-if-not-test ()
+  (let ((list (list 1 2 3 4 5)))
+    (should (equal '(2 4) (cl-delete-if-not 'evenp list)))
+    (should (equal '() (cl-delete-if-not 'evenp '())))
+    (should (equal '() (cl-delete-if-not 'evenp (list 1))))))
+
+(ert-deftest cl-delete-duplicates-test ()
+  (let ((list (list 1 2 3 2 1)))
+    (should (equal '(3 2 1) (cl-delete-duplicates list)))
+    (should (equal '() (cl-delete-duplicates '())))))
+
 ;; keywords supported:  :test :test-not :key :start :end :from-end
 (ert-deftest cl-seq-remove-duplicates-test ()
   (let ((list '(1 2 3 4 5 2 6)))
@@ -185,6 +241,65 @@ Body are forms defining the test."
     (should (equal '(b 2 3 4 5 2 6) (cl-substitute 'b nil list
                                                    :if-not (lambda (x) (> (cl-position x list :from-end t) 1)))))))
 
+(ert-deftest cl-seq-substitute-if-test ()
+  (let ((result (cl-substitute-if 'x #'evenp '(1 2 3 4 5))))
+    (should (equal result '(1 x 3 x 5))))
+  (let ((result (cl-substitute-if 'x #'evenp '(1 3 5))))
+    (should (equal result '(1 3 5))))
+  (let ((result (cl-substitute-if 'x #'(lambda (n) t) '(1 2 3 4 5))))
+    (should (equal result '(x x x x x))))
+  (let ((result (cl-substitute-if 'x #'evenp '(1 2 3 4 5) :start 1 :end 4)))
+    (should (equal result '(1 x 3 x 5))))
+  (let ((result (cl-substitute-if 'x #'oddp '(1 2 3 4 5) :from-end t)))
+    (should (equal result '(x 2 x 4 x))))
+  (let ((result (cl-substitute-if 'x (lambda (n) (= n 3)) '(1 2 3 4 5) :key 'identity)))
+    (should (equal result '(1 2 x 4 5)))))
+
+(ert-deftest cl-seq-substitute-if-not-test ()
+  (let ((result (cl-substitute-if-not 'x #'evenp '(1 2 3 4 5))))
+    (should (equal result '(x 2 x 4 x))))
+  (let ((result (cl-substitute-if-not 'x #'evenp '(2 4 6))))
+    (should (equal result '(2 4 6))))
+  (let ((result (cl-substitute-if-not 'x #'(lambda (n) (> n 5)) '(1 2 3 4 5))))
+    (should (equal result '(x x x x x))))
+  (let ((result (cl-substitute-if-not 'x #'evenp '(1 2 3 4 5) :start 0 :end 4)))
+    (should (equal result '(x 2 x 4 5))))
+  (let ((result (cl-substitute-if-not 'x #'oddp '(1 2 3 4 5) :from-end t)))
+    (should (equal result '(1 x 3 x 5))))
+  (let ((result (cl-substitute-if-not 'x (lambda (n) (= n 3)) '(1 2 3 4 5) :key 'identity)))
+    (should (equal result '(x x 3 x x)))))
+
+(ert-deftest cl-find-if-test ()
+  (let ((result (cl-find-if #'evenp '(1 2 3 4 5))))
+    (should (equal result 2)))
+  (let ((result (cl-find-if #'(lambda (n) (> n 5)) '(1 2 3 4 5))))
+    (should (equal result nil)))
+  (let ((result (cl-find-if #'(lambda (n) (> n 3)) '(1 2 3 4 5 6 7))))
+    (should (equal result 4)))
+  (let ((result (cl-find-if #'evenp '(1 2 3 4 5) :start 2)))
+    (should (equal result 4)))
+  (let ((result (cl-find-if #'evenp '(1 2 3 4 5) :end 1)))
+    (should (equal result nil)))
+  (let ((result (cl-find-if #'oddp '(2 4 5 6 7) :from-end t)))
+    (should (equal result 7)))
+  (let ((result (cl-find-if (lambda (n) (= n 4)) '(1 2 3 4 5) :key 'identity)))
+    (should (equal result 4))))
+
+(ert-deftest cl-find-if-not-test ()
+  (let ((result (cl-find-if-not #'evenp '(1 2 3 4 5))))
+    (should (equal result 1)))
+  (let ((result (cl-find-if-not #'oddp '(1 3 5))))
+    (should (equal result nil)))
+  (let ((result (cl-find-if-not #'(lambda (n) (< n 4)) '(1 2 3 4 5 6 7))))
+    (should (equal result 4)))
+  (let ((result (cl-find-if-not #'evenp '(1 2 3 4 5) :start 2)))
+    (should (equal result 3)))
+  (let ((result (cl-find-if-not #'evenp '(1 2 3 4 5) :end 3)))
+    (should (equal result 1)))
+  (let ((result (cl-find-if-not #'oddp '(2 4 6 7 8) :from-end t)))
+    (should (equal result 8)))
+  (let ((result (cl-find-if-not (lambda (n) (= n 4)) '(1 2 3 4 5) :key 'identity)))
+    (should (equal result 1))))
 
 ;; keywords supported:  :test :test-not :key :count :start :end :from-end
 (ert-deftest cl-seq-nsubstitute-test ()
@@ -221,7 +336,7 @@ Body are forms defining the test."
     (dolist (test tests)
       (let ((_list cl-seq--test-list))
         (cl-seq--with-side-effects orig nil
-                                   test)))))
+          test)))))
 
 ;; keywords supported:  :test :test-not :key :start :end :from-end
 (ert-deftest cl-seq-position-test ()
@@ -241,6 +356,22 @@ Body are forms defining the test."
     (should (= 1 (cl-position 5 list :key (lambda (x) (1+ (* x x))))))
     (should (= 5 (cl-position 5 list :key (lambda (x) (1+ (* x x))) :from-end t)))))
 
+(ert-deftest cl-position-if-test ()
+  (let ((result (cl-position-if #'evenp '(1 2 3 4 5))))
+    (should (equal result 1)))
+  (let ((result (cl-position-if #'(lambda (n) (> n 5)) '(1 2 3 4 5))))
+    (should (equal result nil)))
+  (let ((result (cl-position-if #'(lambda (n) (> n 3)) '(1 2 3 4 5 6 7))))
+    (should (equal result 3)))
+  (let ((result (cl-position-if #'evenp '(1 2 3 4 5) :start 2)))
+    (should (equal result 3)))
+  (let ((result (cl-position-if #'evenp '(1 2 3 4 5) :end 1)))
+    (should (equal result nil)))
+  (let ((result (cl-position-if #'oddp '(2 4 5 6 7) :from-end t)))
+    (should (equal result 4)))
+  (let ((result (cl-position-if (lambda (n) (= n 4)) '(1 2 3 4 5) :key 'identity)))
+    (should (equal result 3))))
+
 ;; keywords supported:  :test :test-not :key :start :end
 (ert-deftest cl-seq-count-test ()
   (let ((list '(1 2 3 4 5 2 6)))
@@ -254,6 +385,50 @@ Body are forms defining the test."
     (should (equal (cl-count 'foo list :test (lambda (_a b) (cl-oddp b)))
                    (cl-count 'foo list :test-not (lambda (_a b) (cl-evenp b)))))))
 
+(ert-deftest cl-count-if-test ()
+  (let ((result (cl-count-if #'evenp '(1 2 3 4 5))))
+    (should (equal result 2)))
+  (let ((result (cl-count-if #'oddp '(2 4 6 8))))
+    (should (equal result 0)))
+  (let ((result (cl-count-if (lambda (x) t) '(1 2 3 4))))
+    (should (equal result 4)))
+  (let ((result (cl-count-if (lambda (x) nil) '(1 2 3 4))))
+    (should (equal result 0)))
+  (let ((result (cl-count-if #'(lambda (x) (> x 2)) '(1 2 3 4 5) :key 'identity)))
+    (should (equal result 3)))
+  (let ((result (cl-count-if #'evenp '(1 2 3 4 5) :start 2)))
+    (should (equal result 1)))
+  (let ((result (cl-count-if #'evenp '(1 2 3 4 5) :end 3)))
+    (should (equal result 1)))
+  (let ((result (cl-count-if #'evenp '())))
+    (should (equal result 0)))
+  (let ((result (cl-count-if #'(lambda (x) (numberp x)) '(1 "two" 3 4 "five" 6))))
+    (should (equal result 4)))
+  (let ((result (cl-count-if (lambda (x) (and (numberp x) (> x 2))) '(1 2 3 4 5 6))))
+    (should (equal result 4))))
+
+(ert-deftest cl-count-if-not-test ()
+  (let ((result (cl-count-if-not #'evenp '(1 2 3 4 5))))
+    (should (equal result 3)))
+  (let ((result (cl-count-if-not #'oddp '(1 3 5))))
+    (should (equal result 0)))
+  (let ((result (cl-count-if-not (lambda (x) t) '(1 2 3 4))))
+    (should (equal result 0)))
+  (let ((result (cl-count-if-not (lambda (x) nil) '(1 2 3 4))))
+    (should (equal result 4)))
+  (let ((result (cl-count-if-not #'(lambda (x) (> x 3)) '(1 2 3 4 5) :key 'identity)))
+    (should (equal result 3)))
+  (let ((result (cl-count-if-not #'evenp '(1 2 3 4 5) :start 2)))
+    (should (equal result 2)))
+  (let ((result (cl-count-if-not #'evenp '(1 2 3 4 5) :end 3)))
+    (should (equal result 2)))
+  (let ((result (cl-count-if-not #'evenp '())))
+    (should (equal result 0)))
+  (let ((result (cl-count-if-not #'(lambda (x) (numberp x)) '(1 "two" 3 4 "five" 6))))
+    (should (equal result 2)))
+  (let ((result (cl-count-if-not (lambda (x) (and (numberp x) (> x 2))) '(1 2 3 4 5 6))))
+    (should (equal result 2))))
+
 ;; keywords supported:  :test :test-not :key :start1 :end1 :start2 :end2 :from-end
 (ert-deftest cl-seq-mismatch-test ()
   (let ((list '(1 2 3 4 5 2 6))
@@ -312,5 +487,536 @@ Body are forms defining the test."
       (should (eq (cl-assoc x a) (car a)))
       (should (eq (cl-rassoc x a) (cadr a))))))
 
+(ert-deftest cl-sort-test ()
+  (let ((result (cl-sort '(3 1 4 1 5 9 2 6 5 3 5) '<)))
+    (should (equal result '(1 1 2 3 3 4 5 5 5 6 9))))
+  (let ((result (cl-sort '(5 3 2 8 1 4) '>)))
+    (should (equal result '(8 5 4 3 2 1))))
+  (let ((result (cl-sort '("banana" "apple" "cherry") 'string<)))
+    (should (equal result '("apple" "banana" "cherry"))))
+  (let ((result (cl-sort '("banana" "fig" "apple" "kiwi") (lambda (x y) (< (length x) (length y))) :key 'identity)))
+    (should (equal result '("fig" "kiwi" "apple" "banana"))))
+  (let ((result (cl-sort (vector 3 1 4 1 5) '<)))
+    (should (equal result (vector 1 1 3 4 5))))
+  (let ((result (cl-sort '(1 2 3 4 5) '<)))
+    (should (equal result '(1 2 3 4 5))))
+  (let ((result (cl-sort '(-3 1 4 -1 -5 9) '<)))
+    (should (equal result '(-5 -3 -1 1 4 9))))
+  (let ((result (cl-sort '(1 2 3 4 5) (lambda (x y) (> x y)))))
+    (should (equal result '(5 4 3 2 1))))
+  (let ((result (cl-sort '() '<)))
+    (should (equal result '())))
+  (let ((result (cl-sort '("Banana" "apple" "cherry") 'string< :key 'downcase)))
+    (should (equal result '("apple" "Banana" "cherry")))) )
+
+(ert-deftest cl-stable-sort-test ()
+  (let ((result (cl-stable-sort '(3 1 4 1 5 9 2 6 5 3 5) '<)))
+    (should (equal result '(1 1 2 3 3 4 5 5 5 6 9))))
+  (let ((result (cl-stable-sort '(5 3 2 8 1 4) '>)))
+    (should (equal result '(8 5 4 3 2 1))))
+  (let ((result (cl-stable-sort '("banana" "apple" "cherry") 'string<)))
+    (should (equal result '("apple" "banana" "cherry"))))
+  (let ((result (cl-stable-sort '("banana" "fig" "apple" "kiwi") (lambda (x y) (< (length x) (length y))) :key 'identity)))
+    (should (equal result '("fig" "kiwi" "apple" "banana"))))
+  (let ((result (cl-stable-sort (vector 3 1 4 1 5) '<)))
+    (should (equal result (vector 1 1 3 4 5))))
+  (let ((result (cl-stable-sort '(1 2 3 4 5) '<)))
+    (should (equal result '(1 2 3 4 5))))
+  (let ((result (cl-stable-sort '(-3 1 4 -1 -5 9) '<)))
+    (should (equal result '(-5 -3 -1 1 4 9))))
+  (let ((result (cl-stable-sort '(1 2 3 4 5) (lambda (x y) (> x y)))))
+    (should (equal result '(5 4 3 2 1))))
+  (let ((result (cl-stable-sort '() '<)))
+    (should (equal result '())))
+  (let ((result (cl-stable-sort '("Banana" "apple" "cherry") 'string< :key 'downcase)))
+    (should (equal result '("apple" "Banana" "cherry")))) )
+
+(ert-deftest cl-merge-test ()
+  (let ((result (cl-merge 'list '(1 3 5) '(2 4 6) '<)))
+    (should (equal result '(1 2 3 4 5 6))))
+  (let ((result (cl-merge 'list '(1 3 3 5) '(2 3 4 6) '<)))
+    (should (equal result '(1 2 3 3 3 4 5 6))))
+  (let ((result (cl-merge 'list '() '(2 4 6) '<)))
+    (should (equal result '(2 4 6))))
+  (let ((result (cl-merge 'list '(1 3 5) '() '<)))
+    (should (equal result '(1 3 5))))
+  (let ((result (cl-merge 'list '() '() '<)))
+    (should (equal result '())))
+  (let ((result (cl-merge 'list '(1 4 6) '(2 3 5) '< :key (lambda (x) x))))
+    (should (equal result '(1 2 3 4 5 6))))
+  (let ((result (cl-merge 'vector (vector 1 3 5) (vector 2 4 6) '<)))
+    (should (equal result (vector 1 2 3 4 5 6))))
+  (let ((result (cl-merge 'list '(5 3 1) '(6 4 2) '>)))
+    (should (equal result '(6 5 4 3 2 1))))
+  (let ((result (cl-merge 'list '(1 2 3) '(1 2 3) '>)))
+    (should (equal result '(1 2 3 1 2 3))))
+  (let ((result (cl-merge 'list '(1 2) '(3 4 5) '<)))
+    (should (equal result '(1 2 3 4 5))))
+  (let ((result (cl-merge 'list '(4 5 6) '(1 2 3) '<)))
+    (should (equal result '(1 2 3 4 5 6))))
+  (let ((result (cl-merge 'list '(1 2 3) '(1.5 2.5 3.5) '<)))
+    (should (equal result '(1 1.5 2 2.5 3 3.5))))
+  (let ((result (cl-merge 'list '(1 2 3) '(10 20 30) '< :key (lambda (x) (* x 10)))))
+    (should (equal result '(1 2 3 10 20 30)))))
+
+(ert-deftest cl-member-test ()
+  (let ((result (cl-member 'b '(a b c d))))
+    (should (equal result '(b c d))))
+  (let ((result (cl-member 'x '(a b c d))))
+    (should (equal result nil)))
+  (let ((result (cl-member 'a '(a b a c d))))
+    (should (equal result '(a b a c d))))
+  (let ((result (cl-member "test" '("test" "not-test" "test2") :test 'string=)))
+    (should (equal result '("test" "not-test" "test2"))))
+  (let ((result (cl-member 'x '(a b c d) :test-not 'eq)))
+    (should (equal result '(a b c d))))
+  (let ((result (cl-member 3 '(1 2 3 4 5) :key 'identity)))
+    (should (equal result '(3 4 5))))
+  (let ((result (cl-member 2.5 '(1 2 2.5 3) :test 'equal)))
+    (should (equal result '(2.5 3))))
+  (let ((result (cl-member 'a '(a a a a) :test 'eq)))
+    (should (equal result '(a a a a))))
+  (let ((result (cl-member 'a '())))
+    (should (equal result nil)))
+  (let ((result (cl-member 'b '(a c d) :test-not 'eq)))
+    (should (equal result '(a c d))))
+  (let ((result (cl-member 3 '(1 2 3 4 5) :key '1+)))
+    (should (equal result '(2 3 4 5)))))
+
+(ert-deftest cl-member-if-test ()
+  (let ((result (cl-member-if #'evenp '(1 2 3 4 5))))
+    (should (equal result '(2 3 4 5))))
+  (let ((result (cl-member-if #'(lambda (x) nil) '(1 2 3 4 5))))
+    (should (equal result nil)))
+  (let ((result (cl-member-if #'(lambda (x) t) '(1 2 3 4 5))))
+    (should (equal result '(1 2 3 4 5))))
+  (let ((result (cl-member-if #'(lambda (x) (= x 1)) '(1 2 3 4 5))))
+    (should (equal result '(1 2 3 4 5))))
+  (let ((result (cl-member-if #'(lambda (x) (and (numberp x) (evenp x))) '(1 3 5 4 2))))
+    (should (equal result '(4 2))))
+  (let ((result (cl-member-if (lambda (x) (string= (number-to-string x) "3")) '(1 2 3 4 5) :key 'identity)))
+    (should (equal result '(3 4 5))))
+  (let ((result (cl-member-if #'(lambda (x) (eq x 'a)) '(a a a a))))
+    (should (equal result '(a a a a))))
+  (let ((result (cl-member-if #'evenp '())))
+    (should (equal result nil)))
+  (let ((result (cl-member-if #'(lambda (x) (< x 0)) '(1 2 3 4 5))))
+    (should (equal result nil)))
+  (let ((result (cl-member-if (lambda (x) (and (numberp x) (<= x 2))) '(1 "two" 3 0))))
+    (should (equal result '(1 "two" 3 0))))
+  (let ((result (cl-member-if (lambda (x) (> x 5)) '(1 2 3 6 7 8) :key 'identity)))
+    (should (equal result '(6 7 8)))))
+
+(ert-deftest cl-member-if-not-test ()
+  (let ((result (cl-member-if-not #'evenp '(1 2 3 4 5))))
+    (should (equal result '(1 2 3 4 5))))
+  (let ((result (cl-member-if-not #'evenp '(2 4 6 8 10 11))))
+    (should (equal result '(11))))
+  (let ((result (cl-member-if-not #'(lambda (x) (> x 5)) '(1 2 3 4 5))))
+    (should (equal result '(1 2 3 4 5))))
+  (let ((result (cl-member-if-not #'(lambda (x) t) '(1 2 3 4 5))))
+    (should (equal result nil)))
+  (let ((result (cl-member-if-not #'(lambda (x) (= x 1)) '(1 2 3 4 5))))
+    (should (equal result '(2 3 4 5))))
+  (let ((result (cl-member-if-not (lambda (x) (string= (number-to-string x) "2")) '(1 2 3 4 5) :key 'identity)))
+    (should (equal result '(1 2 3 4 5))))
+  (let ((result (cl-member-if-not #'evenp '())))
+    (should (equal result nil)))
+  (let ((result (cl-member-if-not #'(lambda (x) (eq x 'a)) '(a a a a))))
+    (should (equal result nil)))
+  (let ((result (cl-member-if-not #'(lambda (x) (< x 0)) '(1 2 3 4 5))))
+    (should (equal result '(1 2 3 4 5))))
+  (let ((result (cl-member-if-not #'(lambda (x) (or (numberp x) (stringp x) (eq x 'b))) '(a "b" 3 nil))))
+    (should (equal result '(a "b" 3 nil))))
+  (let ((result (cl-member-if-not (lambda (x) (numberp x)) '(1 "two" 3 "four" 5) :key 'identity)))
+    (should (equal result '("two" 3 "four" 5)))))
+
+(ert-deftest cl-assoc-test ()
+  (let ((result (cl-assoc 'b '((a . 1) (b . 2) (c . 3)))))
+    (should (equal result '(b . 2))))
+  (let ((result (cl-assoc 'x '((a . 1) (b . 2) (c . 3)))))
+    (should (equal result nil)))
+  (let ((result (cl-assoc "key" '(("key" . 1) ("not-key" . 2)) :test 'string=)))
+    (should (equal result '("key" . 1))))
+  (let ((result (cl-assoc 'a '((a . 1) (b . 2) (c . 3)) :test-not 'eq)))
+    (should (equal result '(b . 2))))
+  (let ((result (cl-assoc '2 '((1 . 'a) (2 . 'b) (3 . 'c)) :key 'identity)))
+    (should (equal result '(2 . 'b))))
+  (let ((result (cl-assoc 'a '((a . 1) (a . 2) (a . 3)) :test 'eq)))
+    (should (equal result '(a . 1))))
+  (let ((result (cl-assoc 'a '())))
+    (should (equal result nil)))
+  (let ((result (cl-assoc 'b '((a . 1) (b . 2) (b . 3) (c . 4)))))
+    (should (equal result '(b . 2)))))
+
+(ert-deftest cl-assoc-if-test ()
+  (let ((result (cl-assoc-if #'evenp '((1 . "odd") (2 . "even") (3 . "odd") (4 . "even")))))
+    (should (equal result '(2 . "even"))))
+  (let ((result (cl-assoc-if #'(lambda (x) (= x 5)) '((1 . "one") (2 . "two") (3 . "three")))))
+    (should (equal result nil)))
+  (let ((result (cl-assoc-if #'(lambda (x) (= x 1)) '((1 . "one") (2 . "two") (3 . "three")))))
+    (should (equal result '(1 . "one"))))
+  (let ((result (cl-assoc-if #'(lambda (x) (string= x "baz")) '((foo . 1) (bar . 2) (baz . 3)))))
+    (should (equal result '(baz . 3))))
+  (let ((result (cl-assoc-if (lambda (x) (and (numberp x) (> x 2))) '((1 . "one") (3 . "three") (4 . "four")))))
+    (should (equal result '(3 . "three"))))
+  (let ((result (cl-assoc-if #'(lambda (x) (> x 1)) '((0 . "zero") (1 . "one") (2 . "two")))))
+    (should (equal result '(2 . "two"))))
+  (let ((result (cl-assoc-if #'evenp '())))
+    (should (equal result nil)))
+  (let ((result (cl-assoc-if #'(lambda (x) (eq x 'a)) '((a . "first") (a . "second") (b . "third")))))
+    (should (equal result '(a . "first"))))
+  (let ((result (cl-assoc-if #'(lambda (x) (and (symbolp x) (not (eq x 'b)))) '((b . "b") (c . "c") (d . "d")))))
+    (should (equal result '(c . "c"))))
+  (let ((result (cl-assoc-if (lambda (x) (and (listp x) (> (length x) 1))) '(((1 2) . "pair 1") ((1) . "pair 2")))))
+    (should (equal result '((1 2) . "pair 1")))))
+
+(ert-deftest cl-assoc-if-not-test ()
+  (let ((result (cl-assoc-if-not #'evenp '((1 . "odd") (2 . "even") (3 . "odd") (4 . "even")))))
+    (should (equal result '(1 . "odd"))))
+  (let ((result (cl-assoc-if-not #'(lambda (x) (> x 0)) '((1 . "one") (2 . "two") (3 . "three")))))
+    (should (equal result nil)))
+  (let ((result (cl-assoc-if-not #'(lambda (x) (< x 5)) '((1 . "one") (2 . "two") (3 . "three")))))
+    (should (equal result nil)))
+  (let ((result (cl-assoc-if-not #'(lambda (x) (= x 1)) '((1 . "one") (2 . "two") (3 . "three")))))
+    (should (equal result '(2 . "two"))))
+  (let ((result (cl-assoc-if-not #'(lambda (x) (string= x "baz")) '((foo . "first") (bar . "second") (baz . "third")))))
+    (should (equal result '(foo . "first"))))
+  (let ((result (cl-assoc-if-not (lambda (x) (and (numberp x) (> x 2))) '((1 . "one") (3 . "three") (4 . "four")))))
+    (should (equal result '(1 . "one"))))
+  (let ((result (cl-assoc-if-not #'(lambda (x) (symbolp x)) '((1 . "one") (b . "bee") (2 . "two")))))
+    (should (equal result '(1 . "one"))))
+  (let ((result (cl-assoc-if-not #'evenp '())))
+    (should (equal result nil)))
+  (let ((result (cl-assoc-if-not #'(lambda (x) (eq x 'a)) '((a . "first") (a . "second") (b . "third")))))
+    (should (equal result '(b . "third")))))
+
+(ert-deftest cl-rassoc-test ()
+  (let ((result (cl-rassoc 2 '(( "one" . 1) ("two" . 2) ("three" . 3)))))
+    (should (equal result (cons "two" 2))))
+  (let ((result (cl-rassoc 4 '(( "one" . 1) ("two" . 2) ("three" . 3)))))
+    (should (equal result nil)))
+  (let ((result (cl-rassoc 2 '(( "one" . 1) ("two" . 2) ("baz" . 2)) :test 'equal)))
+    (should (equal result (cons "two" 2))))
+  (let ((result (cl-rassoc 2 '(( "one" . 1) ("two" . 2) ("three" . 3)) :test-not 'equal)))
+    (should (equal result (cons "one" 1))))
+  (let ((result (cl-rassoc 1 '())))
+    (should (equal result nil)))
+  (let ((result (cl-rassoc 1 '(( "first" . 1) ("second" . 1) ("third" . 1)))))
+    (should (equal result (cons "first" 1))))
+  (let ((result (cl-rassoc 3 '(( "one" . 1) ("two" . 2) ("three" . 3)))))
+    (should (equal result (cons "three" 3))))
+  (let ((result (cl-rassoc 'found '((( "pair 1") . 1) ( "pair 2" . 2) ( "pair 3" . 3)))))
+    (should (equal result nil))))
+
+(ert-deftest cl-rassoc-if-test ()
+  (let ((result (cl-rassoc-if #'evenp '(( "one" . 1) ("two" . 2) ("three" . 3)))))
+    (should (equal result '("two" . 2))))
+  (let ((result (cl-rassoc-if #'evenp '(( "one" . 1) ("three" . 3) ("five" . 5)))))
+    (should (equal result nil)))
+  (let ((result (cl-rassoc-if #'(lambda (x) (= x 1)) '(( "one" . 1) ("two" . 2) ("three" . 3)))))
+    (should (equal result '("one" . 1))))
+  (let ((result (cl-rassoc-if (lambda (x) (> x 1)) '(( "one" . 1) ("two" . 2) ("three" . 3)))))
+    (should (equal result '("two" . 2))))
+  (let ((result (cl-rassoc-if #'(lambda (x) (and (numberp x) (< x 3))) '(( "one" . 1) ("two" . 2) ("three" . 3)))))
+    (should (equal result '("one" . 1))))
+  (let ((result (cl-rassoc-if #'evenp '())))
+    (should (equal result nil)))
+  (let ((result (cl-rassoc-if #'(lambda (x) (> x 0)) '(( "first" . 1) ("second" . 2) ("third" . 3)))))
+    (should (equal result '("first" . 1))))
+  (let ((result (cl-rassoc-if #'(lambda (x) (string= (number-to-string x) "two")) '(( "one" . 1) ("two" . 2) ("three" . 3)))))
+    (should (equal result nil)))
+  (let ((result (cl-rassoc-if #'(lambda (x) (stringp x)) '(( "one" . 1) ("two" . 2) ("three" . 3)))))
+    (should (equal result nil))))
+
+(ert-deftest cl-rassoc-if-not-test ()
+  (let ((result (cl-rassoc-if-not #'evenp '(( "one" . 1) ("two" . 2) ("three" . 3)))))
+    (should (equal result '("one" . 1))))
+  (let ((result (cl-rassoc-if-not #'(lambda (x) (> x 0)) '(( "one" . 1) ("two" . 2) ("three" . 3)))))
+    (should (equal result nil)))
+  (let ((result (cl-rassoc-if-not #'(lambda (x) (< x 5)) '(( "one" . 1) ("two" . 2) ("six" . 6)))))
+    (should (equal result '( "six" . 6))))
+  (let ((result (cl-rassoc-if-not #'(lambda (x) (= x 1)) '(( "one" . 1) ("two" . 2) ("three" . 3)))))
+    (should (equal result '("two" . 2))))
+  (let ((result (cl-rassoc-if-not #'(lambda (x) (> x 2)) '(( "one" . 1) ("two" . 1) ("three" . 3)))))
+    (should (equal result '("one" . 1))))
+  (let ((result (cl-rassoc-if-not #'(lambda (x) (and (numberp x) (< x 3))) '(( "one" . 1) ("two" . 2) ("three" . 3)))))
+    (should (equal result '("three" . 3))))
+  (let ((result (cl-rassoc-if-not #'(lambda (x) (equal x 2)) '(( "one" . 1) ("two" . 2) ("three" . 3)))))
+    (should (equal result '("one" . 1))))
+  (let ((result (cl-rassoc-if-not #'evenp '())))
+    (should (equal result nil)))
+  (let ((result (cl-rassoc-if-not #'(lambda (x) (numberp x)) '(( "one" . 1) ("two" . 2) ("three" . 3)))))
+    (should (equal result nil)))
+  (let ((result (cl-rassoc-if-not (lambda (x) (and (listp x) (= (length x) 1))) '(((1 2) . 1) ((3 4) . 2) ((5) . 2)))))
+    (should (equal result '((1 2) . 1)))))
+
+(ert-deftest cl-intersection-test ()
+  (let ((result (cl-intersection '(1 2 3 4) '(3 4 5 6))))
+    (should (equal result '(4 3))))
+  (let ((result (cl-intersection '(1 2) '(3 4))))
+    (should (equal result '())))
+  (let ((result (cl-intersection '(1 2 3) '(1 2 3))))
+    (should (equal result '(1 2 3))))
+  (let ((result (cl-intersection '(1 1 2 3) '(1 2 2 3 4))))
+    (should (equal result '(3 2 1 1))))
+  (let ((result (cl-intersection '(1 "two" 3) '(3 "two" 4))))
+    (should (equal result '(3))))
+  (let ((result (cl-intersection '(1 2 3) '(3 2 1) :test 'equal)))
+    (should (equal result '(1 2 3))))
+  (let ((result (cl-intersection '(1 2 3) '(3 4 5) :key #'identity)))
+    (should (equal result '(3))))
+  (let ((result (cl-intersection '() '(1 2 3))))
+    (should (equal result '())))
+  (let ((result (cl-intersection '() '())))
+    (should (equal result '())))
+  (let ((result (cl-intersection '(1 2 3 4 5) '(3 4 5 6 7 8))))
+    (should (equal result '(5 4 3)))))
+
+(ert-deftest cl-nintersection-test ()
+  (let ((list1 '(1 2 3 4))
+        (list2 '(3 4 5 6)))
+    (let ((result (cl-nintersection list1 list2)))
+      (should (equal result '(4 3)))
+      (should (equal list1 '(1 2 3 4)))
+      (should (equal list2 '(3 4 5 6)))))
+  (let ((list1 '(1 2))
+        (list2 '(3 4)))
+    (let ((result (cl-nintersection list1 list2)))
+      (should (equal result '()))
+      (should (equal list1 '(1 2)))
+      (should (equal list2 '(3 4)))))
+  (let ((list1 '(1 2 3))
+        (list2 '(1 2 3)))
+    (let ((result (cl-nintersection list1 list2)))
+      (should (equal result '(1 2 3)))
+      (should (equal list1 '(1 2 3)))
+      (should (equal list2 '(1 2 3)))))
+  (let ((list1 '(1 1 2 2 3))
+        (list2 '(2 2 3 4)))
+    (let ((result (cl-nintersection list1 list2)))
+      (should (equal result '(3 2 2)))
+      (should (equal list1 '(1 1 2 2 3)))
+      (should (equal list2 '(2 2 3 4)))))
+  (let ((list1 '(1 "two" 3))
+        (list2 '(3 "two" 4)))
+    (let ((result (cl-nintersection list1 list2)))
+      (should (equal result '(3)))
+      (should (equal list1 '(1 "two" 3)))
+      (should (equal list2 '(3 "two" 4)))))
+  (let ((list1 '(1 2 3))
+        (list2 '(3 2 1)))
+    (let ((result (cl-nintersection list1 list2 :test 'equal)))
+      (should (equal result '(1 2 3)))
+      (should (equal list1 '(1 2 3)))
+      (should (equal list2 '(3 2 1)))))
+  (let ((list1 '())
+        (list2 '(1 2 3)))
+    (let ((result (cl-nintersection list1 list2)))
+      (should (equal result '()))
+      (should (equal list1 '()))
+      (should (equal list2 '(1 2 3)))))
+  (let ((list1 '())
+        (list2 '()))
+    (let ((result (cl-nintersection list1 list2)))
+      (should (equal result '())))))
+
+(ert-deftest cl-set-difference-test ()
+  (let ((result (cl-set-difference '(1 2 3 4) '(3 4 5 6))))
+    (should (equal result '(1 2))))
+  (let ((result (cl-set-difference '(1 2 3) '())))
+    (should (equal result '(1 2 3))))
+  (let ((result (cl-set-difference '(1 2 3) '(1 2 3))))
+    (should (equal result '())))
+  (let ((result (cl-set-difference '(1 1 2 3 4) '(3 4 5))))
+    (should (equal result '(1 1 2))))
+  (let ((result (cl-set-difference '(1 2 3) '(3 2 4))))
+    (should (equal result '(1))))
+  (let ((result (cl-set-difference '(1 2 3) '(3 2 1) :test 'equal)))
+    (should (equal result '())))
+  (let ((result (cl-set-difference '((1 . "one") (2 . "two") (3 . "three"))
+                                    '((1 . "uno") (2 . "dos"))
+                                    :key 'car)))
+    (should (equal result '((3 . "three")))))
+  (let ((result (cl-set-difference '() '(1 2 3))))
+    (should (equal result '())))
+  (let ((result (cl-set-difference '(1 2 3) '())))
+    (should (equal result '(1 2 3))))
+  (let ((result (cl-set-difference '(1 2 3 4 5) '(3 4 5 6 7))))
+    (should (equal result '(1 2))))
+  (let ((list1 '(1 2 3))
+        (list2 '(2 3 4)))
+    (cl-set-difference list1 list2)
+    (should (equal list1 '(1 2 3)))
+    (should (equal list2 '(2 3 4)))))
+
+(ert-deftest cl-nset-difference-test ()
+  (let ((list1 '(1 2 3 4))
+        (list2 '(3 4 5 6)))
+    (let ((result (cl-nset-difference list1 list2)))
+      (should (equal result '(1 2)))
+      (should (equal list1 '(1 2 3 4)))
+      (should (equal list2 '(3 4 5 6)))))
+  (let ((list1 '(1 2 3))
+        (list2 '()))
+    (let ((result (cl-nset-difference list1 list2)))
+      (should (equal result '(1 2 3)))
+      (should (equal list1 '(1 2 3)))
+      (should (equal list2 '()))))
+  (let ((list1 '(1 2 3))
+        (list2 '(1 2 3)))
+    (let ((result (cl-nset-difference list1 list2)))
+      (should (equal result '()))
+      (should (equal list1 '(1 2 3)))
+      (should (equal list2 '(1 2 3)))))
+  (let ((list1 '(1 1 2 2 3))
+        (list2 '(3 4 5)))
+    (let ((result (cl-nset-difference list1 list2)))
+      (should (equal result '(1 1 2 2)))
+      (should (equal list1 '(1 1 2 2 3)))
+      (should (equal list2 '(3 4 5)))))
+  (let ((list1 '(1 2 3))
+        (list2 '(3 2 4)))
+    (let ((result (cl-nset-difference list1 list2)))
+      (should (equal result '(1)))
+      (should (equal list1 '(1 2 3)))
+      (should (equal list2 '(3 2 4)))))
+  (let ((list1 '(1 2 3))
+        (list2 '(3 2 1)))
+    (let ((result (cl-nset-difference list1 list2 :test 'equal)))
+      (should (equal result '()))
+      (should (equal list1 '(1 2 3)))
+      (should (equal list2 '(3 2 1)))))
+  (let ((list1 '())
+          (list2 '(1 2 3)))
+      (let ((result (cl-nset-difference list1 list2)))
+        (should (equal result '()))
+        (should (equal list1 '()))
+        (should (equal list2 '(1 2 3)))))
+  (let ((list1 '())
+        (list2 '()))
+    (let ((result (cl-nset-difference list1 list2)))
+      (should (equal result '()))))
+  (let ((list1 '(1 2 3 4 5))
+        (list2 '(3 4 5 6 7)))
+    (let ((result (cl-nset-difference list1 list2)))
+      (should (equal result '(1 2)))
+      (should (equal list1 '(1 2 3 4 5)))
+      (should (equal list2 '(3 4 5 6 7))))))
+
+(ert-deftest cl-set-exclusive-or-test ()
+  (let ((result (cl-set-exclusive-or '(1 2 3) '(3 4 5))))
+    (should (equal result '(1 2 4 5))))
+  (let ((result (cl-set-exclusive-or '(1 2 3) '())))
+    (should (equal result '(1 2 3))))
+  (let ((result (cl-set-exclusive-or '() '(3 4 5))))
+    (should (equal result '(3 4 5))))
+  (let ((result (cl-set-exclusive-or '(1 2 3) '(1 2 3))))
+    (should (equal result nil)))
+  (let ((result (cl-set-exclusive-or '(1 1 2 3) '(3 4 5))))
+    (should (equal result '(1 1 2 4 5))))
+  (let ((result (cl-set-exclusive-or '(1 2 3) '(3 3 4 5))))
+    (should (equal result '(1 2 4 5))))
+  (let ((result (cl-set-exclusive-or '(1 2 3) '(3 2 4))))
+    (should (equal result '(1 4))))
+  (let ((result (cl-set-exclusive-or '(1 2 3) '(3 2 1) :test 'equal)))
+    (should (equal result '())))
+  (let ((result (cl-set-exclusive-or '() '())))
+    (should (equal result '())))
+  (let ((result (cl-set-exclusive-or '(1 2 3 4 5) '(3 4 5 6 7)))
+        (list1 '(1 2 3 4 5))
+        (list2 '(3 4 5 6 7)))
+    (should (equal result '(1 2 6 7)))
+    (should (equal list1 '(1 2 3 4 5)))
+    (should (equal list2 '(3 4 5 6 7)))))
+
+(ert-deftest cl-nset-exclusive-or-test ()
+  (let ((list1 '(1 2 3))
+        (list2 '(3 4 5)))
+    (let ((result (cl-nset-exclusive-or list1 list2)))
+      (should (equal result '(1 2 4 5)))
+      (should (equal list1 '(1 2 3)))
+      (should (equal list2 '(3 4 5)))))
+  (let ((list1 '(1 2 3))
+        (list2 '()))
+    (let ((result (cl-nset-exclusive-or list1 list2)))
+      (should (equal result '(1 2 3)))
+      (should (equal list1 '(1 2 3)))
+      (should (equal list2 '()))))
+  (let ((list1 '(1 2 3))
+        (list2 '(1 2 3)))
+    (let ((result (cl-nset-exclusive-or list1 list2)))
+      (should (equal result nil)))
+    (should (equal list1 '(1 2 3)))
+    (should (equal list2 '(1 2 3))))
+  (let ((list1 '(1 1 2 2 3))
+        (list2 '(3 4 5)))
+    (let ((result (cl-nset-exclusive-or list1 list2)))
+      (should (equal result '(1 1 2 2 4 5)))
+      (should (equal list1 '(1 1 2 2 3)))
+      (should (equal list2 '(3 4 5)))))
+  (let ((list1 '(1 2 3))
+        (list2 '(3 3 4 5)))
+    (let ((result (cl-nset-exclusive-or list1 list2)))
+      (should (equal result '(1 2 4 5)))
+      (should (equal list1 '(1 2 3)))
+      (should (equal list2 '(3 3 4 5)))))
+  (let ((list1 '(1 2 3))
+        (list2 '(3 2 4)))
+    (let ((result (cl-nset-exclusive-or list1 list2)))
+      (should (equal result '(1 4)))
+      (should (equal list1 '(1 2 3)))
+      (should (equal list2 '(3 2 4)))))
+  (let ((list1 '(1 2 3))
+        (list2 '(3 2 1)))
+    (let ((result (cl-nset-exclusive-or list1 list2 :test 'equal)))
+      (should (equal result '()))
+      (should (equal list1 '(1 2 3)))
+      (should (equal list2 '(3 2 1)))))
+  (let ((list1 '())
+        (list2 '(1 2 3)))
+    (let ((result (cl-nset-exclusive-or list1 list2)))
+      (should (equal result '(1 2 3)))
+      (should (equal list1 '()))
+      (should (equal list2 '(1 2 3)))))
+  (let ((list1 '())
+        (list2 '()))
+    (let ((result (cl-nset-exclusive-or list1 list2)))
+      (should (equal result '()))))
+  (let ((list1 '(1 2 3 4 5))
+        (list2 '(3 4 5 6 7)))
+    (let ((result (cl-nset-exclusive-or list1 list2)))
+      (should (equal result '(1 2 6 7)))
+      (should (equal list1 '(1 2 3 4 5)))
+      (should (equal list2 '(3 4 5 6 7))))))
+
+(ert-deftest cl-subsetp-test ()
+  (let ((result (cl-subsetp '(1 2) '(1 2 3 4))))
+    (should (equal result t)))
+  (let ((result (cl-subsetp '() '(1 2 3 4))))
+    (should (equal result t)))
+  (let ((result (cl-subsetp '(1 2) '())))
+    (should (equal result nil)))
+  (let ((result (cl-subsetp '(1 2 3) '(1 2 3))))
+    (should (equal result t)))
+  (let ((result (cl-subsetp '(1 1 2) '(1 2 3))))
+    (should (equal result t)))
+  (let ((result (cl-subsetp '(1 2) '(1 1 2 3 4))))
+    (should (equal result t)))
+  (let ((result (cl-subsetp '(1 "two" 3) '(3 "two" 1))))
+    (should (equal result nil)))
+  (let ((result (cl-subsetp '(1 2) '(2 1) :test 'equal)))
+    (should (equal result t)))
+  (let ((result (cl-subsetp '((1 . "one") (2 . "two")) '((1 . "uno") (2 . "dos")) :key 'car)))
+    (should (equal result t)))
+  (let ((result (cl-subsetp '(1 2) '(3 4 2 1) :test 'eq)))
+    (should (equal result t)))
+  (let ((result (cl-subsetp '((1 2) (3)) '((1 2 . "found") (3 . "found")) :key 'car)))
+    (should (equal result t)))
+  (let ((result (cl-subsetp '(1 2) '(1 2 3 2))))
+    (should (equal result t)))
+  (let ((result (cl-subsetp '() '())))
+    (should (equal result t))))
+
 (provide 'cl-seq-tests)
 ;;; cl-seq-tests.el ends here
-- 
2.41.0