test: fix catch2 related syntax and testing logic

This commit is contained in:
2025-11-09 11:02:17 +01:00
parent aee965c84d
commit 3c82f2934c
+54 -66
View File
@@ -1,116 +1,104 @@
#include <catch2/catch_test_macros.hpp>
#include <catch2/catch_approx.hpp>
#include <TopoDS_Shape.hxx>
#include "point.hpp"
TEST_CASE("Create points") {
TEST_CASE("Create points and get coordinates") {
SECTION("Positive integer coordinates") {
int coords[3] = [3,7,2];
double coords[3] = {3, 7, 2};
TopoDS_Shape p = make_point(coords[0], coords[1], coords[2]);
INFO("Point coordinates: " << coords[0] << ", " << coords[1] << ", " << coords[2]);
double x, y, z;
coord_point(p, &x, &y, &z);
REQUIRE(p.x == coords[0]);
REQUIRE(p.y == coords[1]);
REQUIRE(p.z == coords[2]);
INFO("Point coordinates: " << x << ", " << y << ", " << z);
REQUIRE(x == Catch::Approx(coords[0]));
REQUIRE(y == Catch::Approx(coords[1]));
REQUIRE(z == Catch::Approx(coords[2]));
}
SECTION("Negative integer coordinates") {
int coords[3] = [-2,-5,-14];
double coords[3] = {-2, -5, -14};
TopoDS_Shape p = make_point(coords[0], coords[1], coords[2]);
INFO("Point coordinates: " << coords[0] << ", " << coords[1] << ", " << coords[2]);
double x, y, z;
coord_point(p, &x, &y, &z);
REQUIRE(p.x == coords[0]);
REQUIRE(p.y == coords[1]);
REQUIRE(p.z == coords[2]);
REQUIRE(x == Catch::Approx(coords[0]));
REQUIRE(y == Catch::Approx(coords[1]));
REQUIRE(z == Catch::Approx(coords[2]));
}
SECTION("Mixed integer coordinates") {
int coords[3] = [8,-5,4];
double coords[3] = {8, -5, 4};
TopoDS_Shape p = make_point(coords[0], coords[1], coords[2]);
INFO("Point coordinates: " << coords[0] << ", " << coords[1] << ", " << coords[2]);
double x, y, z;
coord_point(p, &x, &y, &z);
REQUIRE(p.x == coords[0]);
REQUIRE(p.y == coords[1]);
REQUIRE(p.z == coords[2]);
REQUIRE(x == Catch::Approx(coords[0]));
REQUIRE(y == Catch::Approx(coords[1]));
REQUIRE(z == Catch::Approx(coords[2]));
}
SECTION("Positive float coordinates") {
double coords[3] = [3.2352,7.124662,2.5];
double coords[3] = {3.2352, 7.124662, 2.5};
TopoDS_Shape p = make_point(coords[0], coords[1], coords[2]);
INFO("Point coordinates: " << coords[0] << ", " << coords[1] << ", " << coords[2]);
double x, y, z;
coord_point(p, &x, &y, &z);
REQUIRE(p.x == coords[0]);
REQUIRE(p.y == coords[1]);
REQUIRE(p.z == coords[2]);
REQUIRE(x == Catch::Approx(coords[0]));
REQUIRE(y == Catch::Approx(coords[1]));
REQUIRE(z == Catch::Approx(coords[2]));
}
SECTION("Negative float coordinates") {
double coords[3] = [-2.1345,-5.463,-14.00001];
double coords[3] = {-2.1345, -5.463, -14.00001};
TopoDS_Shape p = make_point(coords[0], coords[1], coords[2]);
INFO("Point coordinates: " << coords[0] << ", " << coords[1] << ", " << coords[2]);
double x, y, z;
coord_point(p, &x, &y, &z);
REQUIRE(p.x == coords[0]);
REQUIRE(p.y == coords[1]);
REQUIRE(p.z == coords[2]);
REQUIRE(x == Catch::Approx(coords[0]));
REQUIRE(y == Catch::Approx(coords[1]));
REQUIRE(z == Catch::Approx(coords[2]));
}
SECTION("Mixed float coordinates") {
double coords[3] = [8.124,-5.523,4.0000];
double coords[3] = {8.124, -5.523, 4.0};
TopoDS_Shape p = make_point(coords[0], coords[1], coords[2]);
INFO("Point coordinates: " << coords[0] << ", " << coords[1] << ", " << coords[2]);
double x, y, z;
coord_point(p, &x, &y, &z);
REQUIRE(p.x == coords[0]);
REQUIRE(p.y == coords[1]);
REQUIRE(p.z == coords[2]);
REQUIRE(x == Catch::Approx(coords[0]));
REQUIRE(y == Catch::Approx(coords[1]));
REQUIRE(z == Catch::Approx(coords[2]));
}
SECTION("Origin float") {
int coords[3] = [0,0,0];
SECTION("Origin") {
double coords[3] = {0, 0, 0};
TopoDS_Shape p = make_point(coords[0], coords[1], coords[2]);
INFO("Point coordinates: " << coords[0] << ", " << coords[1] << ", " << coords[2]);
double x, y, z;
coord_point(p, &x, &y, &z);
REQUIRE(p.x == coords[0]);
REQUIRE(p.y == coords[1]);
REQUIRE(p.z == coords[2]);
REQUIRE(x == Catch::Approx(coords[0]));
REQUIRE(y == Catch::Approx(coords[1]));
REQUIRE(z == Catch::Approx(coords[2]));
}
SECTION("Large values") {
float coords[3] = [65186415.16516, 948156654, -6516515.165];
double coords[3] = {65186415.16516, 948156654.0, -6516515.165};
TopoDS_Shape p = make_point(coords[0], coords[1], coords[2]);
INFO("Point coordinates: " << coords[0] << ", " << coords[1] << ", " << coords[2]);
double x, y, z;
coord_point(p, &x, &y, &z);
REQUIRE(p.x == coords[0]);
REQUIRE(p.y == coords[1]);
REQUIRE(p.z == coords[2]);
REQUIRE(x == Catch::Approx(coords[0]));
REQUIRE(y == Catch::Approx(coords[1]));
REQUIRE(z == Catch::Approx(coords[2]));
}
}
/*
TEST_CASE("Get points") {
SECTION("Get point 1") {
REQUIRE();
}
SECTION("Get point 2") {
REQUIRE();
}
SECTION("Get point 3") {
REQUIRE();
}
SECTION("Get point 4") {
REQUIRE();
}
SECTION("Get point 5") {
REQUIRE();
}
}
*/