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.
 
 

63 lines
1.6 KiB

#include "gp/containers/dynarray.hpp"
#include "gp/containers/vector.hpp"
#include "gp/algorithms/sort.hpp"
#include "test_scaffold.h"
#include "allocator.hpp"
#include <memory>
#include <random>
#include <iostream>
#include <string>
#include <algorithm>
typedef std::mt19937_64 cheap_rand;
struct dynarray_test : public test_scaffold {
uint32_t seed;
dynarray_test() {
name = __FILE__ ":1_seed";
seed = std::random_device{}();
name += std::to_string(seed);
}
virtual int run() {
using val = gp::dynarray<int, 100>;
cheap_rand setter(seed);
std::unique_ptr<gp::array<char, 4096*4096>> store = std::make_unique<gp::array<char, 4096*4096>>();
gp::buddy alloc{&*store->begin(), store->size()};
gp::vector<val> vals{alloc};
std::uniform_int_distribution<int> dist(0,99);
for(int i = 0; i < 1000; i++) {
val insert{};
int max = dist(setter);
for(int b = 0; b < max; b++) {
insert.emplace_back(b);
}
vals.emplace_back(insert);
}
for(int i = 0; i < vals.size(); i++) {
for(int j = i+1; j < vals.size(); j++) {
if(!(vals[i] != vals[j])) {
if(vals[i] == vals[j]) {
vals.remove(vals.begin()+j);
j--;
}
}
}
}
gp::sort(vals.begin(), vals.end(), [](const val& a, const val& b){
return a.size() < b.size();
});
return vals.size() > 100;
}
};
append_test dummy_afdglys543(new dynarray_test{});