General Purpose library for Freestanding C++ and POSIX systems
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 

111 行
3.1 KiB

#include "gp/utils/pair.hpp"
#include "gp/algorithms/min_max.hpp"
#include "test_scaffold.h"
#include <random>
#include <string>
typedef std::mt19937_64 cheap_rand;
struct pair_test : public test_scaffold {
uint32_t seed;
pair_test() {
seed = std::random_device{}();
name = __FILE__ ":1_seed";
name += std::to_string(seed);
}
virtual int run() {
cheap_rand setter(seed);
gp::pair<double, std::string> v{0, "zero"};
bool result = true;
for(int i = 0 ; i < 100; i++)
{
auto a = setter();
v = gp::pair(a, std::to_string(a));
result = gp::pair<double, std::string>(a, std::to_string(a)) == v ? result : false;
}
return !result;
}
};
append_test dummy_rsly21r43(new pair_test{});
template<typename T>
struct sort_pair_test : public test_scaffold {
uint32_t seed;
sort_pair_test() {
seed = std::random_device{}();
name = __FILE__ ":2_sort_pair";
name += std::to_string(seed);
}
virtual int run() {
// TODO: Verify things, like, for real
cheap_rand setter(seed);
bool result = true;
std::uniform_real_distribution<T> dist{-1.0, 1.0};
for(int i = 0 ; i < 10000; i++)
{
gp::pair<T, T> v{dist(setter), dist(setter)};
gp::pair<T, T>
ascending{gp::min(v.first, v.second), gp::max(v.first, v.second)},
descending{gp::max(v.first, v.second), gp::min(v.first, v.second)},
clamped{gp::clamp<float>(0.25,v.first, 0.5), gp::min(0.5, v.first, v.second)},
minmaxed{gp::min<T>(dist(setter), dist(setter), dist(setter)), gp::max<T>(dist(setter), dist(setter), dist(setter))},
rngclamp{gp::clamp<T>(dist(setter),dist(setter), dist(setter)), gp::clamp<T>(dist(setter), dist(setter), dist(setter))};
result = ascending.first == descending.second ? result : false;
}
return !result;
}
};
append_test dummy_5qsd5r43(new sort_pair_test<float>{});
append_test dummy_4365xv43(new sort_pair_test<double>{});
template<typename T>
struct sort_pair_test2 : public test_scaffold {
uint32_t seed;
sort_pair_test2() {
seed = std::random_device{}();
name = __FILE__ ":3_sort_pair2";
name += std::to_string(seed);
}
virtual int run() {
// TODO: Verify things, like, for real
cheap_rand setter(seed);
bool result = true;
std::uniform_int_distribution<T> dist{0, 4096};
for(int i = 0 ; i < 10000; i++)
{
gp::pair<T, T> v{dist(setter), dist(setter)};
gp::pair<T, T>
ascending{gp::min<T>(v.first, v.second), gp::max<T>(v.first, v.second)},
descending{gp::max<T>(v.first, v.second), gp::min<T>(v.first, v.second)},
clamped{gp::clamp<T>(512,v.first, 1024), gp::min(1024, v.first, v.second)},
minmaxed{gp::min<T>(dist(setter),dist(setter), dist(setter)), gp::max<T>(dist(setter), dist(setter), dist(setter))},
rngclamp{gp::clamp<T>(dist(setter),dist(setter), dist(setter)), gp::clamp<T>(dist(setter), dist(setter), dist(setter))};
result = ascending.first == descending.second ? result : false;
}
return !result;
}
};
append_test dummy_5zegfh43(new sort_pair_test2<int>{});
append_test dummy_sdghtfh4(new sort_pair_test2<unsigned long>{});
append_test dummy_judlg8gb(new sort_pair_test2<long>{});
append_test dummy_5egkzbcd(new sort_pair_test2<long long>{});