Files
ViewDesignEngine/tests/fuzz/fuzz_boolean.cpp
T
茂之钳 107cf58034
CI / Build & Test (push) Failing after 33s
CI / Release Build (push) Failing after 29s
Build & Test / build-and-test (push) Has been cancelled
Build & Test / python-bindings (push) Has been cancelled
feat(v3.3): B-Rep face splitting + fuzz testing (all 3 tasks)
2026-07-24 12:48:42 +00:00

60 lines
1.8 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#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());
}
}