]> gitweb.factorcode.org Git - factor.git/blob - core/sets/sets-tests.factor
factor: rename [ ] [ ] unit-test -> { } [ ] unit-test using a refactoring tool!
[factor.git] / core / sets / sets-tests.factor
1 ! Copyright (C) 2010 Daniel Ehrenberg, Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: sets tools.test kernel prettyprint hash-sets sorting
4 math sequences bit-sets bit-arrays ;
5 IN: sets.tests
6
7 { V{ 1 2 3 } } [ 3 V{ 1 2 } clone [ adjoin ] keep ] unit-test
8 { V{ 1 2 } } [ 2 V{ 1 2 } clone [ adjoin ] keep ] unit-test
9
10 { t } [ 4 { 2 4 5 } in? ] unit-test
11 { f } [ 1 { 2 4 5 } in? ] unit-test
12 { f } [ f 5 <bit-set> in? ] unit-test
13
14 { V{ 1 2 } } [ 3 V{ 1 2 } clone [ delete ] keep ] unit-test
15 { V{ 2 } } [ 1 V{ 1 2 } clone [ delete ] keep ] unit-test
16 { 0 } [ 5 <bit-set> 0 over delete cardinality ] unit-test
17 { 0 } [ 5 <bit-set> f over delete cardinality ] unit-test
18 { 0 } [ 5 <bit-set> 3 over adjoin 3 over delete cardinality ] unit-test
19 { 0 } [ 5 <bit-set> 10 over delete cardinality ] unit-test
20 { HS{ 1 } } [ HS{ 1 2 } 2 over delete ] unit-test
21
22 { { 1 2 3 } } [ { 1 1 1 2 2 3 3 3 3 3 } dup set-like natural-sort ] unit-test
23 { { 1 2 3 } } [ HS{ 1 2 3 } { } set-like natural-sort ] unit-test
24 { { 1 2 3 } } [ { 1 2 2 3 3 } { } set-like ] unit-test
25 { { 3 2 1 } } [ { 3 3 2 2 1 } { } set-like ] unit-test
26 { t } [ 4 <bit-set> 1 <bit-set> set-like 4 <bit-set> = ] unit-test
27 { t } [ { 1 2 3 } HS{ } set-like HS{ 1 2 3 } = ] unit-test
28
29 { HS{ 1 2 3 } } [ { 1 2 3 } fast-set ] unit-test
30 { T{ bit-set { table ?{ f } } } }
31 [ 1 <bit-set> fast-set ] unit-test
32
33 { { 1 } } [ { 1 } members ] unit-test
34
35 { { } } [ { } { } union ] unit-test
36 { { 1 2 3 4 } } [ { 1 2 3 } { 2 3 4 } union ] unit-test
37
38 { { } } [ { } { } intersect ] unit-test
39 { { 2 3 } } [ { 1 2 3 } { 2 3 4 } intersect ] unit-test
40 { { 2 3 } } [ { 1 2 3 } { 2 3 4 5 } intersect ] unit-test
41 { { 2 3 4 } } [ { 1 2 3 4 } { 2 3 4 } intersect ] unit-test
42 { { 2 3 } } [ { 1 2 2 3 } { 2 3 3 4 } intersect ] unit-test
43
44 { t } [ { 1 2 } { 1 3 } intersects? ] unit-test
45 { f } [ { 4 2 } { 1 3 } intersects? ] unit-test
46 { f } [ { } { 1 } intersects? ] unit-test
47 { f } [ { 1 } { } intersects? ] unit-test
48 { f } [ { } { } intersects? ] unit-test
49
50 { { } } [ { } { } diff ] unit-test
51 { { 1 } } [ { 1 2 3 } { 2 3 4 } diff ] unit-test
52 { { 1 } } [ { 1 2 3 } { 2 3 4 5 } diff ] unit-test
53 { { 1 } } [ { 1 2 3 4 } { 2 3 4 } diff ] unit-test
54 { { 1 } } [ { 1 1 2 3 } { 2 3 4 4 } diff ] unit-test
55
56 { T{ bit-set { table ?{ f f f } } } }
57 [ 3 <bit-set> 0 over adjoin dup diff ] unit-test
58
59 { f } [ { 1 2 3 4 } { 1 2 } subset? ] unit-test
60 { t } [ { 1 2 3 4 } { 1 2 } swap subset? ] unit-test
61 { t } [ { 1 2 } { 1 2 } subset? ] unit-test
62 { t } [ { } { 1 2 } subset? ] unit-test
63 { t } [ { } { } subset? ] unit-test
64 { f } [ { 1 } { } subset? ] unit-test
65
66 { t } [ { 1 2 3 } { 2 1 3 } set= ] unit-test
67 { f } [ { 2 3 } { 1 2 3 } set= ] unit-test
68 { f } [ { 1 2 3 } { 2 3 } set= ] unit-test
69
70 { { 2 1 2 1 } } [ { 1 2 3 2 1 2 1 } duplicates ] unit-test
71 { f } [ HS{ 1 2 3 1 2 1 } duplicates ] unit-test
72
73 { f } [ { 0 1 1 2 3 5 } all-unique? ] unit-test
74 { t } [ { 0 1 2 3 4 5 } all-unique? ] unit-test
75 { t } [ HS{ 0 1 2 3 4 5 } all-unique? ] unit-test
76
77 { t } [ f null? ] unit-test
78 { f } [ { 4 } null? ] unit-test
79 { t } [ HS{ } null? ] unit-test
80 { f } [ HS{ 3 } null? ] unit-test
81 { t } [ 2 <bit-set> null? ] unit-test
82 { f } [ 3 <bit-set> 0 over adjoin null? ] unit-test
83
84 { 0 } [ f cardinality ] unit-test
85 { 0 } [ { } cardinality ] unit-test
86 { 1 } [ { 1 } cardinality ] unit-test
87 { 1 } [ { 1 1 } cardinality ] unit-test
88 { 1 } [ HS{ 1 } cardinality ] unit-test
89 { 3 } [ HS{ 1 2 3 } cardinality ] unit-test
90 { 0 } [ 0 <bit-set> cardinality ] unit-test
91 { 0 } [ 5 <bit-set> cardinality ] unit-test
92 { 2 } [ 5 <bit-set> 0 over adjoin 1 over adjoin cardinality ] unit-test
93 { 1 } [ 5 <bit-set> 1 over adjoin cardinality ] unit-test
94
95 { { } } [ { } { } within ] unit-test
96 { { 2 3 } } [ { 1 2 3 } { 2 3 4 } within ] unit-test
97 { { 2 2 3 } } [ { 1 2 2 3 } { 2 3 3 4 } within ] unit-test
98
99 { { } } [ { } { } without ] unit-test
100 { { 1 } } [ { 1 2 3 } { 2 3 4 } without ] unit-test
101 { { 1 1 } } [ { 1 1 2 3 3 } { 2 3 4 4 } without ] unit-test
102
103 { { 1 2 3 } } [ { { 1 } { 2 } { 1 3 } } combine ] unit-test
104 { f } [ { } combine ] unit-test
105
106 { { 1 4 9 16 25 36 } }
107 [ { { 1 2 3 } { 4 5 6 } } [ [ sq ] map ] gather ] unit-test
108
109 { H{ { 3 HS{ 1 2 } } } } [ H{ } clone 1 3 pick adjoin-at 2 3 pick adjoin-at ] unit-test
110
111 { H{ { 3 H{ { 1 1 } { 2 2 } } } } } [ H{ } clone 1 3 pick conjoin-at 2 3 pick conjoin-at ] unit-test
112
113 TUPLE: null-set ;
114 INSTANCE: null-set set
115 M: null-set members drop f ;
116
117 { 0 } [ T{ null-set } cardinality ] unit-test
118 { f } [ T{ null-set } members ] unit-test
119 { t } [ T{ null-set } T{ null-set } set-like T{ null-set } = ] unit-test
120
121 { t } [ T{ null-set } set? ] unit-test
122 { t } [ HS{ } set? ] unit-test
123 { t } [ { } set? ] unit-test
124 { t } [ 5 <bit-set> set? ] unit-test
125 { f } [ H{ } set? ] unit-test
126
127 { HS{ } } [ HS{ } [ clear-set ] keep ] unit-test
128 { HS{ } } [ HS{ 1 2 3 } [ clear-set ] keep ] unit-test
129
130 { HS{ } } [ HS{ } HS{ } union! ] unit-test
131 { HS{ 1 } } [ HS{ 1 } HS{ } union! ] unit-test
132 { HS{ 1 } } [ HS{ } HS{ 1 } union! ] unit-test
133 { HS{ 1 2 3 } } [ HS{ 1 } HS{ 1 2 3 } union! ] unit-test
134
135 { f } [ { } intersection ] unit-test
136 { HS{ } } [ { HS{ } } intersection ] unit-test
137 { HS{ 1 } } [ { HS{ 1 2 3 } HS{ 1 } } intersection ] unit-test
138
139 { HS{ } } [ HS{ } HS{ } diff! ] unit-test
140 { HS{ 1 } } [ HS{ 1 2 3 } HS{ 2 3 } diff! ] unit-test
141 { HS{ 1 } } [ HS{ 1 } HS{ 2 3 4 } diff! ] unit-test
142 { HS{ 1 2 3 } } [ HS{ 1 2 3 } HS{ 4 } diff! ] unit-test
143
144 { HS{ } } [ HS{ } HS{ } intersect! ] unit-test
145 { HS{ 2 3 } } [ HS{ 1 2 3 } HS{ 2 3 } intersect! ] unit-test
146 { HS{ } } [ HS{ 1 } HS{ 2 3 4 } intersect! ] unit-test
147 { HS{ } } [ HS{ 1 2 3 } HS{ 4 } intersect! ] unit-test