blob: 3544364897d21135c1775a35564339749d0d83e4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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)))))
|