General Purpose library for Freestanding C++ and POSIX systems
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

126 linhas
2.3 KiB

  1. #include "test_scaffold.h"
  2. #include <random>
  3. #include <string>
  4. #include "gp/quotient_filter.hpp"
  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{});