General Purpose library for Freestanding C++ and POSIX systems
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

108 rindas
2.9 KiB

  1. #include "gp/containers/dynarray.hpp"
  2. #include "gp/containers/vector.hpp"
  3. #include "gp/algorithms/sort.hpp"
  4. #include "test_scaffold.h"
  5. #include "allocator.hpp"
  6. #include <memory>
  7. #include <random>
  8. #include <iostream>
  9. #include <string>
  10. #include <algorithm>
  11. typedef std::mt19937_64 cheap_rand;
  12. struct dynarray_test : public test_scaffold {
  13. uint32_t seed;
  14. dynarray_test() {
  15. name = __FILE__ ":1_seed";
  16. seed = std::random_device{}();
  17. name += std::to_string(seed);
  18. }
  19. virtual int run() {
  20. using val = gp::dynarray<int, 100>;
  21. cheap_rand setter(seed);
  22. std::unique_ptr<gp::array<char, 4096*4096>> store = std::make_unique<gp::array<char, 4096*4096>>();
  23. gp::buddy alloc{&*store->begin(), store->size()};
  24. gp::vector<val> vals{alloc};
  25. std::uniform_int_distribution<int> dist(0,99);
  26. for(int i = 0; i < 1000; i++) {
  27. val insert{};
  28. int max = dist(setter);
  29. for(int b = 0; b < max; b++) {
  30. insert.emplace_back(b);
  31. }
  32. vals.emplace_back(insert);
  33. }
  34. for(int i = 0; i < vals.size(); i++) {
  35. for(int j = i+1; j < vals.size(); j++) {
  36. if(!(vals[i] != vals[j])) {
  37. if(vals[i] == vals[j]) {
  38. vals.remove(vals.begin()+j);
  39. j--;
  40. }
  41. }
  42. }
  43. }
  44. gp::sort(vals.begin(), vals.end(), [](const val& a, const val& b){
  45. return a.size() < b.size();
  46. });
  47. return vals.size() > 100;
  48. }
  49. };
  50. append_test dummy_afdglys543(new dynarray_test{});
  51. struct dynarray2_test : public test_scaffold {
  52. uint32_t seed;
  53. dynarray2_test() {
  54. name = __FILE__ ":2_seed";
  55. seed = std::random_device{}();
  56. name += std::to_string(seed);
  57. }
  58. virtual int run() {
  59. using val = gp::dynarray<int, 100>;
  60. cheap_rand setter(seed);
  61. std::unique_ptr<gp::array<char, 4096*4096>> store = std::make_unique<gp::array<char, 4096*4096>>();
  62. gp::buddy alloc{&*store->begin(), store->size()};
  63. gp::vector<val> vals{alloc};
  64. std::uniform_int_distribution<int> dist(0,49);
  65. std::uniform_int_distribution<int> coin(false,true);
  66. bool happened = false;
  67. for(int i = 0; i < 1000; i++) {
  68. val a;
  69. if(coin(setter)) {
  70. a.emplace_back(dist(setter));
  71. }
  72. a.emplace_back(dist(setter));
  73. for(int j = 0; j < 1000; j++) {
  74. val b;
  75. if(coin(setter)) {
  76. b.emplace_back(dist(setter));
  77. }
  78. b.emplace_back(dist(setter));
  79. if(a == b) {
  80. if(! (a != b)) {
  81. happened = true;
  82. }
  83. }
  84. }
  85. }
  86. return !happened;
  87. }
  88. };
  89. append_test dummy_5dfqlys543(new dynarray2_test{});