diff --git a/test/occt/point-test.cpp b/test/occt/point-test.cpp index f3805a0..867189a 100644 --- a/test/occt/point-test.cpp +++ b/test/occt/point-test.cpp @@ -1,116 +1,104 @@ #include +#include +#include #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(); - } -} -*/