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.
 
 

86 lines
2.1 KiB

#include "gp/containers/array.hpp"
#include "gp/containers/vector.hpp"
#include "gp/algorithms/partition.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 partition_array_test : public test_scaffold {
uint32_t seed;
partition_array_test() {
name = __FILE__ ":1_seed";
seed = std::random_device{}();
name += std::to_string(seed);
}
virtual int run() {
cheap_rand setter(seed);
for(int i = 0; i < 250; ++i) {
gp::array<uint32_t, 200> ary;
for(auto& elem : ary) {
elem = setter();
}
auto pivot = gp::hoare_partition(ary.begin(), ary.end(), [](const auto& v){return v % 2;});
for(auto it = ary.begin(); it != pivot;++it) {
gp_config::assertion(!!(*it % 2), "partition failed");
}
for(auto it = pivot; it != ary.end();++it) {
gp_config::assertion(!(*it % 2), "partition failed");
}
}
return 0;
}
};
append_test dummy_s5f468e43(new partition_array_test{});
struct partition_array_lomuto_test : public test_scaffold {
uint32_t seed;
partition_array_lomuto_test() {
name = __FILE__ ":2_seed";
seed = std::random_device{}();
name += std::to_string(seed);
}
virtual int run() {
cheap_rand setter(seed);
for(int i = 0; i < 250; ++i) {
gp::array<uint32_t, 200> ary;
for(auto& elem : ary) {
elem = setter();
}
auto pivot = gp::lomuto_partition(ary.begin(), ary.end(), [](const auto& v){return v % 2;});
for(auto it = ary.begin(); it != pivot;++it) {
gp_config::assertion(!!(*it % 2), "partition failed");
}
for(auto it = pivot; it != ary.end();++it) {
gp_config::assertion(!(*it % 2), "partition failed");
}
}
return 0;
}
};
append_test dummy_lcvudg8e43(new partition_array_lomuto_test{});