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.
 
 

109 lines
2.9 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{});
struct dynarray2_test : public test_scaffold {
uint32_t seed;
dynarray2_test() {
name = __FILE__ ":2_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,49);
std::uniform_int_distribution<int> coin(false,true);
bool happened = false;
for(int i = 0; i < 1000; i++) {
val a;
if(coin(setter)) {
a.emplace_back(dist(setter));
}
a.emplace_back(dist(setter));
for(int j = 0; j < 1000; j++) {
val b;
if(coin(setter)) {
b.emplace_back(dist(setter));
}
b.emplace_back(dist(setter));
if(a == b) {
if(! (a != b)) {
happened = true;
}
}
}
}
return !happened;
}
};
append_test dummy_5dfqlys543(new dynarray2_test{});