isomorfeus-ferret 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +612 -0
- data/README.md +44 -0
- data/ext/isomorfeus_ferret_ext/benchmark.c +223 -0
- data/ext/isomorfeus_ferret_ext/benchmark.h +45 -0
- data/ext/isomorfeus_ferret_ext/benchmarks_all.h +25 -0
- data/ext/isomorfeus_ferret_ext/bm_bitvector.c +123 -0
- data/ext/isomorfeus_ferret_ext/bm_hash.c +118 -0
- data/ext/isomorfeus_ferret_ext/bm_micro_string.c +40 -0
- data/ext/isomorfeus_ferret_ext/bm_store.c +93 -0
- data/ext/isomorfeus_ferret_ext/email.rl +21 -0
- data/ext/isomorfeus_ferret_ext/extconf.rb +5 -0
- data/ext/isomorfeus_ferret_ext/fio_tmpfile.h +53 -0
- data/ext/isomorfeus_ferret_ext/frb_analysis.c +2577 -0
- data/ext/isomorfeus_ferret_ext/frb_index.c +3457 -0
- data/ext/isomorfeus_ferret_ext/frb_lang.c +9 -0
- data/ext/isomorfeus_ferret_ext/frb_lang.h +17 -0
- data/ext/isomorfeus_ferret_ext/frb_qparser.c +629 -0
- data/ext/isomorfeus_ferret_ext/frb_search.c +4460 -0
- data/ext/isomorfeus_ferret_ext/frb_store.c +515 -0
- data/ext/isomorfeus_ferret_ext/frb_threading.h +30 -0
- data/ext/isomorfeus_ferret_ext/frb_utils.c +1127 -0
- data/ext/isomorfeus_ferret_ext/frt_analysis.c +1644 -0
- data/ext/isomorfeus_ferret_ext/frt_analysis.h +247 -0
- data/ext/isomorfeus_ferret_ext/frt_array.c +124 -0
- data/ext/isomorfeus_ferret_ext/frt_array.h +54 -0
- data/ext/isomorfeus_ferret_ext/frt_bitvector.c +95 -0
- data/ext/isomorfeus_ferret_ext/frt_bitvector.h +586 -0
- data/ext/isomorfeus_ferret_ext/frt_compound_io.c +374 -0
- data/ext/isomorfeus_ferret_ext/frt_config.h +44 -0
- data/ext/isomorfeus_ferret_ext/frt_document.c +134 -0
- data/ext/isomorfeus_ferret_ext/frt_document.h +52 -0
- data/ext/isomorfeus_ferret_ext/frt_except.c +95 -0
- data/ext/isomorfeus_ferret_ext/frt_except.h +188 -0
- data/ext/isomorfeus_ferret_ext/frt_field_index.c +233 -0
- data/ext/isomorfeus_ferret_ext/frt_field_index.h +42 -0
- data/ext/isomorfeus_ferret_ext/frt_filter.c +157 -0
- data/ext/isomorfeus_ferret_ext/frt_fs_store.c +502 -0
- data/ext/isomorfeus_ferret_ext/frt_global.c +427 -0
- data/ext/isomorfeus_ferret_ext/frt_global.h +290 -0
- data/ext/isomorfeus_ferret_ext/frt_hash.c +518 -0
- data/ext/isomorfeus_ferret_ext/frt_hash.h +466 -0
- data/ext/isomorfeus_ferret_ext/frt_hashset.c +191 -0
- data/ext/isomorfeus_ferret_ext/frt_hashset.h +206 -0
- data/ext/isomorfeus_ferret_ext/frt_helper.c +62 -0
- data/ext/isomorfeus_ferret_ext/frt_helper.h +13 -0
- data/ext/isomorfeus_ferret_ext/frt_ind.c +353 -0
- data/ext/isomorfeus_ferret_ext/frt_ind.h +54 -0
- data/ext/isomorfeus_ferret_ext/frt_index.c +6377 -0
- data/ext/isomorfeus_ferret_ext/frt_index.h +880 -0
- data/ext/isomorfeus_ferret_ext/frt_lang.c +104 -0
- data/ext/isomorfeus_ferret_ext/frt_lang.h +44 -0
- data/ext/isomorfeus_ferret_ext/frt_mempool.c +87 -0
- data/ext/isomorfeus_ferret_ext/frt_mempool.h +33 -0
- data/ext/isomorfeus_ferret_ext/frt_multimapper.c +349 -0
- data/ext/isomorfeus_ferret_ext/frt_multimapper.h +52 -0
- data/ext/isomorfeus_ferret_ext/frt_posh.c +1006 -0
- data/ext/isomorfeus_ferret_ext/frt_posh.h +973 -0
- data/ext/isomorfeus_ferret_ext/frt_priorityqueue.c +147 -0
- data/ext/isomorfeus_ferret_ext/frt_priorityqueue.h +147 -0
- data/ext/isomorfeus_ferret_ext/frt_q_boolean.c +1612 -0
- data/ext/isomorfeus_ferret_ext/frt_q_const_score.c +157 -0
- data/ext/isomorfeus_ferret_ext/frt_q_filtered_query.c +209 -0
- data/ext/isomorfeus_ferret_ext/frt_q_fuzzy.c +281 -0
- data/ext/isomorfeus_ferret_ext/frt_q_match_all.c +147 -0
- data/ext/isomorfeus_ferret_ext/frt_q_multi_term.c +672 -0
- data/ext/isomorfeus_ferret_ext/frt_q_parser.c +3084 -0
- data/ext/isomorfeus_ferret_ext/frt_q_phrase.c +1182 -0
- data/ext/isomorfeus_ferret_ext/frt_q_prefix.c +98 -0
- data/ext/isomorfeus_ferret_ext/frt_q_range.c +665 -0
- data/ext/isomorfeus_ferret_ext/frt_q_span.c +2386 -0
- data/ext/isomorfeus_ferret_ext/frt_q_term.c +311 -0
- data/ext/isomorfeus_ferret_ext/frt_q_wildcard.c +166 -0
- data/ext/isomorfeus_ferret_ext/frt_ram_store.c +460 -0
- data/ext/isomorfeus_ferret_ext/frt_scanner.c +899 -0
- data/ext/isomorfeus_ferret_ext/frt_scanner.h +28 -0
- data/ext/isomorfeus_ferret_ext/frt_scanner_mb.c +6705 -0
- data/ext/isomorfeus_ferret_ext/frt_scanner_utf8.c +4419 -0
- data/ext/isomorfeus_ferret_ext/frt_search.c +1824 -0
- data/ext/isomorfeus_ferret_ext/frt_search.h +924 -0
- data/ext/isomorfeus_ferret_ext/frt_similarity.c +150 -0
- data/ext/isomorfeus_ferret_ext/frt_similarity.h +79 -0
- data/ext/isomorfeus_ferret_ext/frt_sort.c +796 -0
- data/ext/isomorfeus_ferret_ext/frt_stopwords.c +395 -0
- data/ext/isomorfeus_ferret_ext/frt_store.c +680 -0
- data/ext/isomorfeus_ferret_ext/frt_store.h +789 -0
- data/ext/isomorfeus_ferret_ext/frt_term_vectors.c +72 -0
- data/ext/isomorfeus_ferret_ext/frt_threading.h +23 -0
- data/ext/isomorfeus_ferret_ext/frt_win32.h +54 -0
- data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.c +409 -0
- data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.h +95 -0
- data/ext/isomorfeus_ferret_ext/libstemmer.c +93 -0
- data/ext/isomorfeus_ferret_ext/libstemmer.h +73 -0
- data/ext/isomorfeus_ferret_ext/q_parser.y +1366 -0
- data/ext/isomorfeus_ferret_ext/scanner.h +28 -0
- data/ext/isomorfeus_ferret_ext/scanner.in +43 -0
- data/ext/isomorfeus_ferret_ext/scanner.rl +84 -0
- data/ext/isomorfeus_ferret_ext/scanner_mb.rl +200 -0
- data/ext/isomorfeus_ferret_ext/scanner_utf8.rl +85 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_danish.c +324 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_danish.h +7 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_dutch.c +610 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_dutch.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_english.c +1104 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_english.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_finnish.c +749 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_finnish.h +7 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_french.c +1233 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_french.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_german.c +490 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_german.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_hungarian.c +1217 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_hungarian.h +7 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_italian.c +1052 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_italian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_norwegian.c +283 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_norwegian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_porter.c +735 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_porter.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_portuguese.c +1003 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_portuguese.h +7 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_spanish.c +1079 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_spanish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_swedish.c +293 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_swedish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_romanian.c +984 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_romanian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_KOI8_R_russian.c +686 -0
- data/ext/isomorfeus_ferret_ext/stem_KOI8_R_russian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_danish.c +325 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_danish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_dutch.c +620 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_dutch.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_english.c +1111 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_english.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_finnish.c +754 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_finnish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_french.c +1242 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_french.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_german.c +495 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_german.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_hungarian.c +1220 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_hungarian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_italian.c +1059 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_italian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_norwegian.c +285 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_norwegian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_porter.c +741 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_porter.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_portuguese.c +1009 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_portuguese.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_romanian.c +990 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_romanian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_russian.c +680 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_russian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_spanish.c +1083 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_spanish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_swedish.c +294 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_swedish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_turkish.c +2191 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_turkish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_api.c +66 -0
- data/ext/isomorfeus_ferret_ext/stem_api.h +26 -0
- data/ext/isomorfeus_ferret_ext/stem_header.h +57 -0
- data/ext/isomorfeus_ferret_ext/stem_modules.h +190 -0
- data/ext/isomorfeus_ferret_ext/stem_modules.txt +50 -0
- data/ext/isomorfeus_ferret_ext/stem_utilities.c +478 -0
- data/ext/isomorfeus_ferret_ext/test.c +850 -0
- data/ext/isomorfeus_ferret_ext/test.h +416 -0
- data/ext/isomorfeus_ferret_ext/test_1710.c +63 -0
- data/ext/isomorfeus_ferret_ext/test_analysis.c +1221 -0
- data/ext/isomorfeus_ferret_ext/test_array.c +272 -0
- data/ext/isomorfeus_ferret_ext/test_bitvector.c +600 -0
- data/ext/isomorfeus_ferret_ext/test_compound_io.c +170 -0
- data/ext/isomorfeus_ferret_ext/test_document.c +156 -0
- data/ext/isomorfeus_ferret_ext/test_except.c +244 -0
- data/ext/isomorfeus_ferret_ext/test_fields.c +522 -0
- data/ext/isomorfeus_ferret_ext/test_file_deleter.c +185 -0
- data/ext/isomorfeus_ferret_ext/test_filter.c +331 -0
- data/ext/isomorfeus_ferret_ext/test_fs_store.c +25 -0
- data/ext/isomorfeus_ferret_ext/test_global.c +299 -0
- data/ext/isomorfeus_ferret_ext/test_hash.c +485 -0
- data/ext/isomorfeus_ferret_ext/test_hashset.c +288 -0
- data/ext/isomorfeus_ferret_ext/test_helper.c +47 -0
- data/ext/isomorfeus_ferret_ext/test_highlighter.c +548 -0
- data/ext/isomorfeus_ferret_ext/test_index.c +2323 -0
- data/ext/isomorfeus_ferret_ext/test_lang.c +74 -0
- data/ext/isomorfeus_ferret_ext/test_mempool.c +102 -0
- data/ext/isomorfeus_ferret_ext/test_multimapper.c +64 -0
- data/ext/isomorfeus_ferret_ext/test_priorityqueue.c +213 -0
- data/ext/isomorfeus_ferret_ext/test_q_const_score.c +84 -0
- data/ext/isomorfeus_ferret_ext/test_q_filtered.c +61 -0
- data/ext/isomorfeus_ferret_ext/test_q_fuzzy.c +241 -0
- data/ext/isomorfeus_ferret_ext/test_q_parser.c +464 -0
- data/ext/isomorfeus_ferret_ext/test_q_span.c +575 -0
- data/ext/isomorfeus_ferret_ext/test_ram_store.c +77 -0
- data/ext/isomorfeus_ferret_ext/test_search.c +1874 -0
- data/ext/isomorfeus_ferret_ext/test_segments.c +167 -0
- data/ext/isomorfeus_ferret_ext/test_similarity.c +25 -0
- data/ext/isomorfeus_ferret_ext/test_sort.c +333 -0
- data/ext/isomorfeus_ferret_ext/test_store.c +591 -0
- data/ext/isomorfeus_ferret_ext/test_store.h +3 -0
- data/ext/isomorfeus_ferret_ext/test_term.c +351 -0
- data/ext/isomorfeus_ferret_ext/test_term_vectors.c +373 -0
- data/ext/isomorfeus_ferret_ext/test_test.c +83 -0
- data/ext/isomorfeus_ferret_ext/test_threading.c +188 -0
- data/ext/isomorfeus_ferret_ext/testhelper.c +561 -0
- data/ext/isomorfeus_ferret_ext/testhelper.h +25 -0
- data/ext/isomorfeus_ferret_ext/tests_all.h +87 -0
- data/ext/isomorfeus_ferret_ext/uchar-ucs4.rl +1854 -0
- data/ext/isomorfeus_ferret_ext/uchar-utf8.rl +1999 -0
- data/ext/isomorfeus_ferret_ext/url.rl +27 -0
- data/ext/isomorfeus_ferret_ext/word_list.h +15156 -0
- data/lib/isomorfeus/ferret/document.rb +132 -0
- data/lib/isomorfeus/ferret/field_symbol.rb +85 -0
- data/lib/isomorfeus/ferret/index/field_infos.rb +48 -0
- data/lib/isomorfeus/ferret/index/index.rb +970 -0
- data/lib/isomorfeus/ferret/monitor.rb +323 -0
- data/lib/isomorfeus/ferret/stdlib_patches.rb +151 -0
- data/lib/isomorfeus/ferret/version.rb +5 -0
- data/lib/isomorfeus-ferret.rb +8 -0
- metadata +307 -0
@@ -0,0 +1,288 @@
|
|
1
|
+
#include "frt_global.h"
|
2
|
+
#include "frt_hashset.h"
|
3
|
+
#include "test.h"
|
4
|
+
|
5
|
+
/**
|
6
|
+
* Test basic FrtHashSet functions like adding elements and testing for
|
7
|
+
* existence.
|
8
|
+
*/
|
9
|
+
static void test_hs(TestCase *tc, void *data)
|
10
|
+
{
|
11
|
+
char *two = frt_estrdup("two");
|
12
|
+
FrtHashSet *hs = frt_hs_new_str(&free);
|
13
|
+
(void)data; /* suppress unused argument warning */
|
14
|
+
|
15
|
+
Atrue(FRT_HASH_KEY_EQUAL);
|
16
|
+
Atrue(!FRT_HASH_KEY_DOES_NOT_EXIST);
|
17
|
+
Aiequal(0, hs->size);
|
18
|
+
|
19
|
+
Aiequal(FRT_HASH_KEY_DOES_NOT_EXIST, frt_hs_add(hs, frt_estrdup("one")));
|
20
|
+
Aiequal(1, hs->size);
|
21
|
+
Aiequal(FRT_HASH_KEY_EQUAL, frt_hs_exists(hs, "one"));
|
22
|
+
Aiequal(FRT_HASH_KEY_DOES_NOT_EXIST, frt_hs_exists(hs, two));
|
23
|
+
|
24
|
+
Aiequal(FRT_HASH_KEY_EQUAL, frt_hs_add(hs, frt_estrdup("one")));
|
25
|
+
Aiequal(1, hs->size);
|
26
|
+
Aiequal(FRT_HASH_KEY_EQUAL, frt_hs_exists(hs, "one"));
|
27
|
+
|
28
|
+
frt_hs_add(hs, two);
|
29
|
+
Aiequal(FRT_HASH_KEY_EQUAL, frt_hs_exists(hs, "one"));
|
30
|
+
Aiequal(FRT_HASH_KEY_EQUAL, frt_hs_exists(hs, "two"));
|
31
|
+
Aiequal(FRT_HASH_KEY_SAME, frt_hs_exists(hs, two));
|
32
|
+
Apequal(two, frt_hs_orig(hs, "two"));
|
33
|
+
Apequal(two, frt_hs_orig(hs, two));
|
34
|
+
Aiequal(FRT_HASH_KEY_DOES_NOT_EXIST, frt_hs_exists(hs, "three"));
|
35
|
+
Aiequal(2, hs->size);
|
36
|
+
|
37
|
+
frt_hs_add(hs, frt_estrdup("three"));
|
38
|
+
Aiequal(FRT_HASH_KEY_EQUAL, frt_hs_exists(hs, "one"));
|
39
|
+
Aiequal(FRT_HASH_KEY_EQUAL, frt_hs_exists(hs, "two"));
|
40
|
+
Aiequal(FRT_HASH_KEY_SAME, frt_hs_exists(hs, two));
|
41
|
+
Aiequal(FRT_HASH_KEY_EQUAL, frt_hs_exists(hs, "three"));
|
42
|
+
Aiequal(3, hs->size);
|
43
|
+
|
44
|
+
frt_hs_del(hs, "two");
|
45
|
+
Aiequal(FRT_HASH_KEY_EQUAL, frt_hs_exists(hs, "one"));
|
46
|
+
Aiequal(FRT_HASH_KEY_DOES_NOT_EXIST, frt_hs_exists(hs, "two"));
|
47
|
+
Aiequal(FRT_HASH_KEY_EQUAL, frt_hs_exists(hs, "three"));
|
48
|
+
Aiequal(2, hs->size);
|
49
|
+
Asequal("one", hs->first->elem);
|
50
|
+
Asequal("three", hs->first->next->elem);
|
51
|
+
|
52
|
+
frt_hs_clear(hs);
|
53
|
+
Aiequal(FRT_HASH_KEY_DOES_NOT_EXIST, frt_hs_exists(hs, "one"));
|
54
|
+
Aiequal(FRT_HASH_KEY_DOES_NOT_EXIST, frt_hs_exists(hs, "two"));
|
55
|
+
Aiequal(FRT_HASH_KEY_DOES_NOT_EXIST, frt_hs_exists(hs, "three"));
|
56
|
+
Aiequal(0, hs->size);
|
57
|
+
|
58
|
+
frt_hs_destroy(hs);
|
59
|
+
}
|
60
|
+
|
61
|
+
static void test_hs_ptr(TestCase *tc, void *data)
|
62
|
+
{
|
63
|
+
FrtHashSet *hs = frt_hs_new_ptr(NULL);
|
64
|
+
FrtSymbol word1 = rb_intern("one"), word2 = rb_intern("two");
|
65
|
+
char *word_one = frt_estrdup("one");
|
66
|
+
(void)data; /* suppress unused argument warning */
|
67
|
+
|
68
|
+
Aiequal(0, hs->size);
|
69
|
+
|
70
|
+
Aiequal(FRT_HASH_KEY_DOES_NOT_EXIST, frt_hs_add(hs, (void *)word1));
|
71
|
+
Aiequal(1, hs->size);
|
72
|
+
Aiequal(FRT_HASH_KEY_SAME, frt_hs_exists(hs, (void *)word1));
|
73
|
+
Aiequal(FRT_HASH_KEY_DOES_NOT_EXIST, frt_hs_exists(hs, "one"));
|
74
|
+
Aiequal(FRT_HASH_KEY_SAME, frt_hs_add(hs, (void *)word1));
|
75
|
+
Aiequal(1, hs->size);
|
76
|
+
|
77
|
+
Aiequal(FRT_HASH_KEY_DOES_NOT_EXIST, frt_hs_add(hs, (void *)word2));
|
78
|
+
Aiequal(2, hs->size);
|
79
|
+
Aiequal(FRT_HASH_KEY_SAME, frt_hs_exists(hs, (void *)word2));
|
80
|
+
Aiequal(FRT_HASH_KEY_DOES_NOT_EXIST, frt_hs_exists(hs, "two"));
|
81
|
+
Aiequal(FRT_HASH_KEY_SAME, frt_hs_add(hs, (void *)word2));
|
82
|
+
Aiequal(2, hs->size);
|
83
|
+
|
84
|
+
Aiequal(FRT_HASH_KEY_DOES_NOT_EXIST, frt_hs_add(hs, (void *)word_one));
|
85
|
+
Aiequal(3, hs->size);
|
86
|
+
Aiequal(FRT_HASH_KEY_SAME, frt_hs_exists(hs, word_one));
|
87
|
+
Aiequal(FRT_HASH_KEY_DOES_NOT_EXIST, frt_hs_exists(hs, "one"));
|
88
|
+
Aiequal(FRT_HASH_KEY_SAME, frt_hs_add(hs, (void *)word_one));
|
89
|
+
Aiequal(3, hs->size);
|
90
|
+
|
91
|
+
free(word_one);
|
92
|
+
frt_hs_destroy(hs);
|
93
|
+
}
|
94
|
+
|
95
|
+
/**
|
96
|
+
* Test hs_add_safe
|
97
|
+
*/
|
98
|
+
|
99
|
+
static void test_hs_add_safe(TestCase *tc, void *data)
|
100
|
+
{
|
101
|
+
char *str = frt_estrdup("one");
|
102
|
+
FrtHashSet *hs = frt_hs_new_str(&free);
|
103
|
+
(void)data; /* suppress unused argument warning */
|
104
|
+
|
105
|
+
Atrue(frt_hs_add_safe(hs, str));
|
106
|
+
Atrue(frt_hs_add_safe(hs, (char *)str));
|
107
|
+
Atrue(!frt_hs_add_safe(hs, (char *)"one"));
|
108
|
+
|
109
|
+
int to_add = 100;
|
110
|
+
int idx = 0;
|
111
|
+
for (; to_add >= 0; --to_add)
|
112
|
+
{
|
113
|
+
snprintf(str, sizeof(str)/sizeof(str[0]), "%d", idx);
|
114
|
+
Atrue(frt_hs_add_safe(hs, frt_estrdup(str)));
|
115
|
+
++idx;
|
116
|
+
}
|
117
|
+
|
118
|
+
for (idx = 0; idx <= to_add; ++idx)
|
119
|
+
{
|
120
|
+
snprintf(str, sizeof(str)/sizeof(str[0]), "%d", idx);
|
121
|
+
Aiequal(FRT_HASH_KEY_EQUAL, frt_hs_exists(hs, str));
|
122
|
+
}
|
123
|
+
|
124
|
+
frt_hs_destroy(hs);
|
125
|
+
}
|
126
|
+
|
127
|
+
/**
|
128
|
+
* Test merging of two HashSets. When one FrtHashSet is merged into another the
|
129
|
+
* FrtHashSet that was merged should be destroyed including all elements that
|
130
|
+
* weren't added to the final HashSet.
|
131
|
+
*/
|
132
|
+
static void test_hs_merge(TestCase *tc, void *data)
|
133
|
+
{
|
134
|
+
FrtHashSet *hs1 = frt_hs_new_str(&free);
|
135
|
+
FrtHashSet *hs2 = frt_hs_new_str(&free);
|
136
|
+
FrtHashSetEntry *hse;
|
137
|
+
(void)data; /* suppress unused argument warning */
|
138
|
+
|
139
|
+
frt_hs_add(hs1, frt_estrdup("one"));
|
140
|
+
frt_hs_add(hs1, frt_estrdup("two"));
|
141
|
+
frt_hs_add(hs1, frt_estrdup("three"));
|
142
|
+
frt_hs_add(hs2, frt_estrdup("two"));
|
143
|
+
frt_hs_add(hs2, frt_estrdup("three"));
|
144
|
+
frt_hs_add(hs2, frt_estrdup("four"));
|
145
|
+
Aiequal(3, hs1->size);
|
146
|
+
Aiequal(3, hs2->size);
|
147
|
+
frt_hs_merge(hs1, hs2);
|
148
|
+
Aiequal(4, hs1->size);
|
149
|
+
hse = hs1->first;
|
150
|
+
Asequal("one", hse->elem);
|
151
|
+
hse = hse->next;
|
152
|
+
Asequal("two", hse->elem);
|
153
|
+
hse = hse->next;
|
154
|
+
Asequal("three", hse->elem);
|
155
|
+
hse = hse->next;
|
156
|
+
Asequal("four", hse->elem);
|
157
|
+
hse = hse->next;
|
158
|
+
Apnull(hse);
|
159
|
+
frt_hs_destroy(hs1);
|
160
|
+
}
|
161
|
+
|
162
|
+
/**
|
163
|
+
* Free Mock used to test that certain elements are being freed when the
|
164
|
+
* FrtHashSet is destroyed.
|
165
|
+
*/
|
166
|
+
static void hs_free_mock(void *p)
|
167
|
+
{
|
168
|
+
char *str = (char *) p;
|
169
|
+
strcpy(str, "free");
|
170
|
+
}
|
171
|
+
|
172
|
+
/**
|
173
|
+
* Test that HashSets are freed correctly. That is, make sure that when a
|
174
|
+
* FrtHashSet is destroyed, all elements have the correct free function called on
|
175
|
+
* them
|
176
|
+
*/
|
177
|
+
static void test_hs_free(TestCase *tc, void *data)
|
178
|
+
{
|
179
|
+
char str1[10], str2[10], str3[10], str4[10], str5[10];
|
180
|
+
FrtHashSet *hs1 = frt_hs_new_str(&hs_free_mock);
|
181
|
+
FrtHashSet *hs2 = frt_hs_new_str(&hs_free_mock);
|
182
|
+
FrtHashSetEntry *hse;
|
183
|
+
(void)data; /* suppress unused argument warning */
|
184
|
+
|
185
|
+
strcpy(str1, "one");
|
186
|
+
strcpy(str2, "one");
|
187
|
+
Atrue(frt_hs_add_safe(hs1, (char *)str1));
|
188
|
+
Atrue(frt_hs_add_safe(hs1, (char *)str1));
|
189
|
+
Atrue(!frt_hs_add_safe(hs1, (char *)"one"));
|
190
|
+
Asequal("one", str1);
|
191
|
+
|
192
|
+
frt_hs_add(hs1, str2);
|
193
|
+
Asequal("free", str2);
|
194
|
+
frt_hs_rem(hs1, "one");
|
195
|
+
Aiequal(FRT_HASH_KEY_DOES_NOT_EXIST, frt_hs_exists(hs1, "one"));
|
196
|
+
Asequal("one", str1);
|
197
|
+
frt_hs_add(hs1, str1);
|
198
|
+
frt_hs_del(hs1, "one");
|
199
|
+
Aiequal(FRT_HASH_KEY_DOES_NOT_EXIST, frt_hs_exists(hs1, "one"));
|
200
|
+
Asequal("free", str1);
|
201
|
+
|
202
|
+
strcpy(str1, "one");
|
203
|
+
strcpy(str2, "two");
|
204
|
+
strcpy(str3, "three");
|
205
|
+
strcpy(str4, "three");
|
206
|
+
strcpy(str5, "four");
|
207
|
+
frt_hs_add(hs1, str1);
|
208
|
+
frt_hs_add(hs1, str2);
|
209
|
+
frt_hs_add(hs1, str3);
|
210
|
+
frt_hs_add(hs2, str2);
|
211
|
+
frt_hs_add(hs2, str4);
|
212
|
+
frt_hs_add(hs2, str5);
|
213
|
+
Aiequal(3, hs1->size);
|
214
|
+
Aiequal(3, hs2->size);
|
215
|
+
frt_hs_merge(hs1, hs2);
|
216
|
+
Aiequal(4, hs1->size);
|
217
|
+
Asequal("free", str4);
|
218
|
+
hse = hs1->first;
|
219
|
+
Apequal(str1, hse->elem);
|
220
|
+
hse = hse->next;
|
221
|
+
Apequal(str2, hse->elem);
|
222
|
+
hse = hse->next;
|
223
|
+
Apequal(str3, hse->elem);
|
224
|
+
hse = hse->next;
|
225
|
+
Apequal(str5, hse->elem);
|
226
|
+
hse = hse->next;
|
227
|
+
Apnull(hse);
|
228
|
+
Asequal("one", str1);
|
229
|
+
Asequal("two", str2);
|
230
|
+
Asequal("three", str3);
|
231
|
+
Asequal("four", str5);
|
232
|
+
frt_hs_destroy(hs1);
|
233
|
+
Asequal("free", str1);
|
234
|
+
Asequal("free", str2);
|
235
|
+
Asequal("free", str3);
|
236
|
+
Asequal("free", str5);
|
237
|
+
}
|
238
|
+
|
239
|
+
/**
|
240
|
+
* FrtHashSet stress test. Make sure the FrtHashSet works under load.
|
241
|
+
*/
|
242
|
+
#define HS_STRESS_NUM 10000 /* number of adds to the FrtHashSet */
|
243
|
+
#define HS_STRESS_MAX 100 /* number of elements allowed in the FrtHashSet */
|
244
|
+
static void stress_hs(TestCase *tc, void *data)
|
245
|
+
{
|
246
|
+
int i;
|
247
|
+
char buf[100];
|
248
|
+
FrtHashSet *hs = frt_hs_new_str(&free);
|
249
|
+
(void)data; /* suppress unused argument warning */
|
250
|
+
|
251
|
+
for (i = 0; i < HS_STRESS_NUM; i++) {
|
252
|
+
sprintf(buf, "<%d>", rand() % HS_STRESS_MAX);
|
253
|
+
frt_hs_add(hs, frt_estrdup(buf));
|
254
|
+
}
|
255
|
+
Assert(hs->size <= HS_STRESS_MAX,
|
256
|
+
"all numbers should be between 0 and %d", HS_STRESS_MAX);
|
257
|
+
|
258
|
+
/* make sure none of the slots were left out for next test */
|
259
|
+
for (i = 0; i < HS_STRESS_MAX; i++) {
|
260
|
+
sprintf(buf, "<%d>", i);
|
261
|
+
frt_hs_add(hs, frt_estrdup(buf));
|
262
|
+
}
|
263
|
+
|
264
|
+
for (i = 0; i < HS_STRESS_MAX; i++) {
|
265
|
+
sprintf(buf, "<%d>", i);
|
266
|
+
if (!Atrue(frt_hs_exists(hs, buf))) {
|
267
|
+
Tmsg("Couldn't find \"%s\"", buf);
|
268
|
+
}
|
269
|
+
}
|
270
|
+
frt_hs_destroy(hs);
|
271
|
+
}
|
272
|
+
|
273
|
+
/**
|
274
|
+
* FrtHashSet Test Suite
|
275
|
+
*/
|
276
|
+
TestSuite *ts_hashset(TestSuite *suite)
|
277
|
+
{
|
278
|
+
suite = ADD_SUITE(suite);
|
279
|
+
|
280
|
+
tst_run_test(suite, test_hs, NULL);
|
281
|
+
tst_run_test(suite, test_hs_ptr, NULL);
|
282
|
+
tst_run_test(suite, test_hs_add_safe, NULL);
|
283
|
+
tst_run_test(suite, test_hs_merge, NULL);
|
284
|
+
tst_run_test(suite, test_hs_free, NULL);
|
285
|
+
tst_run_test(suite, stress_hs, NULL);
|
286
|
+
|
287
|
+
return suite;
|
288
|
+
}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#include "frt_helper.h"
|
2
|
+
#include "test.h"
|
3
|
+
|
4
|
+
static void test_hlp_string_diff(TestCase *tc, void *data)
|
5
|
+
{
|
6
|
+
(void)data; /* suppress unused argument warning */
|
7
|
+
|
8
|
+
Aiequal(3, frt_hlp_string_diff("David", "Dave"));
|
9
|
+
Aiequal(0, frt_hlp_string_diff("David", "Erik"));
|
10
|
+
Aiequal(4, frt_hlp_string_diff("book", "bookworm"));
|
11
|
+
Aiequal(4, frt_hlp_string_diff("bookstop", "book"));
|
12
|
+
Aiequal(4, frt_hlp_string_diff("bookstop", "bookworm"));
|
13
|
+
}
|
14
|
+
|
15
|
+
void test_byte2float(TestCase *tc, void *data)
|
16
|
+
{
|
17
|
+
int i;
|
18
|
+
(void)data;
|
19
|
+
|
20
|
+
for (i = 0; i < 256; i++) {
|
21
|
+
Aiequal(i, frt_float2byte(frt_byte2float((char)i)));
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
void test_int2float(TestCase *tc, void *data)
|
26
|
+
{
|
27
|
+
int i;
|
28
|
+
(void)data;
|
29
|
+
|
30
|
+
for (i = 0; i < 256; i++) {
|
31
|
+
int x = rand() % 20000000;
|
32
|
+
float f = (float)i;
|
33
|
+
Aiequal(x, frt_float2int(frt_int2float(x)));
|
34
|
+
Afequal(f, frt_int2float(frt_float2int(f)));
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
TestSuite *ts_helper(TestSuite *suite)
|
39
|
+
{
|
40
|
+
suite = ADD_SUITE(suite);
|
41
|
+
|
42
|
+
tst_run_test(suite, test_hlp_string_diff, NULL);
|
43
|
+
tst_run_test(suite, test_byte2float, NULL);
|
44
|
+
tst_run_test(suite, test_int2float, NULL);
|
45
|
+
|
46
|
+
return suite;
|
47
|
+
}
|