47 lines
1.3 KiB
C++
47 lines
1.3 KiB
C++
|
|
||
|
#include <cruft/util/tap.hpp>
|
||
|
|
||
|
#include <cruft/util/extent.hpp>
|
||
|
#include <cruft/util/geom/sample/subregion.hpp>
|
||
|
|
||
|
|
||
|
int
|
||
|
main ()
|
||
|
{
|
||
|
cruft::TAP::logger tap;
|
||
|
|
||
|
static const struct {
|
||
|
cruft::extent2i shape;
|
||
|
cruft::extent2i field;
|
||
|
char const *message;
|
||
|
} TESTS[] = {
|
||
|
{ { 1, 1 }, { 1, 1 }, "Unit shape and unit field" },
|
||
|
{ { 1, 1 }, { 100, 100 }, "Unit shape and large field" },
|
||
|
{ { 10, 10 }, { 100, 100 }, "Square shape and large field" },
|
||
|
{ { 1, 10 }, { 100, 100 }, "Tall shape and large field" },
|
||
|
{ { 10, 1 }, { 100, 100 }, "" },
|
||
|
{ { 2, 2 }, { 100, 100 }, "" },
|
||
|
};
|
||
|
|
||
|
static const int ITERATIONS = 1'000;
|
||
|
|
||
|
for (auto const &[shape, field, msg]: TESTS) {
|
||
|
cruft::rand::xoshiro256plusplus gen (42);
|
||
|
cruft::geom::sample::subregion sampler {shape, field};
|
||
|
|
||
|
cruft::region2i const valid (cruft::point2i (0), field);
|
||
|
|
||
|
bool success = true;
|
||
|
for (int i = 0; i < ITERATIONS; ++i) {
|
||
|
auto const choice = sampler (gen);
|
||
|
if (!valid.covers (choice)) {
|
||
|
success = false;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
tap.expect (success, "subregion coverage validity, %!", msg);
|
||
|
}
|
||
|
|
||
|
return tap.status ();
|
||
|
}
|