Skip to content

Commit

Permalink
Catchv3 support in tests. (#213)
Browse files Browse the repository at this point in the history
* Catchv3 support in tests.

* Drop DownloadProject by suggestion of robertodr.

* Rewrite fetch part of script to follow Eigen3 script
  • Loading branch information
susilehtola authored Aug 18, 2023
1 parent df9b054 commit 5320eb4
Show file tree
Hide file tree
Showing 28 changed files with 237 additions and 18,166 deletions.
17,937 changes: 0 additions & 17,937 deletions external/catch/catch.hpp

This file was deleted.

20 changes: 14 additions & 6 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
# Prepare "Catch" library for other executables, if not already available
if(NOT TARGET Catch)
add_library(Catch INTERFACE)
target_include_directories(Catch INTERFACE ${PROJECT_SOURCE_DIR}/external/catch)
find_package( Catch2 3.0.1 CONFIG)
if( NOT Catch2_FOUND )
message( STATUS "Could NOT Find Catch2 (Building v3.3.2 Locally)" )
include( FetchContent )
FetchContent_Declare(
catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.3.2
)
set(BUILD_TESTING OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(catch2)
else()
message( STATUS "Found Catch2 VERSION ${Catch2_VERSION} DIR ${Catch2_DIR}" )
endif()

set(CMAKE_INCLUDE_CURRENT_DIR ON)
Expand All @@ -15,8 +24,7 @@ add_subdirectory(trees)
add_subdirectory(scalingfactor)

target_link_libraries(mrcpp-tests
mrcpp
Catch
PUBLIC mrcpp Catch2::Catch2WithMain
)

# RPATH fixing
Expand Down
2 changes: 1 addition & 1 deletion tests/core/gauss_quadrature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* <https://mrcpp.readthedocs.io/>
*/

#include "catch.hpp"
#include "catch2/catch_all.hpp"

using namespace mrcpp;

Expand Down
10 changes: 5 additions & 5 deletions tests/core/mw_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* <https://mrcpp.readthedocs.io/>
*/

#include "catch.hpp"
#include "catch2/catch_all.hpp"

#include "MRCPP/constants.h"
#include "core/FilterCache.h"
Expand All @@ -47,17 +47,17 @@ TEST_CASE("Interpolating filters", "[mw_filter]") {
double sc = F.col(i).dot(F.col(j));
double sr = F.row(i).dot(F.row(j));
if (i == j) {
REQUIRE(sc == Approx(1.0));
REQUIRE(sr == Approx(1.0));
REQUIRE(sc == Catch::Approx(1.0));
REQUIRE(sr == Catch::Approx(1.0));
} else {
off_diag_col += std::abs(sc);
off_diag_row += std::abs(sr);
}
}
}
}
REQUIRE(off_diag_col == Approx(0.0).margin(1.0e-12));
REQUIRE(off_diag_row == Approx(0.0).margin(1.0e-12));
REQUIRE(off_diag_col == Catch::Approx(0.0).margin(1.0e-12));
REQUIRE(off_diag_row == Catch::Approx(0.0).margin(1.0e-12));
}
}

Expand Down
30 changes: 15 additions & 15 deletions tests/core/scaling_basis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* <https://mrcpp.readthedocs.io/>
*/

#include "catch.hpp"
#include "catch2/catch_all.hpp"

