From dc85740d54c12618a4d2a83ff9fb26c9ed98c6fe Mon Sep 17 00:00:00 2001 From: SatoshiTerasaki Date: Tue, 24 Dec 2024 13:00:43 +0900 Subject: [PATCH] Enable tests using deriv --- test/augment.cxx | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/test/augment.cxx b/test/augment.cxx index 4ae46f7..1cad976 100644 --- a/test/augment.cxx +++ b/test/augment.cxx @@ -38,8 +38,13 @@ TEST_CASE("SparseIR Basis Functions", "[SparseIR]") REQUIRE(tc(freq92) == 0.0); MatsubaraFreq freq93(93); REQUIRE_THROWS_AS(tc(freq93), std::invalid_argument); - //REQUIRE(sparseir::deriv(tc)(4.2) == 0.0); - //REQUIRE(sparseir::deriv(tc, 0) == tc); + auto tdc = tc.deriv(); + REQUIRE(tdc(4.2) == 0.0); + + tdc = tc.deriv(0); + double x = 4.2; + // Expected tdc == tc + REQUIRE(tdc(x) == tc(x)); } SECTION("TauLinear") @@ -69,10 +74,14 @@ TEST_CASE("SparseIR Basis Functions", "[SparseIR]") MatsubaraFreq freq93(93); REQUIRE_THROWS_AS(tl(freq93), std::invalid_argument); - //REQUIRE(sparseir::deriv(tl, 0) == tl); - //REQUIRE(sparseir::deriv(tl)(4.2) == - // Approx(std::sqrt(3 / 123) * 2 / 123)); - //REQUIRE(sparseir::deriv(tl, 2)(4.2) == Approx(0.0)); + double x = 4.2; + auto d0tl = tl.deriv(0); + REQUIRE(d0tl(x) == tl(x)); + auto dtl = tl.deriv(); + REQUIRE(dtl(4.2) == + Approx(std::sqrt(3. / 123.) * 2. / 123.)); + auto ddtl = tl.deriv(2); + REQUIRE(ddtl(4.2) == 0.0); } SECTION("MatsubaraConst") @@ -93,8 +102,14 @@ TEST_CASE("SparseIR Basis Functions", "[SparseIR]") MatsubaraFreq freq93(93); REQUIRE(mc(freq93) == 1.0); - //REQUIRE(sparseir::deriv(mc) == mc); - //REQUIRE(sparseir::deriv(mc, 0) == mc); + auto d0mc = mc.deriv(0); + auto dmc = mc.deriv(); + double x = 4.2; + // Expected dmc == mc + REQUIRE(std::isnan(d0mc(x))); + REQUIRE(std::isnan(mc(x))); + REQUIRE(std::isnan(dmc(x))); + REQUIRE(std::isnan(mc(x))); } }