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.

62 lines
1.6 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{});