diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/ampatree_test.c | 117 | ||||
-rw-r--r-- | test/patree_test.c | 117 | ||||
-rw-r--r-- | test/trie_test.c | 117 |
3 files changed, 0 insertions, 351 deletions
diff --git a/test/ampatree_test.c b/test/ampatree_test.c deleted file mode 100644 index bc7d161..0000000 --- a/test/ampatree_test.c +++ /dev/null @@ -1,117 +0,0 @@ -/* - Copyright 2011-2016 David Robillard <http://drobilla.net> - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -#include "zix/ampatree.h" -#include "zix/common.h" - -#include <stdarg.h> -#include <stdio.h> -#include <string.h> - -static const char* strings[] = { - "http://example.org/foo", - "http://example.org/bar", - "http://example.org/baz", - "http://example.net/foo", - "http://example.net/bar", - "http://example.net/baz", - "http://drobilla.net/", - "http://drobilla.net/software/zix", - "http://www.gbengasesan.com/blog", - "http://www.gbengasesan.com", - "http://echo.jpl.nasa.gov/~lance/delta_v/delta_v.rendezvous.html", - "http://echo.jpl.nasa.gov/asteroids/1986da/1986DA.html", - "http://echo.jpl.nasa.gov/", - "http://echo.jpl.nasa.gov/asteroids/1620_Geographos/geographos.html", - "http://echo.jpl.nasa.gov/~ostro/KY26/", - "http://echo.jpl.nasa.gov/~ostro/KY26/JPL_press_release.text", - "http://echo.jpl.nasa.gov", - "http://echo.jpl.nasa.gov/asteroids/4179_Toutatis/toutatis.html", - "http://echo.jpl.nasa.gov/asteroids/4769_Castalia/cast01.html", - "http://echo.jpl.nasa.gov/publications/review_abs.html", -}; - -ZIX_LOG_FUNC(1, 2) -static int -test_fail(const char* fmt, ...) -{ - va_list args; - va_start(args, fmt); - fprintf(stderr, "error: "); - vfprintf(stderr, fmt, args); - va_end(args); - return 1; -} - -int -main(void) -{ - ZixAMPatree* patree = zix_ampatree_new(); - - const size_t n_strings = sizeof(strings) / sizeof(char*); - - // Insert each string - for (size_t i = 0; i < n_strings; ++i) { - ZixStatus st = zix_ampatree_insert(patree, strings[i], strlen(strings[i])); - if (st) { - return test_fail("Failed to insert `%s'\n", strings[i]); - } - } - - FILE* dot_file = fopen("ampatree.dot", "w"); - zix_ampatree_print_dot(patree, dot_file); - fclose(dot_file); - - // Attempt to insert each string again - for (size_t i = 0; i < n_strings; ++i) { - ZixStatus st = zix_ampatree_insert(patree, strings[i], strlen(strings[i])); - if (st != ZIX_STATUS_EXISTS) { - return test_fail("Double inserted `%s'\n", strings[i]); - } - } - - // Search for each string - for (size_t i = 0; i < n_strings; ++i) { - const char* match = NULL; - ZixStatus st = zix_ampatree_find(patree, strings[i], &match); - if (st) { - return test_fail("Failed to find `%s'\n", strings[i]); - } - if (match != strings[i]) { - return test_fail("Bad match for `%s'\n", strings[i]); - } - } - - // Try some false matches - const char* not_indexed[] = { - "ftp://example.org/not-there-at-all", - "http://example.org/foobar", - "http://", - "http://otherdomain.com" - }; - const size_t n_not_indexed = sizeof(not_indexed) / sizeof(char*); - for (size_t i = 0; i < n_not_indexed; ++i) { - const char* match = NULL; - ZixStatus st = zix_ampatree_find(patree, not_indexed[i], &match); - if (st != ZIX_STATUS_NOT_FOUND) { - return test_fail("Unexpectedly found `%s'\n", not_indexed[i]); - } - } - - zix_ampatree_free(patree); - - return 0; -} diff --git a/test/patree_test.c b/test/patree_test.c deleted file mode 100644 index d7def0c..0000000 --- a/test/patree_test.c +++ /dev/null @@ -1,117 +0,0 @@ -/* - Copyright 2011 David Robillard <http://drobilla.net> - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -#include "zix/common.h" -#include "zix/patree.h" - -#include <stdarg.h> -#include <stdio.h> -#include <string.h> - -static const char* strings[] = { - "http://example.org/foo", - "http://example.org/bar", - "http://example.org/baz", - "http://example.net/foo", - "http://example.net/bar", - "http://example.net/baz", - "http://drobilla.net/", - "http://drobilla.net/software/zix", - "http://www.gbengasesan.com/blog", - "http://www.gbengasesan.com", - "http://echo.jpl.nasa.gov/~lance/delta_v/delta_v.rendezvous.html", - "http://echo.jpl.nasa.gov/asteroids/1986da/1986DA.html", - "http://echo.jpl.nasa.gov/", - "http://echo.jpl.nasa.gov/asteroids/1620_Geographos/geographos.html", - "http://echo.jpl.nasa.gov/~ostro/KY26/", - "http://echo.jpl.nasa.gov/~ostro/KY26/JPL_press_release.text", - "http://echo.jpl.nasa.gov", - "http://echo.jpl.nasa.gov/asteroids/4179_Toutatis/toutatis.html", - "http://echo.jpl.nasa.gov/asteroids/4769_Castalia/cast01.html", - "http://echo.jpl.nasa.gov/publications/review_abs.html", -}; - -ZIX_LOG_FUNC(1, 2) -static int -test_fail(const char* fmt, ...) -{ - va_list args; - va_start(args, fmt); - fprintf(stderr, "error: "); - vfprintf(stderr, fmt, args); - va_end(args); - return 1; -} - -int -main(void) -{ - ZixPatree* patree = zix_patree_new(); - - const size_t n_strings = sizeof(strings) / sizeof(char*); - - // Insert each string - for (size_t i = 0; i < n_strings; ++i) { - ZixStatus st = zix_patree_insert(patree, strings[i], strlen(strings[i])); - if (st) { - return test_fail("Failed to insert `%s'\n", strings[i]); - } - } - - FILE* dot_file = fopen("patree.dot", "w"); - zix_patree_print_dot(patree, dot_file); - fclose(dot_file); - - // Attempt to insert each string again - for (size_t i = 0; i < n_strings; ++i) { - ZixStatus st = zix_patree_insert(patree, strings[i], strlen(strings[i])); - if (st != ZIX_STATUS_EXISTS) { - return test_fail("Double inserted `%s'\n", strings[i]); - } - } - - // Search for each string - for (size_t i = 0; i < n_strings; ++i) { - const char* match = NULL; - ZixStatus st = zix_patree_find(patree, strings[i], &match); - if (st) { - return test_fail("Failed to find `%s'\n", strings[i]); - } - if (match != strings[i]) { - return test_fail("Bad match for `%s'\n", strings[i]); - } - } - - // Try some false matches - const char* not_indexed[] = { - "ftp://example.org/not-there-at-all", - "http://example.org/foobar", - "http://", - "http://otherdomain.com" - }; - const size_t n_not_indexed = sizeof(not_indexed) / sizeof(char*); - for (size_t i = 0; i < n_not_indexed; ++i) { - const char* match = NULL; - ZixStatus st = zix_patree_find(patree, not_indexed[i], &match); - if (st != ZIX_STATUS_NOT_FOUND) { - return test_fail("Unexpectedly found `%s'\n", not_indexed[i]); - } - } - - zix_patree_free(patree); - - return 0; -} diff --git a/test/trie_test.c b/test/trie_test.c deleted file mode 100644 index f4b3eb2..0000000 --- a/test/trie_test.c +++ /dev/null @@ -1,117 +0,0 @@ -/* - Copyright 2011-2016 David Robillard <http://drobilla.net> - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -#include "zix/common.h" -#include "zix/trie.h" - -#include <stdarg.h> -#include <stdio.h> -#include <string.h> - -static const char* strings[] = { - "http://example.org/foo", - "http://example.org/bar", - "http://example.org/baz", - "http://example.net/foo", - "http://example.net/bar", - "http://example.net/baz", - "http://drobilla.net/", - "http://drobilla.net/software/zix", - "http://www.gbengasesan.com/blog", - "http://www.gbengasesan.com", - "http://echo.jpl.nasa.gov/~lance/delta_v/delta_v.rendezvous.html", - "http://echo.jpl.nasa.gov/asteroids/1986da/1986DA.html", - "http://echo.jpl.nasa.gov/", - "http://echo.jpl.nasa.gov/asteroids/1620_Geographos/geographos.html", - "http://echo.jpl.nasa.gov/~ostro/KY26/", - "http://echo.jpl.nasa.gov/~ostro/KY26/JPL_press_release.text", - "http://echo.jpl.nasa.gov", - "http://echo.jpl.nasa.gov/asteroids/4179_Toutatis/toutatis.html", - "http://echo.jpl.nasa.gov/asteroids/4769_Castalia/cast01.html", - "http://echo.jpl.nasa.gov/publications/review_abs.html", -}; - -ZIX_LOG_FUNC(1, 2) -static int -test_fail(const char* fmt, ...) -{ - va_list args; - va_start(args, fmt); - fprintf(stderr, "error: "); - vfprintf(stderr, fmt, args); - va_end(args); - return 1; -} - -int -main(void) -{ - ZixTrie* trie = zix_trie_new(); - - const size_t n_strings = sizeof(strings) / sizeof(char*); - - // Insert each string - for (size_t i = 0; i < n_strings; ++i) { - ZixStatus st = zix_trie_insert(trie, strings[i], strlen(strings[i])); - if (st) { - return test_fail("Failed to insert `%s'\n", strings[i]); - } - } - - FILE* dot_file = fopen("trie.dot", "w"); - zix_trie_print_dot(trie, dot_file); - fclose(dot_file); - - // Attempt to insert each string again - for (size_t i = 0; i < n_strings; ++i) { - ZixStatus st = zix_trie_insert(trie, strings[i], strlen(strings[i])); - if (st != ZIX_STATUS_EXISTS) { - return test_fail("Double inserted `%s'\n", strings[i]); - } - } - - // Search for each string - for (size_t i = 0; i < n_strings; ++i) { - const char* match = NULL; - ZixStatus st = zix_trie_find(trie, strings[i], &match); - if (st) { - return test_fail("Failed to find `%s'\n", strings[i]); - } - if (match != strings[i]) { - return test_fail("Bad match for `%s'\n", strings[i]); - } - } - - // Try some false matches - const char* not_indexed[] = { - "ftp://example.org/not-there-at-all", - "http://example.org/foobar", - "http://", - "http://otherdomain.com" - }; - const size_t n_not_indexed = sizeof(not_indexed) / sizeof(char*); - for (size_t i = 0; i < n_not_indexed; ++i) { - const char* match = NULL; - ZixStatus st = zix_trie_find(trie, not_indexed[i], &match); - if (st != ZIX_STATUS_NOT_FOUND) { - return test_fail("Unexpectedly found `%s'\n", not_indexed[i]); - } - } - - zix_trie_free(trie); - - return 0; -} |