u02/tests: Add average point test for star
parent
583f2ecd3e
commit
d4794e1544
|
@ -563,5 +563,26 @@ TEST_CASE("Star (prop: all points inside circle)") {
|
||||||
REQUIRE(pass);
|
REQUIRE(pass);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The Haskell implementation of regular_polygon_mod has many tests,
|
TEST_CASE("Star (prop: average of all points is centre)") {
|
||||||
|
const int x0 = GENERATE(take(5, random(-100, 100)));
|
||||||
|
const int y0 = GENERATE(take(5, random(-100, 100)));
|
||||||
|
const int n = GENERATE(take(5, random(3, 1000)));
|
||||||
|
const float r2 = GENERATE(take(5, random(0, 100)));
|
||||||
|
const float r_factor = GENERATE(take(5, random(0, 1)));
|
||||||
|
const float r1 = r_factor * r2;
|
||||||
|
const float angle = GENERATE(take(5, random(-16.0 * atan(1), 16 * atan(1))));
|
||||||
|
|
||||||
|
std::vector<std::pair<float, float>> points = star(n, r1, r2, x0, y0, angle);
|
||||||
|
|
||||||
|
float x = 0, y = 0;
|
||||||
|
for (std::pair<float, float> point : points) {
|
||||||
|
x += point.first;
|
||||||
|
y += point.second;
|
||||||
|
}
|
||||||
|
|
||||||
|
REQUIRE_THAT(x / points.size(), WithinRel(x0, 0.1));
|
||||||
|
REQUIRE_THAT(y / points.size(), WithinRel(y0, 0.1));
|
||||||
|
}
|
||||||
|
|
||||||
|
// The Haskell implementation of regular_polygon_mod has many more tests,
|
||||||
// but they are not implemented here for brevity.
|
// but they are not implemented here for brevity.
|
||||||
|
|
Reference in New Issue