2022-07-29 05:29:07 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Dependencies
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
(require 'ert)
|
|
|
|
(require 'dash)
|
|
|
|
(require 'set)
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Tests
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
(ert-deftest set-from-list ()
|
2022-07-30 16:22:10 +02:00
|
|
|
(should (equal '(1 2 3)
|
|
|
|
(->> '(1 2 3 1 2 3)
|
|
|
|
set-from-list
|
|
|
|
set-to-list))))
|
2022-07-29 05:29:07 +02:00
|
|
|
|
|
|
|
(ert-deftest set-distinct? ()
|
2022-07-30 16:22:10 +02:00
|
|
|
(should (set-distinct? (set-new 'one 'two 'three)
|
|
|
|
(set-new 'a 'b 'c)))
|
|
|
|
(should (not
|
|
|
|
(set-distinct? (set-new 1 2 3)
|
|
|
|
(set-new 3 4 5))))
|
|
|
|
(should (not
|
|
|
|
(set-distinct? (set-new 1 2 3)
|
|
|
|
(set-new 1 2 3)))))
|
2022-07-29 05:29:07 +02:00
|
|
|
|
|
|
|
(ert-deftest set-equal? ()
|
2022-07-30 16:22:10 +02:00
|
|
|
(should (not (set-equal? (set-new 'a 'b 'c)
|
|
|
|
(set-new 'x 'y 'z))))
|
|
|
|
(should (not (set-equal? (set-new 'a 'b 'c)
|
|
|
|
(set-new 'a 'b))))
|
|
|
|
(should (set-equal? (set-new 'a 'b 'c)
|
|
|
|
(set-new 'a 'b 'c))))
|
2022-07-29 05:29:07 +02:00
|
|
|
|
|
|
|
(ert-deftest set-intersection ()
|
2022-07-30 16:22:10 +02:00
|
|
|
(should (set-equal? (set-new 2 3)
|
|
|
|
(set-intersection (set-new 1 2 3)
|
|
|
|
(set-new 2 3 4)))))
|
2022-07-29 05:29:07 +02:00
|
|
|
|
|
|
|
(ert-deftest set-to/from-list ()
|
2022-07-30 16:22:10 +02:00
|
|
|
(should (equal '(1 2 3)
|
|
|
|
(->> '(1 1 2 2 3 3)
|
|
|
|
set-from-list
|
|
|
|
set-to-list))))
|
2022-07-29 05:29:07 +02:00
|
|
|
|
|
|
|
(ert-deftest set-subset? ()
|
2022-07-30 16:22:10 +02:00
|
|
|
(should (not (set-subset? (set-new "black" "grey")
|
|
|
|
(set-new "red" "green" "blue"))))
|
|
|
|
(should (set-subset? (set-new "red")
|
|
|
|
(set-new "red" "green" "blue"))))
|
2022-07-29 05:29:07 +02:00
|
|
|
|
2022-07-30 16:22:10 +02:00
|
|
|
(ert-deftest set-superset? ()
|
2022-07-29 05:29:07 +02:00
|
|
|
(let ((primary-colors (set-new "red" "green" "blue")))
|
2022-07-30 16:22:10 +02:00
|
|
|
(should (not (set-superset? primary-colors
|
|
|
|
(set-new "black" "grey"))))
|
|
|
|
(should (set-superset? primary-colors
|
|
|
|
(set-new "red" "green" "blue")))
|
|
|
|
(should (set-superset? primary-colors
|
|
|
|
(set-new "red" "blue")))))
|
2022-07-29 05:29:07 +02:00
|
|
|
|
|
|
|
(ert-deftest set-empty? ()
|
2022-07-30 16:22:10 +02:00
|
|
|
(should (set-empty? (set-new)))
|
|
|
|
(should (not (set-empty? (set-new 1 2 3)))))
|
2022-07-29 05:29:07 +02:00
|
|
|
|
|
|
|
(ert-deftest set-count ()
|
2022-07-30 16:22:10 +02:00
|
|
|
(should (= 0 (set-count (set-new))))
|
|
|
|
(should (= 2 (set-count (set-new 1 1 2 2)))))
|