Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ include(GoogleTest)

add_executable(Shape_shape_test)
target_sources(Shape_shape_test PRIVATE
test_params.hpp
trapezoid_test.cpp
shape_test.cpp
elements_intersections_test.cpp
Expand Down
36 changes: 11 additions & 25 deletions test/approximation_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,6 @@ struct ApproximateShapeByLineSegmentsTestParams
ShapeWithHoles expected_output;


static ApproximateShapeByLineSegmentsTestParams from_json(
nlohmann::basic_json<>& json_item)
{
ApproximateShapeByLineSegmentsTestParams test_params;
test_params.shape = Shape::from_json(json_item["shape"]);
test_params.segment_length = json_item["segment_length"];
test_params.outer = json_item["outer"];
if (json_item.contains("expected_output"))
test_params.expected_output = ShapeWithHoles::from_json(json_item["expected_output"]);
return test_params;
}

static ApproximateShapeByLineSegmentsTestParams read_json(
const std::string& file_path)
{
Expand All @@ -136,8 +124,13 @@ struct ApproximateShapeByLineSegmentsTestParams

nlohmann::json json;
file >> json;
auto test_params = from_json(json);
ApproximateShapeByLineSegmentsTestParams test_params;
test_params.name = file_path;
test_params.shape = Shape::from_json(json["shape"]);
test_params.segment_length = json["segment_length"];
test_params.outer = json["outer"];
if (json.contains("expected_output"))
test_params.expected_output = ShapeWithHoles::from_json(json["expected_output"]);
return test_params;
}
};
Expand Down Expand Up @@ -219,17 +212,6 @@ struct ApproximateByLineSegmentsTestParams
ShapeWithHoles expected_output;


static ApproximateByLineSegmentsTestParams from_json(
nlohmann::basic_json<>& json_item)
{
ApproximateByLineSegmentsTestParams test_params;
test_params.shape_with_holes = ShapeWithHoles::from_json(json_item["shape_with_holes"]);
test_params.segment_length = json_item["segment_length"];
if (json_item.contains("expected_output"))
test_params.expected_output = ShapeWithHoles::from_json(json_item["expected_output"]);
return test_params;
}

static ApproximateByLineSegmentsTestParams read_json(
const std::string& file_path)
{
Expand All @@ -242,8 +224,12 @@ struct ApproximateByLineSegmentsTestParams

nlohmann::json json;
file >> json;
auto test_params = from_json(json);
ApproximateByLineSegmentsTestParams test_params;
test_params.name = file_path;
test_params.shape_with_holes = ShapeWithHoles::from_json(json["shape_with_holes"]);
test_params.segment_length = json["segment_length"];
if (json.contains("expected_output"))
test_params.expected_output = ShapeWithHoles::from_json(json["expected_output"]);
return test_params;
}
};
Expand Down
345 changes: 202 additions & 143 deletions test/boolean_operations_test.cpp

Large diffs are not rendered by default.

14 changes: 3 additions & 11 deletions test/clean_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,6 @@ struct CleanExtremeSlopesOuterTestParams
ShapeWithHoles expected_output;


template <class basic_json>
static CleanExtremeSlopesOuterTestParams from_json(
basic_json& json_item)
{
CleanExtremeSlopesOuterTestParams test_params;
test_params.shape = Shape::from_json(json_item["shape"]);
test_params.expected_output = ShapeWithHoles::from_json(json_item["expected_output"]);
return test_params;
}

static CleanExtremeSlopesOuterTestParams read_json(
const std::string& file_path)
{
Expand All @@ -82,8 +72,10 @@ struct CleanExtremeSlopesOuterTestParams

nlohmann::json json;
file >> json;
auto test_params = from_json(json);
CleanExtremeSlopesOuterTestParams test_params;
test_params.name = file_path;
test_params.shape = Shape::from_json(json["shape"]);
test_params.expected_output = ShapeWithHoles::from_json(json["expected_output"]);
return test_params;
}
};
Expand Down
27 changes: 10 additions & 17 deletions test/elements_intersections_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,6 @@ struct ComputeIntersectionsTestParams
ShapeElement element_2;
ShapeElementIntersectionsOutput expected_output;

template <class basic_json>
static ComputeIntersectionsTestParams from_json(
basic_json& json_item)
{
ComputeIntersectionsTestParams test_params;
test_params.element_1 = ShapeElement::from_json(json_item["element_1"]);
test_params.element_2 = ShapeElement::from_json(json_item["element_2"]);
for (auto& json_element: json_item["expected_output"]["overlapping_parts"].items())
test_params.expected_output.overlapping_parts.emplace_back(ShapeElement::from_json(json_element.value()));
for (auto& json_point: json_item["expected_output"]["improper_intersections"].items())
test_params.expected_output.improper_intersections.emplace_back(Point::from_json(json_point.value()));
for (auto& json_point: json_item["expected_output"]["proper_intersections"].items())
test_params.expected_output.proper_intersections.emplace_back(Point::from_json(json_point.value()));
return test_params;
}

static ComputeIntersectionsTestParams read_json(
const std::string& file_path)
{
Expand All @@ -47,7 +31,16 @@ struct ComputeIntersectionsTestParams

nlohmann::json json;
file >> json;
return from_json(json);
ComputeIntersectionsTestParams test_params;
test_params.element_1 = ShapeElement::from_json(json["element_1"]);
test_params.element_2 = ShapeElement::from_json(json["element_2"]);
for (auto& json_element: json["expected_output"]["overlapping_parts"].items())
test_params.expected_output.overlapping_parts.emplace_back(ShapeElement::from_json(json_element.value()));
for (auto& json_point: json["expected_output"]["improper_intersections"].items())
test_params.expected_output.improper_intersections.emplace_back(Point::from_json(json_point.value()));
for (auto& json_point: json["expected_output"]["proper_intersections"].items())
test_params.expected_output.proper_intersections.emplace_back(Point::from_json(json_point.value()));
return test_params;
}
};

Expand Down
Loading
Loading