// Copyright (c) 2024-2026 Tarik Moussa. // SPDX-License-Identifier: MIT // 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 #include #include using namespace conformallab; // Corresponds to Java testNormalizeModulus() TEST(DiscreteEllipticUtilityTest, NormalizeModulus) { // tau already in fundamental domain → should be returned unchanged std::complex 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(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 tau1(0.3, 1.0); std::complex 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"; }