]> gitweb.factorcode.org Git - factor.git/blob - core/sets/sets-tests.factor
0ffd8aff08777cdf276e0c57ec98ea8663b1f9c8
[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: bit-arrays bit-sets kernel math sequences sets sorting
4 tools.test ;
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 ! combine
104 { { 1 2 3 } } [ { { 1 } { 2 } { 1 3 } } combine ] unit-test
105 { f } [ { } combine ] unit-test
106
107 ! refine
108 { { 2 } } [
109     { { 2 3 } { 2 4 } { 9 8 4 2 } } refine
110 ] unit-test
111
112 { { 1 4 9 16 25 36 } }
113 [ { { 1 2 3 } { 4 5 6 } } [ [ sq ] map ] gather ] unit-test
114
115 { H{ { 3 HS{ 1 2 } } } } [ H{ } clone 1 3 pick adjoin-at 2 3 pick adjoin-at ] unit-test
116
117 { H{ { 3 H{ { 1 1 } { 2 2 } } } } } [ H{ } clone 1 3 pick conjoin-at 2 3 pick conjoin-at ] unit-test
118
119 TUPLE: null-set ;
120 INSTANCE: null-set set
121 M: null-set members drop f ;
122
123 { 0 } [ T{ null-set } cardinality ] unit-test
124 { f } [ T{ null-set } members ] unit-test
125 { t } [ T{ null-set } T{ null-set } set-like T{ null-set } = ] unit-test
126
127 { t } [ T{ null-set } set? ] unit-test
128 { t } [ HS{ } set? ] unit-test
129 { t } [ { } set? ] unit-test
130 { t } [ 5 <bit-set> set? ] unit-test
131 { f } [ H{ } set? ] unit-test
132
133 { HS{ } } [ HS{ } [ clear-set ] keep ] unit-test
134 { HS{ } } [ HS{ 1 2 3 } [ clear-set ] keep ] unit-test
135
136 { HS{ } } [ HS{ } HS{ } union! ] unit-test
137 { HS{ 1 } } [ HS{ 1 } HS{ } union! ] unit-test
138 { HS{ 1 } } [ HS{ } HS{ 1 } union! ] unit-test
139 { HS{ 1 2 3 } } [ HS{ 1 } HS{ 1 2 3 } union! ] unit-test
140
141 { f } [ { } intersection ] unit-test
142 { HS{ } } [ { HS{ } } intersection ] unit-test
143 { HS{ 1 } } [ { HS{ 1 2 3 } HS{ 1 } } intersection ] unit-test
144
145 { HS{ } } [ HS{ } HS{ } diff! ] unit-test
146 { HS{ 1 } } [ HS{ 1 2 3 } HS{ 2 3 } diff! ] unit-test
147 { HS{ 1 } } [ HS{ 1 } HS{ 2 3 4 } diff! ] unit-test
148 { HS{ 1 2 3 } } [ HS{ 1 2 3 } HS{ 4 } diff! ] unit-test
149
150 { HS{ } } [ HS{ } HS{ } intersect! ] unit-test
151 { HS{ 2 3 } } [ HS{ 1 2 3 } HS{ 2 3 } intersect! ] unit-test
152 { HS{ } } [ HS{ 1 } HS{ 2 3 4 } intersect! ] unit-test
153 { HS{ } } [ HS{ 1 2 3 } HS{ 4 } intersect! ] unit-test