Advertisement
GeeckoDev

HybridTrie test template

Dec 10th, 2014
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. #include "hybridtrie.h"
  2. #include <iostream>
  3.  
  4. #define ASSERT(p) \
  5.     if (!(p)) { return 1; }
  6. #define SUCCESS() \
  7.     return 0;
  8.  
  9. int test_exists()
  10. {
  11.     HybridTrie t;
  12.  
  13.     ASSERT(!t.exists(""))
  14.  
  15.     t.insert("algav");
  16.     ASSERT(t.exists("algav") && !t.exists("alga") && !t.exists("a"))
  17.  
  18.     t.insert("alga");
  19.     ASSERT(t.exists("alga"))
  20.  
  21.     SUCCESS()
  22. }
  23.  
  24. int test_countWords()
  25. {
  26.     HybridTrie t;
  27.  
  28.     ASSERT(t.countWords() == 0)
  29.  
  30.     t.insert("algav");
  31.     ASSERT(t.countWords() == 1)
  32.  
  33.     t.insert("algav");
  34.     ASSERT(t.countWords() == 1)
  35.  
  36.     t.insert("alga");
  37.     ASSERT(t.countWords() == 2)
  38.  
  39.     t.insert("test");
  40.     ASSERT(t.countWords() == 3)
  41.  
  42.     t.insert("akga");
  43.     ASSERT(t.countWords() == 4)
  44.  
  45.     SUCCESS()
  46. }
  47.  
  48. int (*test[])() =
  49. {
  50.     test_exists,
  51.     test_countWords,
  52. };
  53.  
  54. int main(int argc, char *argv[])
  55. {
  56.     int n = (sizeof(test) / sizeof(int(*)()));
  57.     int count = 0;
  58.  
  59.     for (int i = 0; i < n; i++) {
  60.         std::cout << "running test " << i << "... ";
  61.         if (test[i]()) {
  62.             std::cout << "failed" << std::endl;
  63.         }
  64.         else {
  65.             std::cout << "passed" << std::endl;
  66.             count++;
  67.         }
  68.     }
  69.  
  70.     std::cout << count << '/' << n << " tests passed." << std::endl;
  71.  
  72.     return (count != n);
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement