autoc 1.4 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGES.md +3 -0
- data/README.md +149 -0
- data/cmake/AutoC.cmake +39 -0
- data/lib/autoc/allocators.rb +51 -0
- data/lib/autoc/association.rb +126 -0
- data/lib/autoc/box.rb +311 -0
- data/lib/autoc/cmake.rb +54 -0
- data/lib/autoc/collection.rb +83 -110
- data/lib/autoc/composite.rb +333 -0
- data/lib/autoc/cstring.rb +263 -0
- data/lib/autoc/function.rb +247 -0
- data/lib/autoc/hash_map.rb +328 -0
- data/lib/autoc/hash_set.rb +339 -0
- data/lib/autoc/hashers.rb +102 -0
- data/lib/autoc/list.rb +444 -0
- data/lib/autoc/module.rb +434 -0
- data/lib/autoc/openmp.rb +15 -0
- data/lib/autoc/primitive.rb +27 -0
- data/lib/autoc/ranges.rb +707 -0
- data/lib/autoc/record.rb +247 -0
- data/lib/autoc/scaffold/docs.rb +117 -0
- data/lib/autoc/scaffold/generic_value.rb +86 -0
- data/lib/autoc/scaffold/project.rb +75 -0
- data/lib/autoc/scaffold/test_cstring.rb +113 -0
- data/lib/autoc/scaffold/test_cstring_hash_set.rb +35 -0
- data/lib/autoc/scaffold/test_int_box.rb +22 -0
- data/lib/autoc/scaffold/test_int_hash_set.rb +448 -0
- data/lib/autoc/scaffold/test_int_list.rb +106 -0
- data/lib/autoc/scaffold/test_int_vector.rb +83 -0
- data/lib/autoc/scaffold/test_v2v_hash_map.rb +83 -0
- data/lib/autoc/scaffold/test_value_hash_set.rb +60 -0
- data/lib/autoc/scaffold/test_value_vector.rb +146 -0
- data/{test/test.rb → lib/autoc/scaffold/tests.rb} +179 -158
- data/lib/autoc/scaffold.rb +12 -0
- data/lib/autoc/sequential.rb +99 -0
- data/lib/autoc/set.rb +331 -0
- data/lib/autoc/std.rb +149 -0
- data/lib/autoc/type.rb +93 -531
- data/lib/autoc/vector.rb +290 -0
- data/lib/autoc.rb +4 -35
- metadata +55 -85
- data/.yardopts +0 -4
- data/CHANGES +0 -23
- data/README +0 -28
- data/doc/AutoC/Code.html +0 -523
- data/doc/AutoC/Collection.html +0 -1214
- data/doc/AutoC/HashMap.html +0 -1441
- data/doc/AutoC/HashSet.html +0 -916
- data/doc/AutoC/Iterators/Bidirectional.html +0 -204
- data/doc/AutoC/Iterators/Unidirectional.html +0 -200
- data/doc/AutoC/Iterators.html +0 -126
- data/doc/AutoC/List.html +0 -1039
- data/doc/AutoC/Maps.html +0 -290
- data/doc/AutoC/Module/File.html +0 -415
- data/doc/AutoC/Module/Header.html +0 -437
- data/doc/AutoC/Module/Source.html +0 -707
- data/doc/AutoC/Module.html +0 -948
- data/doc/AutoC/Priority.html +0 -138
- data/doc/AutoC/Queue.html +0 -1172
- data/doc/AutoC/Reference.html +0 -735
- data/doc/AutoC/Sets.html +0 -520
- data/doc/AutoC/String.html +0 -1394
- data/doc/AutoC/TreeMap.html +0 -1565
- data/doc/AutoC/TreeSet.html +0 -1447
- data/doc/AutoC/Type.html +0 -2148
- data/doc/AutoC/UserDefinedType.html +0 -1047
- data/doc/AutoC/Vector.html +0 -987
- data/doc/AutoC.html +0 -331
- data/doc/_index.html +0 -388
- data/doc/class_list.html +0 -51
- data/doc/css/common.css +0 -1
- data/doc/css/full_list.css +0 -58
- data/doc/css/style.css +0 -481
- data/doc/file.CHANGES.html +0 -117
- data/doc/file.README.html +0 -116
- data/doc/file_list.html +0 -61
- data/doc/frames.html +0 -17
- data/doc/index.html +0 -116
- data/doc/js/app.js +0 -243
- data/doc/js/full_list.js +0 -216
- data/doc/js/jquery.js +0 -4
- data/doc/method_list.html +0 -1307
- data/doc/top-level-namespace.html +0 -112
- data/lib/autoc/code.rb +0 -237
- data/lib/autoc/collection/hash_map.rb +0 -385
- data/lib/autoc/collection/hash_set.rb +0 -337
- data/lib/autoc/collection/iterator.rb +0 -39
- data/lib/autoc/collection/list.rb +0 -429
- data/lib/autoc/collection/map.rb +0 -41
- data/lib/autoc/collection/queue.rb +0 -517
- data/lib/autoc/collection/set.rb +0 -134
- data/lib/autoc/collection/tree_map.rb +0 -464
- data/lib/autoc/collection/tree_set.rb +0 -611
- data/lib/autoc/collection/vector.rb +0 -336
- data/lib/autoc/string.rb +0 -492
- data/test/test_auto.c +0 -7141
- data/test/test_auto.h +0 -753
- data/test/test_char_string.rb +0 -270
- data/test/test_int_list.rb +0 -35
- data/test/test_int_tree_set.rb +0 -111
- data/test/test_int_vector.rb +0 -34
- data/test/test_value_hash_map.rb +0 -162
- data/test/test_value_hash_set.rb +0 -173
- data/test/test_value_list.rb +0 -193
- data/test/test_value_queue.rb +0 -275
- data/test/test_value_tree_map.rb +0 -176
- data/test/test_value_tree_set.rb +0 -173
- data/test/test_value_vector.rb +0 -155
- data/test/value.rb +0 -80
@@ -0,0 +1,448 @@
|
|
1
|
+
require 'autoc/hash_set'
|
2
|
+
|
3
|
+
type_test(AutoC::HashSet, :IntHashSet, :int) do
|
4
|
+
|
5
|
+
###
|
6
|
+
|
7
|
+
def render_forward_declarations(stream)
|
8
|
+
super
|
9
|
+
stream << "void #{dump}(#{const_rvalue} target);"
|
10
|
+
end
|
11
|
+
|
12
|
+
def render_implementation(stream)
|
13
|
+
super
|
14
|
+
stream << %{
|
15
|
+
#include <stdio.h>
|
16
|
+
void #{dump}(#{const_rvalue} target) {
|
17
|
+
#{range} r;
|
18
|
+
for(r = #{range.new}(target); !#{range.empty}(&r); #{range.pop_front}(&r)) {
|
19
|
+
printf("%d ", #{range.take_front}(&r));
|
20
|
+
}
|
21
|
+
printf("\\n");
|
22
|
+
}
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
setup %{
|
27
|
+
#{self} t;
|
28
|
+
}
|
29
|
+
|
30
|
+
cleanup %{
|
31
|
+
#{destroy}(&t);
|
32
|
+
}
|
33
|
+
|
34
|
+
test :create_empty, %{
|
35
|
+
#{create}(&t);
|
36
|
+
TEST_TRUE( #{empty}(&t) );
|
37
|
+
TEST_EQUAL( #{size}(&t), 0 );
|
38
|
+
}
|
39
|
+
|
40
|
+
test :iterate_0, %{
|
41
|
+
#{create}(&t);
|
42
|
+
#{range} r = #{range.new}(&t);
|
43
|
+
TEST_TRUE( #{range.empty}(&r) );
|
44
|
+
}
|
45
|
+
|
46
|
+
test :iterate_1, %{
|
47
|
+
#{create}(&t);
|
48
|
+
TEST_EQUAL( #{size}(&t), 0 );
|
49
|
+
#{put}(&t, -3);
|
50
|
+
TEST_EQUAL( #{size}(&t), 1 );
|
51
|
+
#{range} r = #{range.new}(&t);
|
52
|
+
TEST_FALSE( #{range.empty}(&r) );
|
53
|
+
TEST_EQUAL( #{range.take_front}(&r), -3 );
|
54
|
+
#{range.pop_front}(&r);
|
55
|
+
TEST_TRUE( #{range.empty}(&r) );
|
56
|
+
}
|
57
|
+
|
58
|
+
###
|
59
|
+
|
60
|
+
setup %{
|
61
|
+
int i;
|
62
|
+
#{self} t;
|
63
|
+
#{create}(&t);
|
64
|
+
for(i = 0; i < 3; ++i) {
|
65
|
+
#{put}(&t, i*11);
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
cleanup %{
|
70
|
+
#{destroy}(&t);
|
71
|
+
}
|
72
|
+
|
73
|
+
test :iterate_3, %{
|
74
|
+
TEST_EQUAL( #{size}(&t), 3);
|
75
|
+
#{range} r = #{range.new}(&t);
|
76
|
+
TEST_FALSE( #{range.empty}(&r) );
|
77
|
+
#{range.pop_front}(&r);
|
78
|
+
TEST_FALSE( #{range.empty}(&r) );
|
79
|
+
#{range.pop_front}(&r);
|
80
|
+
TEST_FALSE( #{range.empty}(&r) );
|
81
|
+
#{range.pop_front}(&r);
|
82
|
+
TEST_TRUE( #{range.empty}(&r) );
|
83
|
+
}
|
84
|
+
|
85
|
+
###
|
86
|
+
|
87
|
+
setup %{
|
88
|
+
#{self} t;
|
89
|
+
#{create}(&t);
|
90
|
+
}
|
91
|
+
|
92
|
+
cleanup %{
|
93
|
+
#{destroy}(&t);
|
94
|
+
}
|
95
|
+
|
96
|
+
test :put_uniques, %{
|
97
|
+
TEST_TRUE( #{put}(&t, 0) );
|
98
|
+
TEST_TRUE( #{put}(&t, -1) );
|
99
|
+
TEST_TRUE( #{put}(&t, 1) );
|
100
|
+
TEST_EQUAL( #{size}(&t), 3 );
|
101
|
+
}
|
102
|
+
|
103
|
+
test :put_duplicates, %{
|
104
|
+
TEST_TRUE( #{put}(&t, 0) );
|
105
|
+
TEST_TRUE( #{put}(&t, -1) );
|
106
|
+
TEST_TRUE( #{put}(&t, 1) );
|
107
|
+
TEST_FALSE( #{put}(&t, 0) );
|
108
|
+
TEST_FALSE( #{put}(&t, 1) );
|
109
|
+
TEST_FALSE( #{put}(&t, -1) );
|
110
|
+
TEST_EQUAL( #{size}(&t), 3 );
|
111
|
+
}
|
112
|
+
|
113
|
+
test :push, %{
|
114
|
+
TEST_FALSE( #{push}(&t, 1) );
|
115
|
+
TEST_FALSE( #{push}(&t, -1) );
|
116
|
+
TEST_TRUE( #{push}(&t, 1) );
|
117
|
+
TEST_EQUAL( #{size}(&t), 2 );
|
118
|
+
}
|
119
|
+
|
120
|
+
test :contains, %{
|
121
|
+
TEST_FALSE( #{contains}(&t, -1) );
|
122
|
+
TEST_TRUE( #{put}(&t, -1) );
|
123
|
+
TEST_TRUE( #{contains}(&t, -1) );
|
124
|
+
}
|
125
|
+
|
126
|
+
###
|
127
|
+
|
128
|
+
setup %{
|
129
|
+
#{self} t, r;
|
130
|
+
#{create}(&t);
|
131
|
+
#{create}(&r);
|
132
|
+
}
|
133
|
+
|
134
|
+
cleanup %{
|
135
|
+
#{destroy}(&t);
|
136
|
+
#{destroy}(&r);
|
137
|
+
}
|
138
|
+
|
139
|
+
test :remove_empty, %{
|
140
|
+
TEST_EQUAL( #{size}(&t), 0 );
|
141
|
+
TEST_FALSE( #{remove}(&t, 0) );
|
142
|
+
TEST_TRUE( #{equal}(&t, &r) );
|
143
|
+
TEST_TRUE( #{equal}(&r, &t) );
|
144
|
+
}
|
145
|
+
|
146
|
+
test :remove_nonexistent, %{
|
147
|
+
TEST_TRUE( #{put}(&t, 1) );
|
148
|
+
TEST_TRUE( #{put}(&t, 2) );
|
149
|
+
TEST_TRUE( #{put}(&t, 3) );
|
150
|
+
TEST_TRUE( #{put}(&r, 1) );
|
151
|
+
TEST_TRUE( #{put}(&r, 2) );
|
152
|
+
TEST_TRUE( #{put}(&r, 3) );
|
153
|
+
TEST_EQUAL( #{size}(&t), 3 );
|
154
|
+
TEST_FALSE( #{remove}(&t, 0) );
|
155
|
+
TEST_TRUE( #{equal}(&t, &r) );
|
156
|
+
TEST_TRUE( #{equal}(&r, &t) );
|
157
|
+
}
|
158
|
+
|
159
|
+
test :remove, %{
|
160
|
+
TEST_TRUE( #{put}(&t, 1) );
|
161
|
+
TEST_TRUE( #{put}(&t, 2) );
|
162
|
+
TEST_TRUE( #{put}(&t, 3) );
|
163
|
+
TEST_TRUE( #{put}(&r, 1) );
|
164
|
+
TEST_TRUE( #{put}(&r, 3) );
|
165
|
+
TEST_EQUAL( #{size}(&t), 3 );
|
166
|
+
TEST_TRUE( #{contains}(&t, 2) );
|
167
|
+
TEST_TRUE( #{remove}(&t, 2) );
|
168
|
+
TEST_FALSE( #{contains}(&t, 2) );
|
169
|
+
TEST_TRUE( #{equal}(&t, &r) );
|
170
|
+
TEST_TRUE( #{equal}(&r, &t) );
|
171
|
+
}
|
172
|
+
|
173
|
+
###
|
174
|
+
|
175
|
+
setup %{
|
176
|
+
#{self} t1, t2;
|
177
|
+
#{create}(&t1);
|
178
|
+
#{create}(&t2);
|
179
|
+
}
|
180
|
+
|
181
|
+
cleanup %{
|
182
|
+
#{destroy}(&t1);
|
183
|
+
#{destroy}(&t2);
|
184
|
+
}
|
185
|
+
|
186
|
+
test :equal_empty, %{
|
187
|
+
TEST_EQUAL( #{size}(&t1), 0 );
|
188
|
+
TEST_EQUAL( #{size}(&t2), 0 );
|
189
|
+
TEST_TRUE( #{equal}(&t1, &t2) );
|
190
|
+
}
|
191
|
+
|
192
|
+
test :equal_one, %{
|
193
|
+
TEST_TRUE( #{put}(&t1, 3) );
|
194
|
+
TEST_TRUE( #{put}(&t2, 3) );
|
195
|
+
TEST_EQUAL( #{size}(&t1), 1 );
|
196
|
+
TEST_EQUAL( #{size}(&t2), 1 );
|
197
|
+
TEST_TRUE( #{equal}(&t1, &t2) );
|
198
|
+
}
|
199
|
+
|
200
|
+
test :equal, %{
|
201
|
+
TEST_TRUE( #{put}(&t1, 3) );
|
202
|
+
TEST_TRUE( #{put}(&t1, -3) );
|
203
|
+
TEST_TRUE( #{put}(&t1, 0) );
|
204
|
+
TEST_TRUE( #{put}(&t2, -3) );
|
205
|
+
TEST_TRUE( #{put}(&t2, 0) );
|
206
|
+
TEST_TRUE( #{put}(&t2, 3) );
|
207
|
+
TEST_EQUAL( #{size}(&t1), 3 );
|
208
|
+
TEST_EQUAL( #{size}(&t2), 3 );
|
209
|
+
TEST_TRUE( #{equal}(&t1, &t2) );
|
210
|
+
}
|
211
|
+
|
212
|
+
test :subset_empty, %{
|
213
|
+
TEST_TRUE( #{equal}(&t1, &t2) );
|
214
|
+
TEST_TRUE( #{subset}(&t1, &t1) );
|
215
|
+
TEST_TRUE( #{subset}(&t2, &t2) );
|
216
|
+
TEST_TRUE( #{subset}(&t1, &t2) );
|
217
|
+
TEST_TRUE( #{subset}(&t2, &t1) );
|
218
|
+
}
|
219
|
+
|
220
|
+
test :subset_equal, %{
|
221
|
+
TEST_TRUE( #{put}(&t1, 1) );
|
222
|
+
TEST_TRUE( #{put}(&t1, 2) );
|
223
|
+
TEST_TRUE( #{put}(&t1, 3) );
|
224
|
+
TEST_TRUE( #{put}(&t2, 3) );
|
225
|
+
TEST_TRUE( #{put}(&t2, 2) );
|
226
|
+
TEST_TRUE( #{put}(&t2, 1) );
|
227
|
+
/* t2 == t1 */
|
228
|
+
TEST_TRUE( #{equal}(&t1, &t2) );
|
229
|
+
TEST_TRUE( #{subset}(&t1, &t1) );
|
230
|
+
TEST_TRUE( #{subset}(&t2, &t2) );
|
231
|
+
TEST_TRUE( #{subset}(&t1, &t2) );
|
232
|
+
TEST_TRUE( #{subset}(&t2, &t1) );
|
233
|
+
}
|
234
|
+
|
235
|
+
test :subset, %{
|
236
|
+
TEST_TRUE( #{put}(&t1, 1) );
|
237
|
+
TEST_TRUE( #{put}(&t1, 2) );
|
238
|
+
TEST_TRUE( #{put}(&t1, 3) );
|
239
|
+
TEST_TRUE( #{put}(&t2, 2) );
|
240
|
+
TEST_TRUE( #{put}(&t2, 1) );
|
241
|
+
/* t2 < t1 */
|
242
|
+
TEST_FALSE( #{equal}(&t1, &t2) );
|
243
|
+
TEST_TRUE( #{subset}(&t1, &t1) );
|
244
|
+
TEST_TRUE( #{subset}(&t2, &t2) );
|
245
|
+
TEST_FALSE( #{subset}(&t1, &t2) );
|
246
|
+
TEST_TRUE( #{subset}(&t2, &t1) );
|
247
|
+
}
|
248
|
+
|
249
|
+
test :disjoint, %{
|
250
|
+
TEST_TRUE( #{put}(&t1, 1) );
|
251
|
+
TEST_TRUE( #{put}(&t1, 2) );
|
252
|
+
TEST_TRUE( #{put}(&t1, 3) );
|
253
|
+
TEST_TRUE( #{put}(&t2, -1) );
|
254
|
+
TEST_TRUE( #{put}(&t2, -2) );
|
255
|
+
TEST_TRUE( #{put}(&t2, -3) );
|
256
|
+
TEST_FALSE( #{equal}(&t1, &t2) );
|
257
|
+
TEST_TRUE( #{disjoint}(&t1, &t2) );
|
258
|
+
TEST_TRUE( #{disjoint}(&t2, &t1) );
|
259
|
+
TEST_TRUE( #{put}(&t1, 0) );
|
260
|
+
TEST_TRUE( #{put}(&t2, 0) );
|
261
|
+
TEST_FALSE( #{disjoint}(&t1, &t2) );
|
262
|
+
TEST_FALSE( #{disjoint}(&t2, &t1) );
|
263
|
+
}
|
264
|
+
|
265
|
+
test :disjoint_equal, %{
|
266
|
+
TEST_TRUE( #{put}(&t1, 1) );
|
267
|
+
TEST_TRUE( #{put}(&t1, 2) );
|
268
|
+
TEST_TRUE( #{put}(&t1, 3) );
|
269
|
+
TEST_TRUE( #{put}(&t2, 1) );
|
270
|
+
TEST_TRUE( #{put}(&t2, 2) );
|
271
|
+
TEST_TRUE( #{put}(&t2, 3) );
|
272
|
+
TEST_TRUE( #{equal}(&t1, &t2) );
|
273
|
+
TEST_FALSE( #{disjoint}(&t1, &t2) );
|
274
|
+
TEST_FALSE( #{disjoint}(&t2, &t1) );
|
275
|
+
}
|
276
|
+
|
277
|
+
test :disjoint_empty, %{
|
278
|
+
TEST_TRUE( #{equal}(&t1, &t2) );
|
279
|
+
TEST_TRUE( #{disjoint}(&t1, &t2) );
|
280
|
+
TEST_TRUE( #{disjoint}(&t2, &t1) );
|
281
|
+
}
|
282
|
+
|
283
|
+
###
|
284
|
+
|
285
|
+
setup %{
|
286
|
+
#{self} t1, t2, r, t;
|
287
|
+
#{create}(&t1);
|
288
|
+
#{create}(&t2);
|
289
|
+
#{create}(&r);
|
290
|
+
}
|
291
|
+
|
292
|
+
cleanup %{
|
293
|
+
#{destroy}(&t1);
|
294
|
+
#{destroy}(&t2);
|
295
|
+
#{destroy}(&r);
|
296
|
+
#{destroy}(&t);
|
297
|
+
}
|
298
|
+
|
299
|
+
test :join_empty, %{
|
300
|
+
#{create_join}(&t, &t1, &t2);
|
301
|
+
#{join}(&t1, &t2);
|
302
|
+
TEST_TRUE( #{equal}(&r, &t1) );
|
303
|
+
TEST_TRUE( #{equal}(&r, &t2) );
|
304
|
+
TEST_TRUE( #{equal}(&r, &t) );
|
305
|
+
}
|
306
|
+
|
307
|
+
test :join, %{
|
308
|
+
/* 1,2,3 */
|
309
|
+
TEST_TRUE( #{put}(&r, 1) );
|
310
|
+
TEST_TRUE( #{put}(&r, 2) );
|
311
|
+
TEST_TRUE( #{put}(&r, 3) );
|
312
|
+
/* 1,2 */
|
313
|
+
TEST_TRUE( #{put}(&t1, 1) );
|
314
|
+
TEST_TRUE( #{put}(&t1, 2) );
|
315
|
+
/* 1,3 */
|
316
|
+
TEST_TRUE( #{put}(&t2, 1) );
|
317
|
+
TEST_TRUE( #{put}(&t2, 3) );
|
318
|
+
#{create_join}(&t, &t1, &t2);
|
319
|
+
#{join}(&t1, &t2); /* 1,2 | 1,3 -> 1,2,3 */
|
320
|
+
TEST_TRUE( #{equal}(&r, &t1) );
|
321
|
+
TEST_TRUE( #{equal}(&t1, &r) );
|
322
|
+
TEST_FALSE( #{equal}(&r, &t2) );
|
323
|
+
TEST_FALSE( #{equal}(&t2, &r) );
|
324
|
+
TEST_TRUE( #{equal}(&t, &r) );
|
325
|
+
}
|
326
|
+
|
327
|
+
test :subtract, %{
|
328
|
+
/* 0,2 */
|
329
|
+
TEST_TRUE( #{put}(&r, 0) );
|
330
|
+
TEST_TRUE( #{put}(&r, 2) );
|
331
|
+
/* 0,1,2 */
|
332
|
+
TEST_TRUE( #{put}(&t1, 0) );
|
333
|
+
TEST_TRUE( #{put}(&t1, 1) );
|
334
|
+
TEST_TRUE( #{put}(&t1, 2) );
|
335
|
+
/* 1,3 */
|
336
|
+
TEST_TRUE( #{put}(&t2, 1) );
|
337
|
+
TEST_TRUE( #{put}(&t2, 3) );
|
338
|
+
#{create_difference}(&t, &t1, &t2); /* 0,1,2 - 1,3 -> 0,2 */
|
339
|
+
#{subtract}(&t1, &t2);
|
340
|
+
TEST_TRUE( #{equal}(&r, &t1) );
|
341
|
+
TEST_TRUE( #{equal}(&t1, &r) );
|
342
|
+
TEST_FALSE( #{equal}(&r, &t2) );
|
343
|
+
TEST_FALSE( #{equal}(&t2, &r) );
|
344
|
+
TEST_TRUE( #{equal}(&t, &t1) );
|
345
|
+
}
|
346
|
+
|
347
|
+
test :intersect_disjoint, %{
|
348
|
+
/* 1,2,3 */
|
349
|
+
TEST_TRUE( #{put}(&t1, 1) );
|
350
|
+
TEST_TRUE( #{put}(&t1, 2) );
|
351
|
+
TEST_TRUE( #{put}(&t1, 3) );
|
352
|
+
/* -1,-2,-3 */
|
353
|
+
TEST_TRUE( #{put}(&t2, -1) );
|
354
|
+
TEST_TRUE( #{put}(&t2, -2) );
|
355
|
+
TEST_TRUE( #{put}(&t2, -3) );
|
356
|
+
#{create_intersection}(&t, &t1, &t2);
|
357
|
+
#{intersect}(&t1, &t2);
|
358
|
+
TEST_TRUE( #{empty}(&t1) );
|
359
|
+
TEST_TRUE( #{equal}(&r, &t1) );
|
360
|
+
TEST_TRUE( #{equal}(&t1, &r) );
|
361
|
+
TEST_TRUE( #{equal}(&t, &r) );
|
362
|
+
TEST_TRUE( #{empty}(&t) );
|
363
|
+
}
|
364
|
+
|
365
|
+
test :intersect_equal, %{
|
366
|
+
/* 1,2,3 */
|
367
|
+
TEST_TRUE( #{put}(&t1, 1) );
|
368
|
+
TEST_TRUE( #{put}(&t1, 2) );
|
369
|
+
TEST_TRUE( #{put}(&t1, 3) );
|
370
|
+
/* 1,2,3 */
|
371
|
+
TEST_TRUE( #{put}(&t2, 3) );
|
372
|
+
TEST_TRUE( #{put}(&t2, 2) );
|
373
|
+
TEST_TRUE( #{put}(&t2, 1) );
|
374
|
+
/* 1,2,3 */
|
375
|
+
TEST_TRUE( #{put}(&r, 3) );
|
376
|
+
TEST_TRUE( #{put}(&r, 2) );
|
377
|
+
TEST_TRUE( #{put}(&r, 1) );
|
378
|
+
#{create_intersection}(&t, &t1, &t2);
|
379
|
+
#{intersect}(&t1, &t2); /* 1,2,3 & 1,2,3 -> 1,2,3 */
|
380
|
+
TEST_TRUE( #{equal}(&r, &t1) );
|
381
|
+
TEST_TRUE( #{equal}(&t1, &r) );
|
382
|
+
TEST_TRUE( #{equal}(&r, &t2) );
|
383
|
+
TEST_TRUE( #{equal}(&t2, &r) );
|
384
|
+
TEST_TRUE( #{equal}(&t1, &t2) );
|
385
|
+
TEST_TRUE( #{equal}(&t2, &t1) );
|
386
|
+
TEST_TRUE( #{equal}(&t, &r) );
|
387
|
+
}
|
388
|
+
|
389
|
+
test :intersect, %{
|
390
|
+
/* 0,1,2,3 */
|
391
|
+
TEST_TRUE( #{put}(&t1, 1) );
|
392
|
+
TEST_TRUE( #{put}(&t1, 2) );
|
393
|
+
TEST_TRUE( #{put}(&t1, 3) );
|
394
|
+
/* 0,-1,-2,-3 */
|
395
|
+
TEST_TRUE( #{put}(&t2, -1) );
|
396
|
+
TEST_TRUE( #{put}(&t2, -2) );
|
397
|
+
TEST_TRUE( #{put}(&t2, -3) );
|
398
|
+
TEST_TRUE( #{put}(&t1, 0) );
|
399
|
+
TEST_TRUE( #{put}(&t2, 0) );
|
400
|
+
TEST_TRUE( #{put}(&r, 0) );
|
401
|
+
#{create_intersection}(&t, &t1, &t2);
|
402
|
+
#{intersect}(&t1, &t2); /* 0,1,2,3 & 0,-1,-2,-3 -> 0 */
|
403
|
+
TEST_TRUE( #{equal}(&r, &t1) );
|
404
|
+
TEST_TRUE( #{equal}(&t1, &r) );
|
405
|
+
TEST_FALSE( #{equal}(&r, &t2) );
|
406
|
+
TEST_FALSE( #{equal}(&t2, &r) );
|
407
|
+
TEST_TRUE( #{equal}(&r, &t) );
|
408
|
+
}
|
409
|
+
|
410
|
+
test :disjoin_disjoint, %{
|
411
|
+
/* 1,2 */
|
412
|
+
TEST_TRUE( #{put}(&t1, 1) );
|
413
|
+
TEST_TRUE( #{put}(&t1, 2) );
|
414
|
+
/* 3,4 */
|
415
|
+
TEST_TRUE( #{put}(&t2, 4) );
|
416
|
+
TEST_TRUE( #{put}(&t2, 3) );
|
417
|
+
/* 1,2,3,4 */
|
418
|
+
TEST_TRUE( #{put}(&r, 3) );
|
419
|
+
TEST_TRUE( #{put}(&r, 1) );
|
420
|
+
TEST_TRUE( #{put}(&r, 2) );
|
421
|
+
TEST_TRUE( #{put}(&r, 4) );
|
422
|
+
#{create_disjunction}(&t, &t2, &t1);
|
423
|
+
#{disjoin}(&t1, &t2);
|
424
|
+
TEST_TRUE( #{equal}(&r, &t1) ); /* 1,2 ^ 3,4 -> 1,2,3,4 */
|
425
|
+
TEST_TRUE( #{equal}(&r, &t) );
|
426
|
+
}
|
427
|
+
|
428
|
+
test :disjoin, %{
|
429
|
+
/* 1,2,-3 */
|
430
|
+
TEST_TRUE( #{put}(&t1, -3) );
|
431
|
+
TEST_TRUE( #{put}(&t1, 1) );
|
432
|
+
TEST_TRUE( #{put}(&t1, 2) );
|
433
|
+
/* 3,4, -3 */
|
434
|
+
TEST_TRUE( #{put}(&t2, 4) );
|
435
|
+
TEST_TRUE( #{put}(&t2, 3) );
|
436
|
+
TEST_TRUE( #{put}(&t2, -3) );
|
437
|
+
/* 1,2,3,4 */
|
438
|
+
TEST_TRUE( #{put}(&r, 3) );
|
439
|
+
TEST_TRUE( #{put}(&r, 1) );
|
440
|
+
TEST_TRUE( #{put}(&r, 2) );
|
441
|
+
TEST_TRUE( #{put}(&r, 4) );
|
442
|
+
#{create_disjunction}(&t, &t2, &t1);
|
443
|
+
#{disjoin}(&t1, &t2);
|
444
|
+
TEST_TRUE( #{equal}(&r, &t1) ); /* 1,2, -3 ^ 3,4, -3 -> 1,2,3,4 */
|
445
|
+
TEST_TRUE( #{equal}(&r, &t) );
|
446
|
+
}
|
447
|
+
|
448
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'autoc/list'
|
2
|
+
|
3
|
+
[
|
4
|
+
[:IntListDefault, :int, {}],
|
5
|
+
[:IntListComputedSize, :int, { maintain_size: false }]
|
6
|
+
].each do |n, e, kws|
|
7
|
+
|
8
|
+
type_test(AutoC::List, n, e, **kws) do
|
9
|
+
|
10
|
+
###
|
11
|
+
|
12
|
+
setup %{
|
13
|
+
#{self} t;
|
14
|
+
#{create}(&t);
|
15
|
+
}
|
16
|
+
|
17
|
+
cleanup %{
|
18
|
+
#{destroy}(&t);
|
19
|
+
}
|
20
|
+
|
21
|
+
test :create, %{
|
22
|
+
TEST_TRUE( #{empty}(&t) );
|
23
|
+
TEST_EQUAL( #{size}(&t), 0 );
|
24
|
+
}
|
25
|
+
|
26
|
+
test :copy_empty, %{
|
27
|
+
#{self} r;
|
28
|
+
#{copy}(&r, &t);
|
29
|
+
TEST_TRUE( #{equal}(&r, &t) );
|
30
|
+
#{destroy}(&r);
|
31
|
+
}
|
32
|
+
|
33
|
+
test :copy, %{
|
34
|
+
#{self} r;
|
35
|
+
#{push_front}(&t, 1);
|
36
|
+
#{push_front}(&t, 2);
|
37
|
+
#{push_front}(&t, 3);
|
38
|
+
#{copy}(&r, &t);
|
39
|
+
TEST_TRUE( #{equal}(&r, &t) );
|
40
|
+
#{destroy}(&r);
|
41
|
+
}
|
42
|
+
|
43
|
+
###
|
44
|
+
|
45
|
+
setup %{
|
46
|
+
#{self} t;
|
47
|
+
#{create}(&t);
|
48
|
+
#{push_front}(&t, 1);
|
49
|
+
#{push_front}(&t, 2);
|
50
|
+
#{push_front}(&t, 3);
|
51
|
+
}
|
52
|
+
|
53
|
+
cleanup %{
|
54
|
+
#{destroy}(&t);
|
55
|
+
}
|
56
|
+
|
57
|
+
test :remove_none, %{
|
58
|
+
TEST_FALSE( #{remove_first.(:t, 4)} );
|
59
|
+
TEST_EQUAL( #{size.(:t)}, 3 );
|
60
|
+
}
|
61
|
+
|
62
|
+
test :remove_front, %{
|
63
|
+
TEST_TRUE( #{remove_first.(:t, 3)} );
|
64
|
+
TEST_EQUAL( #{size.(:t)}, 2 );
|
65
|
+
TEST_EQUAL( #{take_front.(:t)}, 2 );
|
66
|
+
}
|
67
|
+
|
68
|
+
test :remove_back, %{
|
69
|
+
TEST_TRUE( #{remove_first.(:t, 1)} );
|
70
|
+
TEST_EQUAL( #{size.(:t)}, 2 );
|
71
|
+
}
|
72
|
+
|
73
|
+
test :remove_middle, %{
|
74
|
+
TEST_TRUE( #{remove_first.(:t, 2)} );
|
75
|
+
TEST_EQUAL( #{size.(:t)}, 2 );
|
76
|
+
}
|
77
|
+
|
78
|
+
###
|
79
|
+
|
80
|
+
setup %{
|
81
|
+
int i, c = 3;
|
82
|
+
#{self} t1, t2;
|
83
|
+
#{create}(&t1);
|
84
|
+
#{create}(&t2);
|
85
|
+
for(i = 0; i < c; ++i) {
|
86
|
+
#{push_front}(&t1, i);
|
87
|
+
#{push_front}(&t2, i);
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
cleanup %{
|
92
|
+
#{destroy}(&t1);
|
93
|
+
#{destroy}(&t2);
|
94
|
+
}
|
95
|
+
|
96
|
+
test :equal, %{
|
97
|
+
TEST_EQUAL( #{size}(&t1), #{size}(&t2) );
|
98
|
+
TEST_TRUE( #{equal}(&t1, &t2) );
|
99
|
+
#{push_front}(&t2, -1);
|
100
|
+
TEST_NOT_EQUAL( #{size}(&t1), #{size}(&t2) );
|
101
|
+
TEST_FALSE( #{equal}(&t1, &t2) );
|
102
|
+
}
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'autoc/vector'
|
2
|
+
|
3
|
+
IntVector = type_test(AutoC::Vector, :IntVector, :int) do
|
4
|
+
|
5
|
+
###
|
6
|
+
|
7
|
+
setup %{
|
8
|
+
#{self} t;
|
9
|
+
}
|
10
|
+
|
11
|
+
cleanup %{
|
12
|
+
#{destroy}(&t);
|
13
|
+
}
|
14
|
+
|
15
|
+
test :create, %{
|
16
|
+
#{default_create.(:t)};
|
17
|
+
TEST_EQUAL( #{size}(&t), 0 );
|
18
|
+
}
|
19
|
+
|
20
|
+
test :create_size, %{
|
21
|
+
#{custom_create.(:t, 100)};
|
22
|
+
TEST_EQUAL( #{size}(&t), 100 );
|
23
|
+
}
|
24
|
+
|
25
|
+
###
|
26
|
+
|
27
|
+
setup %{
|
28
|
+
#{self} t1, t2;
|
29
|
+
int i, c = 3;
|
30
|
+
#{custom_create.(:t1, :c)};
|
31
|
+
#{custom_create.(:t2, :c)};
|
32
|
+
for(i = 0; i < c; ++i) {
|
33
|
+
#{set}(&t1, i, i);
|
34
|
+
#{set}(&t2, i, i);
|
35
|
+
/* 0,1,2 */
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
cleanup %{
|
40
|
+
#{destroy}(&t1);
|
41
|
+
#{destroy}(&t2);
|
42
|
+
}
|
43
|
+
|
44
|
+
test :equal_identity, %{
|
45
|
+
TEST_TRUE( #{equal.(:t1, :t1)} );
|
46
|
+
TEST_TRUE( #{equal.(:t2, :t2)} );
|
47
|
+
}
|
48
|
+
|
49
|
+
test :equal, %{
|
50
|
+
TEST_TRUE( #{equal.(:t1, :t2)} );
|
51
|
+
}
|
52
|
+
|
53
|
+
test :not_equal, %{
|
54
|
+
#{set}(&t1, 1, -1);
|
55
|
+
TEST_FALSE( #{equal.(:t1, :t2)} );
|
56
|
+
}
|
57
|
+
|
58
|
+
test :sort_resort, %{
|
59
|
+
#{sort}(&t2, -1);
|
60
|
+
TEST_EQUAL( #{get}(&t2, 0), 2);
|
61
|
+
TEST_FALSE( #{equal.(:t1, :t2)} );
|
62
|
+
#{sort}(&t2, +1);
|
63
|
+
TEST_EQUAL( #{get}(&t2, 0), 0);
|
64
|
+
TEST_TRUE( #{equal.(:t1, :t2)} );
|
65
|
+
}
|
66
|
+
|
67
|
+
test :sort_descend, %{
|
68
|
+
#{sort}(&t2, -1);
|
69
|
+
/* 2,1,0 */
|
70
|
+
TEST_FALSE( #{equal.(:t1, :t2)} );
|
71
|
+
TEST_EQUAL( #{get}(&t2, 0), 2 );
|
72
|
+
TEST_EQUAL( #{get}(&t2, 1), 1 );
|
73
|
+
}
|
74
|
+
|
75
|
+
test :sort_ascend, %{
|
76
|
+
#{sort}(&t2, +1);
|
77
|
+
/* 0,1,2 */
|
78
|
+
TEST_TRUE( #{equal.(:t1, :t2)} );
|
79
|
+
TEST_EQUAL( #{get}(&t2, 0), 0 );
|
80
|
+
TEST_EQUAL( #{get}(&t2, 1), 1 );
|
81
|
+
}
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'autoc/hash_map'
|
2
|
+
|
3
|
+
type_test(AutoC::HashMap, :Value2HashMap, Value, Value) do
|
4
|
+
|
5
|
+
###
|
6
|
+
|
7
|
+
setup %{
|
8
|
+
#{self} t;
|
9
|
+
}
|
10
|
+
|
11
|
+
cleanup %{
|
12
|
+
#{destroy}(&t);
|
13
|
+
}
|
14
|
+
|
15
|
+
test :create_empty, %{
|
16
|
+
#{default_create.(:t)};
|
17
|
+
}
|
18
|
+
|
19
|
+
###
|
20
|
+
|
21
|
+
setup %{
|
22
|
+
#{self} t;
|
23
|
+
#{element} e;
|
24
|
+
#{default_create.(:t)};
|
25
|
+
TEST_TRUE( #{empty.(:t)} );
|
26
|
+
TEST_EQUAL( #{size.(:t)}, 0 );
|
27
|
+
#{element.custom_create.(:e, -1)};
|
28
|
+
}
|
29
|
+
|
30
|
+
cleanup %{
|
31
|
+
#{destroy.(:t)};
|
32
|
+
#{element.destroy.(:e)};
|
33
|
+
}
|
34
|
+
|
35
|
+
test :put_single_identity, %{
|
36
|
+
#{set.(:t, :e, :e)};
|
37
|
+
TEST_FALSE( #{empty.(:t)} );
|
38
|
+
TEST_EQUAL( #{size.(:t)}, 1 );
|
39
|
+
}
|
40
|
+
|
41
|
+
test :put_repeated_identity, %{
|
42
|
+
#{set.(:t, :e, :e)};
|
43
|
+
#{set.(:t, :e, :e)};
|
44
|
+
TEST_FALSE( #{empty.(:t)} );
|
45
|
+
TEST_EQUAL( #{size.(:t)}, 1 );
|
46
|
+
}
|
47
|
+
|
48
|
+
###
|
49
|
+
|
50
|
+
setup %{
|
51
|
+
#{self} t;
|
52
|
+
#{element} e1, e2;
|
53
|
+
#{default_create.(:t)};
|
54
|
+
TEST_TRUE( #{empty.(:t)} );
|
55
|
+
TEST_EQUAL( #{size.(:t)}, 0 );
|
56
|
+
#{element.custom_create.(:e1, -1)};
|
57
|
+
#{element.custom_create.(:e2, +1)};
|
58
|
+
#{set.(:t, :e1, :e2)};
|
59
|
+
TEST_EQUAL( #{size.(:t)}, 1 );
|
60
|
+
}
|
61
|
+
|
62
|
+
cleanup %{
|
63
|
+
#{destroy.(:t)};
|
64
|
+
#{element.destroy.(:e1)};
|
65
|
+
#{element.destroy.(:e2)};
|
66
|
+
}
|
67
|
+
|
68
|
+
test :view_contains, %{
|
69
|
+
TEST_TRUE( #{contains.(:t, :e2)} );
|
70
|
+
TEST_FALSE( #{contains.(:t, :e1)} );
|
71
|
+
TEST_FALSE( #{empty.(:t)} );
|
72
|
+
TEST_EQUAL( #{size.(:t)}, 1 );
|
73
|
+
}
|
74
|
+
|
75
|
+
test :remove, %{
|
76
|
+
TEST_TRUE( #{contains.(:t, :e2)} );
|
77
|
+
TEST_FALSE( #{contains.(:t, :e1)} );
|
78
|
+
TEST_FALSE( #{remove.(:t, :e2)} );
|
79
|
+
TEST_TRUE( #{remove.(:t, :e1)} );
|
80
|
+
TEST_TRUE( #{empty.(:t)} );
|
81
|
+
}
|
82
|
+
|
83
|
+
end
|