Skip to content

Commit

Permalink
Add deduplication test
Browse files Browse the repository at this point in the history
  • Loading branch information
sethrj committed Mar 2, 2024
1 parent d79d9c2 commit 675ce05
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
4 changes: 2 additions & 2 deletions test/orange/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ celeritas_add_library(testcel_orange
)
celeritas_target_link_libraries(testcel_orange
PUBLIC
Celeritas::orange Celeritas::testcel_harness
Celeritas::orange Celeritas::testcel_harness Celeritas::testcel_core
PRIVATE
Celeritas::testcel_geocel Celeritas::testcel_core Celeritas::orange ${nlohmann_json_LIBRARIES}
Celeritas::testcel_geocel Celeritas::orange ${nlohmann_json_LIBRARIES}
)

#-----------------------------------------------------------------------------#
Expand Down
45 changes: 42 additions & 3 deletions test/orange/orangeinp/Transformed.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//---------------------------------------------------------------------------//
#include "orange/orangeinp/Transformed.hh"

#include "corecel/ScopedLogStorer.hh"
#include "corecel/io/Logger.hh"
#include "orange/MatrixUtils.hh"
#include "orange/orangeinp/Shape.hh"

Expand Down Expand Up @@ -151,9 +153,19 @@ TEST_F(TransformedTest, inverse)
// Build original, transformed, and anti-transformed
this->build_volume(*cylshape);
this->build_volume(*transformed);
this->build_volume(Transformed{
transformed,
Transformation{make_rotation(Axis::x, Turn{0.25}), {0, 0, -2}}});
{
celeritas::test::ScopedLogStorer scoped_log_{
&celeritas::world_logger()};
this->build_volume(Transformed{
transformed,
Transformation{make_rotation(Axis::x, Turn{0.25}), {0, 0, -2}}});
static char const* const expected_log_messages[] = {
"While re-inserting region for node 7: existing transform {} "
"differs from new transform {{{1,0,0},{0,1,0},{0,0,1}}, {0,0,0}}"};
EXPECT_VEC_EQ(expected_log_messages, scoped_log_.messages());
static char const* const expected_log_levels[] = {"warning"};
EXPECT_VEC_EQ(expected_log_levels, scoped_log_.levels());
}

static char const* const expected_surface_strings[] = {
"Plane: z=-1",
Expand Down Expand Up @@ -189,6 +201,33 @@ TEST_F(TransformedTest, inverse)
EXPECT_VEC_EQ(expected_trans_strings, transform_strings(u));
}

TEST_F(TransformedTest, deduplicated_inverse)
{
Transformation const tr{make_rotation(Axis::x, Turn{-0.25}), {0, 2, 0}};
Transformation const inv_tr{make_rotation(Axis::x, Turn{0.25}), {0, 0, -2}};

auto sph_inner = std::make_shared<SphereShape>("sphi", Sphere{1.0});
auto sph_outer = std::make_shared<SphereShape>("spho", Sphere{2.0});
auto tr_inner = std::make_shared<Transformed>(sph_inner, tr);

// Build outer and anti-transformed
this->build_volume(*sph_outer);
this->build_volume(Transformed{tr_inner, inv_tr});

static char const* const expected_surface_strings[]
= {"Sphere: r=2", "Sphere: r=1"};
static char const* const expected_volume_strings[] = {"-0", "-1"};
static char const* const expected_trans_strings[]
= {"3: t=0 -> {}", "5: t=2 -> {{{1,0,0},{0,1,0},{0,0,1}}, {0,0,0}}"};
static int const expected_volume_nodes[] = {3, 5};

auto const& u = this->unit();
EXPECT_VEC_EQ(expected_surface_strings, surface_strings(u));
EXPECT_VEC_EQ(expected_volume_strings, volume_strings(u));
EXPECT_VEC_EQ(expected_trans_strings, transform_strings(u));
EXPECT_VEC_EQ(expected_volume_nodes, volume_nodes(u));
}

//---------------------------------------------------------------------------//
} // namespace test
} // namespace orangeinp
Expand Down

0 comments on commit 675ce05

Please sign in to comment.