tests: port DiscreteEllipticUtility + P2 tests; stub HDS-blocked tests
Fully ported (pure math, no HDS required):
test_discrete_elliptic_utility.cpp – 2 tests
normalizeModulus: move tau into SL(2,Z) fundamental domain
test_p2_utility.cpp – 3 tests
P2 projective geometry (perpendicularBisector, pointFromLines,
makeDirectIsometryFromFrames double vs long double precision)
New headers:
include/discrete_elliptic_utility.hpp – normalizeModulus
include/p2_utility.hpp – P2 Euclidean geometry (templated
on scalar type so double and long double share one implementation)
Stubs (GTEST_SKIP, blocked until HDS port – Phase 4):
test_hyper_ideal_functional.cpp – 5 tests (1 @Ignore in Java)
test_hyper_ideal_hyperelliptic_utility.cpp – 3 tests
test_spherical_functional.cpp – 5 tests
All use CoHDS + HalfEdgeUtils which are not yet ported to C++.
Result: 34 tests total | 21 passed | 13 skipped | 0 failed
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,17 @@
|
||||
add_executable(conformallab_tests
|
||||
# ── Fully ported (pure math, no HDS) ────────────────────────────────────
|
||||
test_clausen.cpp
|
||||
test_hyper_ideal_utility.cpp
|
||||
test_matrix_utility.cpp
|
||||
test_surface_curve_utility.cpp
|
||||
test_discrete_elliptic_utility.cpp
|
||||
test_p2_utility.cpp
|
||||
|
||||
# ── Stubs: blocked until HDS port (Phase 4) ──────────────────────────────
|
||||
# All tests call GTEST_SKIP() with a clear explanation.
|
||||
test_hyper_ideal_functional.cpp
|
||||
test_hyper_ideal_hyperelliptic_utility.cpp
|
||||
test_spherical_functional.cpp
|
||||
)
|
||||
|
||||
target_include_directories(conformallab_tests SYSTEM PRIVATE
|
||||
|
||||
39
code/tests/test_discrete_elliptic_utility.cpp
Normal file
39
code/tests/test_discrete_elliptic_utility.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
// Port of de.varylab.discreteconformal.util.DiscreteEllipticUtilityTest (Java/JUnit).
|
||||
// Tests the normalizeModulus function that moves a complex number tau into the
|
||||
// fundamental domain of the modular group SL(2,Z).
|
||||
|
||||
#include "discrete_elliptic_utility.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
#include <complex>
|
||||
#include <cmath>
|
||||
|
||||
using namespace conformallab;
|
||||
|
||||
// Corresponds to Java testNormalizeModulus()
|
||||
TEST(DiscreteEllipticUtilityTest, NormalizeModulus) {
|
||||
// tau already in fundamental domain → should be returned unchanged
|
||||
std::complex<double> tau(0.45, 1.1);
|
||||
auto tauNorm = normalizeModulus(tau);
|
||||
EXPECT_NEAR(0.45, tauNorm.real(), 1E-12);
|
||||
EXPECT_NEAR(1.1, tauNorm.imag(), 1E-12);
|
||||
|
||||
// tau = i/3 (|tau| < 1) → inversion gives 3i
|
||||
tau = std::complex<double>(0.0, 1.0 / 3.0);
|
||||
tauNorm = normalizeModulus(tau);
|
||||
EXPECT_NEAR(3.0, tauNorm.imag(), 1E-12);
|
||||
EXPECT_NEAR(0.0, tauNorm.real(), 1E-12);
|
||||
}
|
||||
|
||||
// Corresponds to Java testNormalizeModulusPeriodShift()
|
||||
// Two tau values that differ by a T-shift (integer shift of Re) must normalize
|
||||
// to the same point in the fundamental domain.
|
||||
TEST(DiscreteEllipticUtilityTest, NormalizeModulusPeriodShift) {
|
||||
std::complex<double> tau1(0.3, 1.0);
|
||||
std::complex<double> tau2(-0.7, 1.0); // tau2 = tau1 - 1
|
||||
|
||||
auto n1 = normalizeModulus(tau1);
|
||||
auto n2 = normalizeModulus(tau2);
|
||||
|
||||
EXPECT_NEAR(n1.real(), n2.real(), 1E-12) << "real parts should be equal";
|
||||
EXPECT_NEAR(n1.imag(), n2.imag(), 1E-12) << "imag parts should be equal";
|
||||
}
|
||||
37
code/tests/test_hyper_ideal_functional.cpp
Normal file
37
code/tests/test_hyper_ideal_functional.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
// Stub for de.varylab.discreteconformal.functional.HyperIdealFunctionalTest (Java/JUnit).
|
||||
//
|
||||
// STATUS: BLOCKED – requires HDS port (Phase 4).
|
||||
//
|
||||
// These tests evaluate gradient and Hessian of the HyperIdealFunctional on
|
||||
// actual mesh data (CoHDS + HyperIdealGenerator). They cannot be ported
|
||||
// until the HalfEdge data structure (CoHDS), the functional evaluation
|
||||
// framework, and the mesh generators are available in C++.
|
||||
//
|
||||
// Java tests and their status:
|
||||
// testHessian() – @Ignore in Java (skipped here too)
|
||||
// testGradientWithHyperIdealAndIdealPoints – blocked: needs HDS
|
||||
// testGradientInTheExtendedDomain – blocked: needs HDS
|
||||
// testGradientWithHyperellipticCurve – blocked: needs HDS
|
||||
// testFunctionalAtNaNValue – blocked: needs HDS
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(HyperIdealFunctionalTest, TestHessian_IgnoredInJava) {
|
||||
GTEST_SKIP() << "@Ignore in Java – skipped here too";
|
||||
}
|
||||
|
||||
TEST(HyperIdealFunctionalTest, GradientWithHyperIdealAndIdealPoints) {
|
||||
GTEST_SKIP() << "Blocked: requires HDS port (CoHDS + HyperIdealFunctional)";
|
||||
}
|
||||
|
||||
TEST(HyperIdealFunctionalTest, GradientInTheExtendedDomain) {
|
||||
GTEST_SKIP() << "Blocked: requires HDS port (CoHDS + HyperIdealFunctional)";
|
||||
}
|
||||
|
||||
TEST(HyperIdealFunctionalTest, GradientWithHyperellipticCurve) {
|
||||
GTEST_SKIP() << "Blocked: requires HDS port (CoHDS + HyperIdealFunctional)";
|
||||
}
|
||||
|
||||
TEST(HyperIdealFunctionalTest, FunctionalAtNaNValue) {
|
||||
GTEST_SKIP() << "Blocked: requires HDS port (CoHDS + HyperIdealFunctional)";
|
||||
}
|
||||
26
code/tests/test_hyper_ideal_hyperelliptic_utility.cpp
Normal file
26
code/tests/test_hyper_ideal_hyperelliptic_utility.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
// Stub for de.varylab.discreteconformal.functional.HyperIdealHyperellipticUtilityTest.
|
||||
//
|
||||
// STATUS: BLOCKED – requires HDS port (Phase 4).
|
||||
//
|
||||
// Tests compute intersection angles of circles associated with hyper-ideal
|
||||
// vertices using CoHDS + HalfEdgeUtils. All three tests operate on mesh
|
||||
// data structures that are not yet available in C++.
|
||||
//
|
||||
// Java tests and their status:
|
||||
// testCalculateCircleIntersections – blocked: needs CoHDS + HalfEdgeUtils
|
||||
// testCalculateCircleIntersectionsInfinite – blocked: needs CoHDS + HalfEdgeUtils
|
||||
// testLawsonHyperellipticAngles – blocked: needs CoHDS + HyperIdealGenerator
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(HyperIdealHyperellipticUtilityTest, CalculateCircleIntersections) {
|
||||
GTEST_SKIP() << "Blocked: requires HDS port (CoHDS + HalfEdgeUtils)";
|
||||
}
|
||||
|
||||
TEST(HyperIdealHyperellipticUtilityTest, CalculateCircleIntersectionsInfinite) {
|
||||
GTEST_SKIP() << "Blocked: requires HDS port (CoHDS + HalfEdgeUtils)";
|
||||
}
|
||||
|
||||
TEST(HyperIdealHyperellipticUtilityTest, LawsonHyperellipticAngles) {
|
||||
GTEST_SKIP() << "Blocked: requires HDS port (CoHDS + HyperIdealGenerator)";
|
||||
}
|
||||
87
code/tests/test_p2_utility.cpp
Normal file
87
code/tests/test_p2_utility.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
// Port of de.varylab.discreteconformal.math.P2BigTest (Java/JUnit).
|
||||
// Tests 2-D projective geometry utilities: perpendicular bisectors,
|
||||
// point-from-lines, and direct isometries in the Euclidean plane.
|
||||
//
|
||||
// The Java test compared double precision (P2) against BigDecimal precision
|
||||
// (P2Big) to 1E-10. Here we compare double against long double to the
|
||||
// same tolerance.
|
||||
|
||||
#include "p2_utility.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
#include <Eigen/Dense>
|
||||
#include <cmath>
|
||||
|
||||
using namespace conformallab;
|
||||
|
||||
// Corresponds to Java P2BigTest.testMakeDirectIsometryFromFramesEuclidean()
|
||||
//
|
||||
// Computes the Euclidean isometry mapping frame (s1,s2) to frame (t1,t2)
|
||||
// with both double and long-double precision, and checks:
|
||||
// 1. The two precisions agree to 1E-10 (precision stability).
|
||||
// 2. The matrix actually maps s1→t1 and s2→t2.
|
||||
TEST(P2UtilityTest, MakeDirectIsometryFromFramesEuclidean) {
|
||||
using V3d = Eigen::Vector3d;
|
||||
using V3ld = Eigen::Matrix<long double, 3, 1>;
|
||||
|
||||
V3d s1(-1.4142135623730963, 0.0, 1.0);
|
||||
V3d s2( 1.4142135623730951, 0.0, 1.0);
|
||||
V3d t1(-2.828427124746189, 2.4494897427831805, 1.0);
|
||||
V3d t2( 0.0, 2.4494897427831783, 1.0);
|
||||
|
||||
// double precision
|
||||
auto T = makeDirectIsometryFromFramesEuclidean<double>(s1, s2, t1, t2);
|
||||
|
||||
// long double precision (analogous to Java's BigDecimal P2Big)
|
||||
V3ld s1l = s1.cast<long double>();
|
||||
V3ld s2l = s2.cast<long double>();
|
||||
V3ld t1l = t1.cast<long double>();
|
||||
V3ld t2l = t2.cast<long double>();
|
||||
auto Tl = makeDirectIsometryFromFramesEuclidean<long double>(s1l, s2l, t1l, t2l);
|
||||
|
||||
// 1. double vs long double must agree to 1E-10
|
||||
for (int i = 0; i < 3; ++i)
|
||||
for (int j = 0; j < 3; ++j)
|
||||
EXPECT_NEAR((double)Tl(i,j), T(i,j), 1E-10)
|
||||
<< "element (" << i << "," << j << ") differs between precisions";
|
||||
|
||||
// 2. T must map s1 → t1 and s2 → t2 (verify isometry correctness)
|
||||
auto map_s1 = T * s1;
|
||||
auto map_s2 = T * s2;
|
||||
EXPECT_NEAR(euclideanDistanceP2(map_s1, t1), 0.0, 1E-9) << "T*s1 should equal t1";
|
||||
EXPECT_NEAR(euclideanDistanceP2(map_s2, t2), 0.0, 1E-9) << "T*s2 should equal t2";
|
||||
}
|
||||
|
||||
// Corresponds to Java P2BigTest.testPerpendicularBisector()
|
||||
TEST(P2UtilityTest, PerpendicularBisector) {
|
||||
Eigen::Vector3d p1(0.5, 0.0, 1.0);
|
||||
Eigen::Vector3d q1(0.0, 0.5, 1.0);
|
||||
|
||||
auto bisector = perpendicularBisectorEuclidean(p1, q1);
|
||||
|
||||
EXPECT_NEAR( 0.5, bisector(0), 1E-10);
|
||||
EXPECT_NEAR(-0.5, bisector(1), 1E-10);
|
||||
EXPECT_NEAR( 0.0, bisector(2), 1E-10);
|
||||
}
|
||||
|
||||
// Corresponds to Java P2BigTest.testPerpendicularBisectorIntersection()
|
||||
//
|
||||
// The intersection of the perpendicular bisectors of two edges must be
|
||||
// equidistant from the endpoints of each edge (circumcenter property).
|
||||
TEST(P2UtilityTest, PerpendicularBisectorIntersection) {
|
||||
Eigen::Vector3d p1(0.5, 0.0, 1.0);
|
||||
Eigen::Vector3d q1(0.0, 1.0, 1.0);
|
||||
Eigen::Vector3d p2(1.0, 0.0, 1.0);
|
||||
Eigen::Vector3d q2(0.0, 1.5, 1.0);
|
||||
|
||||
auto l1 = perpendicularBisectorEuclidean(p1, q1);
|
||||
auto l2 = perpendicularBisectorEuclidean(p2, q2);
|
||||
auto o = pointFromLines(l1, l2); // circumcenter
|
||||
|
||||
// o must be equidistant from p1 and q1
|
||||
EXPECT_NEAR(euclideanDistanceP2(p1, o),
|
||||
euclideanDistanceP2(q1, o), 1E-10);
|
||||
|
||||
// o must be equidistant from p2 and q2
|
||||
EXPECT_NEAR(euclideanDistanceP2(p2, o),
|
||||
euclideanDistanceP2(q2, o), 1E-10);
|
||||
}
|
||||
37
code/tests/test_spherical_functional.cpp
Normal file
37
code/tests/test_spherical_functional.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
// Stub for de.varylab.discreteconformal.functional.SphericalFunctionalTest (Java/JUnit).
|
||||
//
|
||||
// STATUS: BLOCKED – requires HDS port (Phase 4).
|
||||
//
|
||||
// Tests evaluate gradient and Hessian of the SphericalFunctional on meshes
|
||||
// built via CoHDS + ConvexHull, and check that a regular spherical metric
|
||||
// is a critical point of the functional. All tests require the HalfEdge
|
||||
// data structure and the functional evaluation framework in C++.
|
||||
//
|
||||
// Java tests and their status:
|
||||
// testReducedGradient – blocked: needs CoHDS + SphericalFunctional
|
||||
// testReducedHessian – blocked: needs CoHDS + SphericalFunctional
|
||||
// testGradient – blocked: needs CoHDS + SphericalFunctional
|
||||
// testHessian – blocked: needs CoHDS + SphericalFunctional
|
||||
// testCriticalPoint – blocked: needs CoHDS + ConvexHull + SphericalFunctional
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(SphericalFunctionalTest, ReducedGradient) {
|
||||
GTEST_SKIP() << "Blocked: requires HDS port (CoHDS + SphericalFunctional)";
|
||||
}
|
||||
|
||||
TEST(SphericalFunctionalTest, ReducedHessian) {
|
||||
GTEST_SKIP() << "Blocked: requires HDS port (CoHDS + SphericalFunctional)";
|
||||
}
|
||||
|
||||
TEST(SphericalFunctionalTest, Gradient) {
|
||||
GTEST_SKIP() << "Blocked: requires HDS port (CoHDS + SphericalFunctional)";
|
||||
}
|
||||
|
||||
TEST(SphericalFunctionalTest, Hessian) {
|
||||
GTEST_SKIP() << "Blocked: requires HDS port (CoHDS + SphericalFunctional)";
|
||||
}
|
||||
|
||||
TEST(SphericalFunctionalTest, CriticalPoint) {
|
||||
GTEST_SKIP() << "Blocked: requires HDS port (CoHDS + ConvexHull + SphericalFunctional)";
|
||||
}
|
||||
Reference in New Issue
Block a user