bstringtrie_test.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include <stdio.h>
  2. #include <misc/debug.h>
  3. #include <misc/array_length.h>
  4. #include <structure/BStringTrie.h>
  5. const char *strings[] = {
  6. "hello", "world", "hell", "he", "war", "warning", "warned", "", "heap", "why", "not", "nowhere", "neither",
  7. "normal", "how", "apple", "apear", "appreciate", "systematic", "systemic", "system", "self", "serious"
  8. };
  9. #define NUM_STRINGS B_ARRAY_LENGTH(strings)
  10. const char *other_strings[] = {
  11. "warn", "wor", "helloo", "norma", "systems", "server", "no", "when", "nothing"
  12. };
  13. #define NUM_OTHER_STRINGS B_ARRAY_LENGTH(other_strings)
  14. int main ()
  15. {
  16. int res;
  17. BStringTrie trie;
  18. res = BStringTrie_Init(&trie);
  19. ASSERT_FORCE(res);
  20. for (int i = 0; i < NUM_STRINGS; i++) {
  21. res = BStringTrie_Set(&trie, strings[i], i);
  22. ASSERT_FORCE(res);
  23. }
  24. for (int i = 0; i < NUM_STRINGS; i++) {
  25. int value = BStringTrie_Lookup(&trie, strings[i]);
  26. ASSERT_FORCE(value == i);
  27. }
  28. for (int i = 0; i < NUM_STRINGS; i++) {
  29. res = BStringTrie_Set(&trie, strings[i], NUM_STRINGS - 1 - i);
  30. ASSERT_FORCE(res);
  31. }
  32. for (int i = 0; i < NUM_STRINGS; i++) {
  33. int value = BStringTrie_Lookup(&trie, strings[i]);
  34. ASSERT_FORCE(value == NUM_STRINGS - 1 - i);
  35. }
  36. for (int i = 0; i < NUM_OTHER_STRINGS; i++) {
  37. int value = BStringTrie_Lookup(&trie, other_strings[i]);
  38. ASSERT_FORCE(value == BSTRINGTRIE_DEFAULT_VALUE);
  39. }
  40. BStringTrie_Free(&trie);
  41. return 0;
  42. }