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.

127 line
2.3 KiB

4 年之前
4 年之前
  1. #include "gp/algorithms/repeat.hpp"
  2. #include "gp/containers/probabilistic/bloomfilter.hpp"
  3. #include "test_scaffold.h"
  4. #include <random>
  5. #include <string>
  6. typedef std::mt19937_64 cheap_rand;
  7. typedef std::mt19937_64 cheap_rand_bis;
  8. struct bfilter_test : public test_scaffold {
  9. uint32_t seed;
  10. bfilter_test() {
  11. seed = std::random_device{}();
  12. name = __FILE__ ":1_seed";
  13. name += std::to_string(seed);
  14. }
  15. virtual int run() {
  16. cheap_rand setter(seed);
  17. cheap_rand getter(seed);
  18. gp::bloomfilter test_filter;
  19. for(int a = 0 ; a < 100; a++)
  20. {
  21. test_filter.set_hash(setter());
  22. }
  23. bool result = true;
  24. for(int a = 0 ; a < 100; a++)
  25. {
  26. result *= test_filter.test_hash(getter());
  27. }
  28. return !result;
  29. }
  30. };
  31. append_test dummy_r21fg6r43(new bfilter_test{});
  32. struct bfilter2_test : public test_scaffold {
  33. uint32_t seedA;
  34. uint32_t seedB;
  35. bfilter2_test() {
  36. seedA = std::random_device{}();
  37. seedB = std::random_device{}();
  38. name = __FILE__ ":2_seedA";
  39. name += std::to_string(seedA);
  40. name += "&seedB";
  41. name += std::to_string(seedB);
  42. }
  43. bfilter2_test(uint32_t a, uint32_t b) {
  44. seedA = a;
  45. seedB = b;
  46. name = __FILE__ ":2_seedA";
  47. name += std::to_string(seedA);
  48. name += "&seedB";
  49. name += std::to_string(seedB);
  50. }
  51. virtual int run() {
  52. cheap_rand setter(seedA);
  53. cheap_rand_bis getter(seedB);
  54. int interference = 0;
  55. auto cnt = 300;
  56. gp::repeat(cnt, [&](){
  57. gp::bloomfilter test_filter;
  58. for(int a = 0 ; a < 10000; a++)
  59. {
  60. test_filter.set_hash(setter());
  61. }
  62. for(int a = 0 ; a < 10000; a++)
  63. {
  64. interference += test_filter.test_hash(getter()) == true;
  65. }
  66. });
  67. float avg = interference / (float)cnt;
  68. return avg >= 210;
  69. }
  70. };
  71. append_test dummy_r2gflu3(new bfilter2_test{});
  72. append_test dummy_rsdgueiu3(new bfilter2_test{3780040561, 79423740});
  73. struct bfilter3_test : public test_scaffold {
  74. uint32_t seed;
  75. bfilter3_test() {
  76. seed = std::random_device{}();
  77. name = __FILE__ ":3_seed";
  78. name += std::to_string(seed);
  79. }
  80. virtual int run() {
  81. cheap_rand setter(seed);
  82. cheap_rand getter(seed);
  83. gp::bloomfilter<uint32_t, 19, true> test_filter;
  84. for(int a = 0 ; a < 1000; a++)
  85. {
  86. test_filter.set_hash(setter());
  87. }
  88. bool result = true;
  89. for(int a = 0 ; a < 1000; a++)
  90. {
  91. result *= test_filter.test_hash(getter());
  92. }
  93. return !result;
  94. }
  95. };
  96. append_test dummy_56489flu3(new bfilter3_test{});