Files
ViewDesignEngine/tests/fuzz/fuzz_boolean.cpp
T

60 lines
1.8 KiB
C++
Raw Normal View History

#include <gtest/gtest.h>
#include "vde/brep/brep_boolean.h"
#include "vde/brep/modeling.h"
#include <cmath>
#include <random>
using namespace vde::brep;
// ── B-Rep fuzz: random sized boxes with boolean operations ──
TEST(FuzzBoolean, RandomBoxBooleans) {
std::mt19937 rng(42);
std::uniform_real_distribution<double> size_dist(1.0, 5.0);
std::uniform_real_distribution<double> offset_dist(-2.0, 2.0);
for (int i = 0; i < 30; ++i) {
double s1 = size_dist(rng);
double s2 = size_dist(rng);
double ox = offset_dist(rng);
double oy = offset_dist(rng);
double oz = offset_dist(rng);
// NOTE: ox, oy, oz computed for future translate API use
(void)ox; (void)oy; (void)oz;
auto box1 = make_box(s1, s1, s1);
auto box2 = make_box(s2, s2, s2);
// Test that operations don't crash
auto u = brep_union(box1, box2);
auto inter = brep_intersection(box1, box2);
auto diff = brep_difference(box1, box2);
// Basic sanity: results should have finite bounds
EXPECT_TRUE(std::isfinite(u.bounds().min().x()));
EXPECT_TRUE(std::isfinite(inter.bounds().min().x()));
EXPECT_TRUE(std::isfinite(diff.bounds().min().x()));
}
}
// ── B-Rep fuzz: self-operations (AA, A∩A, A\A) ──
TEST(FuzzBoolean, SelfOperations) {
for (int i = 0; i < 20; ++i) {
double s = 1.0 + i * 0.2;
auto box = make_box(s, s, s);
// Self-union should be valid
auto self_u = brep_union(box, box);
EXPECT_TRUE(self_u.is_valid());
// Self-difference should be valid
auto self_d = brep_difference(box, box);
EXPECT_TRUE(self_d.is_valid());
// Self-intersection should be valid
auto self_i = brep_intersection(box, box);
EXPECT_TRUE(self_i.is_valid());
}
}