about summary refs log tree commit diff
path: root/users/wpcarro/emacs/pkgs/set/tests.el
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2022-07-29T03·29-0700
committerclbot <clbot@tvl.fyi>2022-07-29T03·35+0000
commit15c9ff49026f9ddbb42f663dfbc2668faa74cab2 (patch)
tree23da6e794623f267bfcc53802cd654e3d655dba9 /users/wpcarro/emacs/pkgs/set/tests.el
parentcaf068253a8e7eacff0b255de66f830e726d6777 (diff)
feat(wpcarro/emacs): Package al, list, set, struct r/4342
Originally I set-out to package `al.el`, but as I started traversing the
dependencies, I needed to package increasingly more packages. I refactored some
of these to prune their dependencies to slay this hydra before it turned into a
never-ending project. I have mixed feelings about this.

I also introduced `ert` and unit tests into my Elisp packaging, so it'll be nice
to have build-time tests that run when Emacs updates land in depot.

Change-Id: I2756dc60888b80255a495e08ae61bd547e6b3db2
Reviewed-on: https://cl.tvl.fyi/c/depot/+/5998
Reviewed-by: wpcarro <wpcarro@gmail.com>
Autosubmit: wpcarro <wpcarro@gmail.com>
Tested-by: BuildkiteCI
Diffstat (limited to 'users/wpcarro/emacs/pkgs/set/tests.el')
-rw-r--r--users/wpcarro/emacs/pkgs/set/tests.el78
1 files changed, 78 insertions, 0 deletions
diff --git a/users/wpcarro/emacs/pkgs/set/tests.el b/users/wpcarro/emacs/pkgs/set/tests.el
new file mode 100644
index 000000000000..3544364897d2
--- /dev/null
+++ b/users/wpcarro/emacs/pkgs/set/tests.el
@@ -0,0 +1,78 @@
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Dependencies
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(require 'ert)
+(require 'dash)
+(require 'set)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Tests
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(ert-deftest set-from-list ()
+  (equal '(1 2 3)
+         (->> '(1 2 3 1 2 3)
+              set-from-list
+              set-to-list)))
+
+(ert-deftest set-distinct? ()
+  (and
+   (set-distinct? (set-new 'one 'two 'three)
+                  (set-new 'a 'b 'c))
+   (not
+    (set-distinct? (set-new 1 2 3)
+                   (set-new 3 4 5)))
+   (not
+    (set-distinct? (set-new 1 2 3)
+                   (set-new 1 2 3)))))
+
+(ert-deftest set-equal? ()
+  (and
+   (set-equal? (set-new 'a 'b 'c)
+               (set-new 'x 'y 'z))
+   (set-equal? (set-new 'a 'b 'c)
+               (set-new 'a 'b))
+   (set-equal? (set-new 'a 'b 'c)
+               (set-new 'a 'b 'c))))
+
+(ert-deftest set-intersection ()
+  (set-equal? (set-new 2 3)
+              (set-intersection (set-new 1 2 3)
+                                (set-new 2 3 4))))
+
+(ert-deftest set-to/from-list ()
+  (equal '(1 2 3)
+         (->> '(1 1 2 2 3 3)
+              set-from-list
+              set-to-list)))
+
+(ert-deftest set-subset? ()
+  (let ((primary-colors (set-new "red" "green" "blue")))
+    ;; set-subset?
+    (and
+     (set-subset? (set-new "black" "grey")
+                  primary-colors)
+     (set-subset? (set-new "red")
+                  primary-colors))))
+
+(ert-deftest set-subset/superset? ()
+  (let ((primary-colors (set-new "red" "green" "blue")))
+    ;; set-subset?
+    (and
+     (not (set-superset? primary-colors
+                         (set-new "black" "grey")))
+     (set-superset? primary-colors
+                    (set-new "red" "green" "blue"))
+     (set-superset? primary-colors
+                    (set-new "red" "blue")))))
+
+(ert-deftest set-empty? ()
+  (and
+   (set-empty? (set-new))
+   (set-empty? (set-new 1 2 3))))
+
+(ert-deftest set-count ()
+  (and
+   (= 0 (set-count (set-new)))
+   (= 2 (set-count (set-new 1 1 2 2)))))