Skip to content

Commit

Permalink
test: Add test for quads (#37)
Browse files Browse the repository at this point in the history
Add a test for the correctness of merging and splitting quads
  • Loading branch information
rprospero authored Sep 4, 2024
1 parent 788b2df commit 5d43a0a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_policy(SET CMP0054 NEW)
find_package(GTest REQUIRED)
include(GoogleTest)

set(SOURCES axis.cpp triangles.cpp)
set(SOURCES axis.cpp triangles.cpp quads.cpp)
add_executable(axis ${SOURCES})

target_include_directories(
Expand Down
56 changes: 56 additions & 0 deletions tests/quads.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (c) 2024 Team Dissolve and contributors

#include "triangle.h"
#include <gtest/gtest.h>
#include <numeric>

namespace UnitTest
{

TEST(QuadTest, Combine)
{
std::vector<Quad> ts = {{{-1, 5, 9}, {4, 8, 3}, {-7, 2, 6}, {6, 4, -3}},
{{1, -2, -3}, {-4, -8, -6}, {7, -5, -9}, {3, -4, 6}}};

std::vector<Edge> boxes(ts.size());
std::transform(ts.begin(), ts.end(), boxes.begin(), [](const auto x) { return x.bounds(); });
EXPECT_EQ(boxes[1].start.x, -4);
EXPECT_EQ(boxes[1].start.y, -8);
EXPECT_EQ(boxes[1].start.z, -9);
EXPECT_EQ(boxes[1].end.x, 7);
EXPECT_EQ(boxes[1].end.y, -2);
EXPECT_EQ(boxes[1].end.z, 6);

EXPECT_EQ(boxes[0].start.x, -7);
EXPECT_EQ(boxes[0].start.y, 2);
EXPECT_EQ(boxes[0].start.z, -3);
EXPECT_EQ(boxes[0].end.x, 6);
EXPECT_EQ(boxes[0].end.y, 8);
EXPECT_EQ(boxes[0].end.z, 9);

auto bounds = std::reduce(boxes.begin(), boxes.end(), boxes[0], [](const auto a, const auto b) { return a.combine(b); });

EXPECT_EQ(bounds.start.x, -7);
EXPECT_EQ(bounds.start.y, -8);
EXPECT_EQ(bounds.start.z, -9);
EXPECT_EQ(bounds.end.x, 7);
EXPECT_EQ(bounds.end.y, 8);
EXPECT_EQ(bounds.end.z, 9);
}

TEST(QuadTest, Cut)
{
Vec3<float> i{1, 2, 3}, j{4, 5, 6}, k{7, 8, 9}, l{10, 11, 12};
Quad q{i, j, k, l};
auto [first, second] = q.asTriangles();

EXPECT_EQ(first.a, i);
EXPECT_EQ(first.b, j);
EXPECT_EQ(first.c, k);

EXPECT_EQ(second.a, k);
EXPECT_EQ(second.b, l);
EXPECT_EQ(second.c, i);
}
} // namespace UnitTest

0 comments on commit 5d43a0a

Please sign in to comment.