1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-27 17:28:41 +00:00

Fix random usage in matrix4 tests

This commit is contained in:
Lars Mueller 2025-01-30 13:17:13 +01:00 committed by sfan5
parent 1ceeea34f4
commit 5abf220979

View file

@ -85,28 +85,38 @@ SECTION("getScale") {
} }
SECTION("getRotationDegrees") { SECTION("getRotationDegrees") {
auto test_rotation_degrees = [](v3f deg) { auto test_rotation_degrees = [](v3f deg, v3f scale) {
matrix4 S; matrix4 S;
Catch::Generators::RandomFloatingGenerator<f32> gen(0.1f, 10, Catch::getSeed()); S.setScale(scale);
S.setScale({gen.get(), gen.get(), gen.get()}); matrix4 R;
R.setRotationDegrees(deg);
matrix4 R; v3f rot = (R * S).getRotationDegrees();
R.setRotationDegrees(deg); matrix4 B;
v3f rot = (R * S).getRotationDegrees(); B.setRotationDegrees(rot);
matrix4 B; CHECK(matrix_equals(R, B));
B.setRotationDegrees(rot); };
CHECK(matrix_equals(R, B)); SECTION("returns a rotation equivalent to the original rotation") {
}; test_rotation_degrees({100, 200, 300}, v3f(1));
SECTION("returns a rotation equivalent to the original rotation") { Catch::Generators::RandomFloatingGenerator<f32> gen_angle(0, 360, Catch::getSeed());
test_rotation_degrees({100, 200, 300}); Catch::Generators::RandomFloatingGenerator<f32> gen_scale(0.1f, 10, Catch::getSeed());
Catch::Generators::RandomFloatingGenerator<f32> gen(0, 360, Catch::getSeed()); auto draw = [](auto gen) {
for (int i = 0; i < 1000; ++i) f32 f = gen.get();
test_rotation_degrees(v3f{gen.get(), gen.get(), gen.get()}); gen.next();
for (f32 i = 0; i < 360; i += 90) return f;
for (f32 j = 0; j < 360; j += 90) };
for (f32 k = 0; k < 360; k += 90) auto draw_v3f = [&](auto gen) {
test_rotation_degrees({i, j, k}); return v3f{draw(gen), draw(gen), draw(gen)};
} };
for (int i = 0; i < 1000; ++i)
test_rotation_degrees(draw_v3f(gen_angle), draw_v3f(gen_scale));
for (f32 i = 0; i < 360; i += 90)
for (f32 j = 0; j < 360; j += 90)
for (f32 k = 0; k < 360; k += 90) {
for (int l = 0; l < 100; ++l) {
test_rotation_degrees({i, j, k}, draw_v3f(gen_scale));
}
}
}
} }
} }