diff --git a/.gitignore b/.gitignore index 6d7270f82d1cd707caf4df63c42211684a949cd5..316af6224233d8c1a92a712ba395c24f64be58a3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ build .vscode/c_cpp_properties.json .vscode/launch.json +.vscode/settings.json \ No newline at end of file diff --git a/tests/union_tests.cpp b/tests/union_tests.cpp index e468886358f70b7bfda2f90795dad06d5c490eb2..363956ca70ff9da94ecde1f6b1e59f7b62b9754f 100644 --- a/tests/union_tests.cpp +++ b/tests/union_tests.cpp @@ -1,23 +1,106 @@ #include "gtest/gtest.h" #include <union.h> -#include<triangle.h> +#include <triangle.h> -TEST (UnionTrivialTests, NotTouching) { - Triangle t1 = Triangle{{0,0}, {5,0}, {2,3}, 0}; - Triangle t2 = Triangle{{6,0}, {10,0}, {7,5}, 0}; +TEST(UnionTrivialTests, NotTouching) +{ + Triangle t1 = Triangle{{0, 0}, {5, 0}, {2, 3}, 0}; + Triangle t2 = Triangle{{6, 0}, {10, 0}, {7, 5}, 0}; auto ts = unionize(t1, t2); EXPECT_TRUE(ts.size() == 2); } +TEST(UnionTests, TwoIntersections) +{ -TEST (UnionTests, TwoIntersections) { - - auto t1 = Triangle(Point{0,0}, Point{5,0}, Point{2,3}, 0); - auto t2 = Triangle(Point{3,1}, Point{6,1}, Point{4,3}, 0); + auto t1 = Triangle(Point{0, 0}, Point{5, 0}, Point{2, 3}, 0); + auto t2 = Triangle(Point{3, 1}, Point{6, 1}, Point{4, 3}, 0); auto ts = unionize(t1, t2); EXPECT_TRUE(ts.size() > 0); +} + +TEST(UnionTests, TriangleTreeShapeTest) +{ + // Case 1 t1 covers t2 + Triangle bottom = Triangle({0, 5}, {3, 2}, {5, 3}, 1, 1); + Triangle top = Triangle({0.1, 7}, {5, 3}, {3.2, 9}, 2, 2); + + auto results = unionize(bottom, top); + std::vector<Triangle> expected_results_1; + + EXPECT_EQ(results, expected_results_1); + + // Case 2 t2 covers t1 + bottom.depth = 3; + + results = unionize(bottom, top); + + std::vector<Triangle> expected_results_2; + + EXPECT_EQ(results, expected_results_2); +} + +TEST(UnionTests, FoldTriangleTest) +{ + + Triangle bottom = Triangle({0, 5}, {3, 2}, {5, 3}, 1, 1); + Triangle top = Triangle({0.1, 9}, {5, 5}, {2, 4}, 2, 2); + + auto results = unionize(bottom, top); + + std::vector<Triangle> expected_results_1; + + EXPECT_EQ(results, expected_results_1); + + bottom.depth = 3; + + results = unionize(bottom, top); + + std::vector<Triangle> expected_results_2; + + EXPECT_EQ(results, expected_results_2); +} + +TEST(UnionTests, IceCreamTest) +{ + Triangle bottom = Triangle({0, 5}, {3, 2}, {5, 3}, 1, 1); + Triangle top = Triangle({-1, 5}, {2, 4}, {5, 7}, 2, 2); + + auto results = unionize(bottom, top); + + std::vector<Triangle> expected_results_1; + + EXPECT_EQ(results, expected_results_1); + + bottom.depth = 3; + + results = unionize(bottom, top); + + std::vector<Triangle> expected_results_2; + + EXPECT_EQ(results, expected_results_2); +} + +TEST(UnionTests, StarTest) +{ + Triangle bottom = Triangle({0, 3}, {2.5, 6}, {5, 3}, 1, 1); + Triangle top = Triangle({0, 5}, {2, 0}, {5, 5}, 2, 2); + + auto results = unionize(bottom, top); + + std::vector<Triangle> expected_results_1; + + EXPECT_EQ(results, expected_results_1); + + bottom.depth = 3; + + results = unionize(bottom, top); + + std::vector<Triangle> expected_results_2; + + EXPECT_EQ(results, expected_results_2); } \ No newline at end of file