#include "core/InterpolatingBasis.h"
#include "core/LegendreBasis.h"
Expand All @@ -41,8 +41,8 @@ TEST_CASE("InterpolatingBasis", "[interpolating_basis], [scaling_basis]") {
SECTION("Constructor") {
for (int k = 0; k < 1; k++) {
const Polynomial &P_k = basis.getFunc(k);
REQUIRE(P_k.getScaledLowerBound() == Approx(0.0));
REQUIRE(P_k.getScaledUpperBound() == Approx(1.0));
REQUIRE(P_k.getScaledLowerBound() == Catch::Approx(0.0));
REQUIRE(P_k.getScaledUpperBound() == Catch::Approx(1.0));
REQUIRE(P_k.getOrder() == 1);
}
}
Expand All @@ -53,8 +53,8 @@ TEST_CASE("InterpolatingBasis", "[interpolating_basis], [scaling_basis]") {
SECTION("Constructor") {
for (int k = 0; k < 6; k++) {
const Polynomial &P_k = basis.getFunc(k);
REQUIRE(P_k.getScaledLowerBound() == Approx(0.0));
REQUIRE(P_k.getScaledUpperBound() == Approx(1.0));
REQUIRE(P_k.getScaledLowerBound() == Catch::Approx(0.0));
REQUIRE(P_k.getScaledUpperBound() == Catch::Approx(1.0));
REQUIRE(P_k.getOrder() == 6);
}
}
Expand All @@ -65,8 +65,8 @@ TEST_CASE("InterpolatingBasis", "[interpolating_basis], [scaling_basis]") {
SECTION("Constructor") {
for (int k = 0; k < 10; k++) {
const Polynomial &P_k = basis.getFunc(k);
REQUIRE(P_k.getScaledLowerBound() == Approx(0.0));
REQUIRE(P_k.getScaledUpperBound() == Approx(1.0));
REQUIRE(P_k.getScaledLowerBound() == Catch::Approx(0.0));
REQUIRE(P_k.getScaledUpperBound() == Catch::Approx(1.0));
REQUIRE(P_k.getOrder() == 10);
}
}
Expand All @@ -80,8 +80,8 @@ TEST_CASE("LegendreBasis", "[legendre_basis], [scaling_basis]") {
SECTION("Constructor") {
for (int k = 0; k < 1; k++) {
const Polynomial &P_k = basis.getFunc(k);
REQUIRE(P_k.getScaledLowerBound() == Approx(0.0));
REQUIRE(P_k.getScaledUpperBound() == Approx(1.0));
REQUIRE(P_k.getScaledLowerBound() == Catch::Approx(0.0));
REQUIRE(P_k.getScaledUpperBound() == Catch::Approx(1.0));
REQUIRE(P_k.getOrder() == k);
}
}
Expand All @@ -92,8 +92,8 @@ TEST_CASE("LegendreBasis", "[legendre_basis], [scaling_basis]") {
SECTION("Test constructor") {
for (int k = 0; k < 6; k++) {
const Polynomial &P_k = basis.getFunc(k);
REQUIRE(P_k.getScaledLowerBound() == Approx(0.0));
REQUIRE(P_k.getScaledUpperBound() == Approx(1.0));
REQUIRE(P_k.getScaledLowerBound() == Catch::Approx(0.0));
REQUIRE(P_k.getScaledUpperBound() == Catch::Approx(1.0));
REQUIRE(P_k.getOrder() == k);
}
}
Expand All @@ -104,8 +104,8 @@ TEST_CASE("LegendreBasis", "[legendre_basis], [scaling_basis]") {
SECTION("Test constructor") {
for (int k = 0; k < 10; k++) {
const Polynomial &P_k = basis.getFunc(k);
REQUIRE(P_k.getScaledLowerBound() == Approx(0.0));
REQUIRE(P_k.getScaledUpperBound() == Approx(1.0));
REQUIRE(P_k.getScaledLowerBound() == Catch::Approx(0.0));
REQUIRE(P_k.getScaledUpperBound() == Catch::Approx(1.0));
REQUIRE(P_k.getOrder() == k);
}
}
Expand All @@ -117,11 +117,11 @@ template <int K> void testOrthonormality(const ScalingBasis &basis) {
for (int i = 0; i < K; i++) {
const Polynomial &P_i = basis.getFunc(i);
double S_ii = P_i.innerProduct(P_i);
REQUIRE(S_ii == Approx(1.0));
REQUIRE(S_ii == Catch::Approx(1.0));
for (int j = 0; j < i; j++) {
const Polynomial &P_j = basis.getFunc(j);
double S_ij = P_i.innerProduct(P_j);
REQUIRE(S_ij == Approx(0.0).margin(1.0e-10));
REQUIRE(S_ij == Catch::Approx(0.0).margin(1.0e-10));
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/functions/gaussians.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* <https://mrcpp.readthedocs.io/>
*/

#include "catch.hpp"
#include "catch2/catch_all.hpp"

#include "factory_functions.h"

Expand Down Expand Up @@ -77,9 +77,9 @@ SCENARIO("Gaussians", "[gaussians]") {
project(prec, f_tree, gauss);

WHEN("Gaussians are projected") {
THEN("The gaussian can be evaluated") { REQUIRE(gauss.evalf(r_ref) == Approx(ref_val)); }
THEN("The gaussian can be evaluated") { REQUIRE(gauss.evalf(r_ref) == Catch::Approx(ref_val)); }

THEN("the integral is normalized") { REQUIRE(f_tree.integrate() == Approx(1.0)); }
THEN("the integral is normalized") { REQUIRE(f_tree.integrate() == Catch::Approx(1.0)); }

THEN("multiply") {
auto prod_gauss = gauss.mult(gauss);
Expand Down
10 changes: 5 additions & 5 deletions tests/functions/legendre_poly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* <https://mrcpp.readthedocs.io/>
*/

#include "catch.hpp"
#include "catch2/catch_all.hpp"

#include "functions/LegendrePoly.h"

Expand All @@ -42,12 +42,12 @@ TEST_CASE("Legendre polynomials", "[legendre_poly], [polynomials]") {
SECTION("LegendrePoly constructor") {
for (int k = 0; k < nLeg; k++) {
LegendrePoly &L_k = *L[k];
REQUIRE(L_k.getScaledLowerBound() == Approx(0.0));
REQUIRE(L_k.getScaledUpperBound() == Approx(1.0));
REQUIRE(L_k.getScaledLowerBound() == Catch::Approx(0.0));
REQUIRE(L_k.getScaledUpperBound() == Catch::Approx(1.0));
REQUIRE(L_k.getOrder() == k);
// Legendre polynomials are normalized so that L_k(1.0) = 1.0
Coord<1> one{1.0};
REQUIRE(L_k.evalf(one) == Approx(1.0));
REQUIRE(L_k.evalf(one) == Catch::Approx(1.0));
}
}

Expand All @@ -59,7 +59,7 @@ TEST_CASE("Legendre polynomials", "[legendre_poly], [polynomials]") {
for (int j = 0; j < i; j++) {
LegendrePoly &L_j = *L[j];
double S_ij = L_i.innerProduct(L_j);
REQUIRE(S_ij == Approx(0.0).margin(1.0e-12));
REQUIRE(S_ij == Catch::Approx(0.0).margin(1.0e-12));
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions tests/functions/periodify_gaussians.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* <https://mrcpp.readthedocs.io/>
*/

#include "catch.hpp"
#include "catch2/catch_all.hpp"

#include "functions/function_utils.h"
#include "functions/GaussExp.h"
Expand Down Expand Up @@ -73,7 +73,7 @@ template <int D> void testIsNarrowGaussiansMadePeriodic() {
WHEN("The gaussian is generated it is constructed, it is not periodic") {
auto gauss = GaussFunc<D>(beta, alpha, pos);
THEN("The Gaussian should be close to zero at the bondary of the unit cell") {
REQUIRE(gauss.evalf(new_pos) == Approx(0.0));
REQUIRE(gauss.evalf(new_pos) == Catch::Approx(0.0));
}
AND_WHEN("The gaussian is made periodic, it is periodic") {
auto gexp = gauss.periodify(period);
Expand All @@ -100,12 +100,12 @@ template <int D> void testIsWideGaussiansMadePeriodic() {
WHEN("The gaussian is generated it is constructed, it is not periodic") {
auto gauss = GaussFunc<D>(beta, alpha, pos);
THEN("The Gaussian should be close to zero at the bondary of the unit cell") {
REQUIRE(gauss.evalf(new_pos) != Approx(0.0));
REQUIRE(gauss.evalf(new_pos) != Catch::Approx(0.0));
}
AND_WHEN("The gaussian is made periodc, it is periodic") {
auto gexp = gauss.periodify(period);
THEN("The gaussian should have the same value at -0.2 and 1.8") {
REQUIRE(gexp.evalf(pos) == Approx(gexp.evalf(new_pos)));
REQUIRE(gexp.evalf(pos) == Catch::Approx(gexp.evalf(new_pos)));
}
}
}
Expand Down Expand Up @@ -135,12 +135,12 @@ template <int D> void testIsGaussExpMadePeriodic() {
gauss_exp.append(gauss_1);
gauss_exp.append(gauss_2);
REQUIRE(gauss_exp.size() == 2);
REQUIRE(gauss_exp.evalf(r0) != Approx(gauss_exp.evalf(r1)));
REQUIRE(gauss_exp.evalf(r0) != Catch::Approx(gauss_exp.evalf(r1)));

AND_WHEN("The gaussians are make periodic") {
auto per_exp = gauss_exp.periodify(period);
REQUIRE(per_exp.size() > 2);
REQUIRE(per_exp.evalf(r0) == Approx(per_exp.evalf(r1)));
REQUIRE(per_exp.evalf(r0) == Catch::Approx(per_exp.evalf(r1)));
}
}
}
Expand Down
Loading

0 comments on commit 5320eb4

Please sign in to comment.