forked from openmc-dev/openmc
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_region.cpp
More file actions
101 lines (84 loc) · 2.53 KB
/
test_region.cpp
File metadata and controls
101 lines (84 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <catch2/catch_test_macros.hpp>
#include "openmc/cell.h"
#include "openmc/surface.h"
#include <pugixml.hpp>
namespace {
// Helper class to set up and tear down test surfaces
class SurfaceFixture {
public:
SurfaceFixture()
{
pugi::xml_document doc;
pugi::xml_node surf_node = doc.append_child("surface");
surf_node.set_name("surface");
surf_node.append_attribute("id") = "0";
surf_node.append_attribute("type") = "x-plane";
surf_node.append_attribute("coeffs") = "1";
for (int i = 1; i < 10; ++i) {
surf_node.attribute("id") = i;
openmc::model::surfaces.push_back(
std::make_unique<openmc::SurfaceXPlane>(surf_node));
openmc::model::surface_map[i] = i - 1;
}
}
~SurfaceFixture()
{
openmc::model::surfaces.clear();
openmc::model::surface_map.clear();
}
};
} // anonymous namespace
TEST_CASE("Test region simplification")
{
SurfaceFixture fixture;
SECTION("Original bug case from issue #3685")
{
// Input: "-1 2 (-3 4) | (-5 6)" was being incorrectly interpreted
auto region = openmc::Region("(-1 2 (-3 4) | (-5 6))", 0);
REQUIRE(region.str() == " ( ( -1 2 ( -3 4 ) ) | ( -5 6 ) )");
}
SECTION("Simple union - no extra parentheses needed")
{
auto region = openmc::Region("1 | 2", 0);
REQUIRE(region.str() == " 1 | 2");
}
SECTION("Intersection then union")
{
// Intersection should have higher precedence, so (1 2) grouped
auto region = openmc::Region("1 2 | 3", 0);
REQUIRE(region.str() == " ( 1 2 ) | 3");
}
SECTION("Union then intersection")
{
// The (2 3) intersection should be grouped
auto region = openmc::Region("1 | 2 3", 0);
REQUIRE(region.str() == " 1 | ( 2 3 )");
}
SECTION("Nested parentheses preserved")
{
// These parentheses are meaningful and should be preserved
auto region = openmc::Region("(1 | 2) (3 | 4)", 0);
REQUIRE(region.str() == " ( 1 | 2 ) ( 3 | 4 )");
}
SECTION("Deep nesting")
{
auto region = openmc::Region("((1 2) | (3 4)) 5", 0);
REQUIRE(region.str() == " ( ( 1 2 ) | ( 3 4 ) ) 5");
}
SECTION("Multiple unions")
{
auto region = openmc::Region("1 | 2 | 3", 0);
REQUIRE(region.str() == " 1 | 2 | 3");
}
SECTION("Multiple intersections")
{
auto region = openmc::Region("1 2 3", 0);
// Simple cell - no operators in output
REQUIRE(region.str() == " 1 2 3");
}
SECTION("Complex mixed expression")
{
auto region = openmc::Region("1 2 | 3 4 | 5 6", 0);
REQUIRE(region.str() == " ( 1 2 ) | ( 3 4 ) | ( 5 6 )");
}
}