General Purpose library for Freestanding C++ and POSIX systems
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

192 lines
3.4 KiB

преди 4 години
преди 4 години
преди 4 години
  1. #include "gp/containers/probabilistic/quotient_filter.hpp"
  2. #include "test_scaffold.h"
  3. #include <random>
  4. #include <string>
  5. typedef std::mt19937_64 cheap_rand;
  6. typedef std::mt19937_64 cheap_rand_bis;
  7. struct qfilter_test : public test_scaffold {
  8. uint32_t seed;
  9. qfilter_test() {
  10. seed = std::random_device{}();
  11. name = __FILE__ ":1_seed";
  12. name += std::to_string(seed);
  13. }
  14. virtual int run() {
  15. cheap_rand setter(seed);
  16. cheap_rand getter(seed);
  17. gp::quotient_filter test_filter;
  18. for(int a = 0 ; a < 100; a++)
  19. {
  20. test_filter.set_hash(setter());
  21. }
  22. bool result = true;
  23. for(int a = 0 ; a < 100; a++)
  24. {
  25. result *= test_filter.test_hash(getter());
  26. }
  27. return !result;
  28. }
  29. };
  30. append_test dummy_rshyr43(new qfilter_test{});
  31. struct qfilter2_test : public test_scaffold {
  32. uint32_t seedA;
  33. uint32_t seedB;
  34. qfilter2_test() {
  35. seedA = std::random_device{}();
  36. seedB = std::random_device{}();
  37. name = __FILE__ ":2_seedA";
  38. name += std::to_string(seedA);
  39. name += "&seedB";
  40. name += std::to_string(seedB);
  41. }
  42. virtual int run() {
  43. cheap_rand setter(seedA);
  44. cheap_rand deleter(seedA);
  45. cheap_rand_bis getter(seedB);
  46. gp::quotient_filter test_filter;
  47. for(int a = 0 ; a < 100000; a++)
  48. {
  49. test_filter.set_hash(setter());
  50. }
  51. int interference = 0;
  52. for(int a = 0 ; a < 100000; a++)
  53. {
  54. interference += test_filter.test_hash(getter());
  55. }
  56. for(int a = 0 ; a < 100000; a++)
  57. {
  58. test_filter.remove_hash(deleter());
  59. }
  60. return interference > 25;
  61. }
  62. };
  63. append_test dummy_kegdflu3(new qfilter2_test{});
  64. struct qfilter3_test : public test_scaffold {
  65. uint32_t seedA;
  66. uint32_t seedB;
  67. qfilter3_test() {
  68. seedA = std::random_device{}();
  69. seedB = std::random_device{}();
  70. name = __FILE__ ":3_seedA";
  71. name += std::to_string(seedA);
  72. name += "&seedB";
  73. name += std::to_string(seedB);
  74. }
  75. virtual int run() {
  76. cheap_rand setter(seedA);
  77. cheap_rand deleter(seedA);
  78. cheap_rand_bis getter(seedB);
  79. gp::quotient_filter<uint32_t, 20,12, gp::stepcache_skipstone> test_filter;
  80. for(int a = 0 ; a < 100000; a++)
  81. {
  82. test_filter.set_hash(setter());
  83. }
  84. int interference = 0;
  85. for(int a = 0 ; a < 100000; a++)
  86. {
  87. interference += test_filter.test_hash(getter());
  88. }
  89. for(int a = 0 ; a < 100000; a++)
  90. {
  91. test_filter.remove_hash(deleter());
  92. }
  93. return interference > 25;
  94. }
  95. };
  96. append_test dummy_kjdflu3(new qfilter3_test{});
  97. struct qfilter4_test : public test_scaffold {
  98. qfilter4_test() {
  99. }
  100. virtual int run() {
  101. gp::quotient_filter<> test_filter;
  102. for(int a = 0 ; a < 10000; a++)
  103. {
  104. test_filter.set_hash(a);
  105. }
  106. for(int a = 0 ; a < 10000; a++)
  107. {
  108. test_filter.remove_hash(a);
  109. }
  110. for(int a = 0 ; a < 10000; a++)
  111. {
  112. gp_config::assertion(!test_filter.test_hash(a), "everything should have been removed");
  113. }
  114. for(int a = 0 ; a < 10000; a++)
  115. {
  116. test_filter.set_hash(a);
  117. }
  118. for(int a = 0 ; a < 10000; a++)
  119. {
  120. gp_config::assertion(test_filter.test_hash(a), "everything should have been set");
  121. }
  122. return 0;
  123. }
  124. };
  125. append_test dummy_kj54ghu3(new qfilter4_test{});
  126. struct qfilter5_test : public test_scaffold {
  127. qfilter5_test() {
  128. }
  129. virtual int run() {
  130. gp::quotient_filter<uint32_t, 16> test_filter;
  131. for(int a = 0 ; a < 65536; a++)
  132. {
  133. test_filter.set_hash(a);
  134. }
  135. int res = 1;
  136. try {
  137. test_filter.set_hash(123456);
  138. } catch(gp::runtime_error e) {
  139. res = 0;
  140. }
  141. return res;
  142. }
  143. };
  144. append_test dummy_k65421u3(new qfilter5_test{});