Skip to content

Commit 5d43a0a

Browse files
authored
test: Add test for quads (#37)
Add a test for the correctness of merging and splitting quads
1 parent 788b2df commit 5d43a0a

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_policy(SET CMP0054 NEW)
22
find_package(GTest REQUIRED)
33
include(GoogleTest)
44

5-
set(SOURCES axis.cpp triangles.cpp)
5+
set(SOURCES axis.cpp triangles.cpp quads.cpp)
66
add_executable(axis ${SOURCES})
77

88
target_include_directories(

tests/quads.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// SPDX-License-Identifier: GPL-3.0-or-later
2+
// Copyright (c) 2024 Team Dissolve and contributors
3+
4+
#include "triangle.h"
5+
#include <gtest/gtest.h>
6+
#include <numeric>
7+
8+
namespace UnitTest
9+
{
10+
11+
TEST(QuadTest, Combine)
12+
{
13+
std::vector<Quad> ts = {{{-1, 5, 9}, {4, 8, 3}, {-7, 2, 6}, {6, 4, -3}},
14+
{{1, -2, -3}, {-4, -8, -6}, {7, -5, -9}, {3, -4, 6}}};
15+
16+
std::vector<Edge> boxes(ts.size());
17+
std::transform(ts.begin(), ts.end(), boxes.begin(), [](const auto x) { return x.bounds(); });
18+
EXPECT_EQ(boxes[1].start.x, -4);
19+
EXPECT_EQ(boxes[1].start.y, -8);
20+
EXPECT_EQ(boxes[1].start.z, -9);
21+
EXPECT_EQ(boxes[1].end.x, 7);
22+
EXPECT_EQ(boxes[1].end.y, -2);
23+
EXPECT_EQ(boxes[1].end.z, 6);
24+
25+
EXPECT_EQ(boxes[0].start.x, -7);
26+
EXPECT_EQ(boxes[0].start.y, 2);
27+
EXPECT_EQ(boxes[0].start.z, -3);
28+
EXPECT_EQ(boxes[0].end.x, 6);
29+
EXPECT_EQ(boxes[0].end.y, 8);
30+
EXPECT_EQ(boxes[0].end.z, 9);
31+
32+
auto bounds = std::reduce(boxes.begin(), boxes.end(), boxes[0], [](const auto a, const auto b) { return a.combine(b); });
33+
34+
EXPECT_EQ(bounds.start.x, -7);
35+
EXPECT_EQ(bounds.start.y, -8);
36+
EXPECT_EQ(bounds.start.z, -9);
37+
EXPECT_EQ(bounds.end.x, 7);
38+
EXPECT_EQ(bounds.end.y, 8);
39+
EXPECT_EQ(bounds.end.z, 9);
40+
}
41+
42+
TEST(QuadTest, Cut)
43+
{
44+
Vec3<float> i{1, 2, 3}, j{4, 5, 6}, k{7, 8, 9}, l{10, 11, 12};
45+
Quad q{i, j, k, l};
46+
auto [first, second] = q.asTriangles();
47+
48+
EXPECT_EQ(first.a, i);
49+
EXPECT_EQ(first.b, j);
50+
EXPECT_EQ(first.c, k);
51+
52+
EXPECT_EQ(second.a, k);
53+
EXPECT_EQ(second.b, l);
54+
EXPECT_EQ(second.c, i);
55+
}
56+
} // namespace UnitTest

0 commit comments

Comments
 (0)