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.

117 lines
2.1 KiB

  1. #include "gp/algorithm/repeat.hpp"
  2. #include "gp/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. virtual int run() {
  44. cheap_rand setter(seedA);
  45. cheap_rand_bis getter(seedB);
  46. int interference = 0;
  47. auto cnt = 300;
  48. gp::repeat(cnt, [&](){
  49. gp::bloomfilter test_filter;
  50. for(int a = 0 ; a < 10000; a++)
  51. {
  52. test_filter.set_hash(setter());
  53. }
  54. for(int a = 0 ; a < 10000; a++)
  55. {
  56. interference += test_filter.test_hash(getter()) == true;
  57. }
  58. });
  59. float avg = interference / (float)cnt;
  60. return avg >= 210;
  61. }
  62. };
  63. append_test dummy_r2gflu3(new bfilter2_test{});
  64. struct bfilter3_test : public test_scaffold {
  65. uint32_t seed;
  66. bfilter3_test() {
  67. seed = std::random_device{}();
  68. name = __FILE__ ":3_seed";
  69. name += std::to_string(seed);
  70. }
  71. virtual int run() {
  72. cheap_rand setter(seed);
  73. cheap_rand getter(seed);
  74. gp::bloomfilter<uint32_t, 19, true> test_filter;
  75. for(int a = 0 ; a < 1000; a++)
  76. {
  77. test_filter.set_hash(setter());
  78. }
  79. bool result = true;
  80. for(int a = 0 ; a < 1000; a++)
  81. {
  82. result *= test_filter.test_hash(getter());
  83. }
  84. return !result;
  85. }
  86. };
  87. append_test dummy_56489flu3(new bfilter3_test{});