catch2: download with CMake + update to recent Catch2
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// Copyright (2019-2023) Paul Scherrer Institute
|
||||
|
||||
#include <catch2/catch.hpp>
|
||||
#include <catch2/catch_all.hpp>
|
||||
#include "../common/DiffractionGeometry.h"
|
||||
#include <iostream>
|
||||
|
||||
@@ -12,8 +12,8 @@ TEST_CASE("RecipToDetector_1", "[LinearAlgebra][Coord]") {
|
||||
|
||||
auto recip = DetectorToRecip(x, pos_x, pos_y);
|
||||
auto [proj_x, proj_y] = RecipToDector(x, recip);
|
||||
REQUIRE(proj_x == Approx(pos_x));
|
||||
REQUIRE(proj_y == Approx(pos_y));
|
||||
REQUIRE(proj_x == Catch::Approx(pos_x));
|
||||
REQUIRE(proj_y == Catch::Approx(pos_y));
|
||||
REQUIRE((recip - DetectorToRecip(x, proj_x, proj_y)).Length() < 0.00000001f);
|
||||
REQUIRE(DistFromEwaldSphere(x, recip) < 4e-4);
|
||||
}
|
||||
@@ -25,8 +25,8 @@ TEST_CASE("RecipToDetector_2", "[LinearAlgebra][Coord]") {
|
||||
|
||||
auto recip = DetectorToRecip(x, pos_x, pos_y);
|
||||
auto [proj_x, proj_y] = RecipToDector(x, recip);
|
||||
REQUIRE(proj_x == Approx(pos_x));
|
||||
REQUIRE(proj_y == Approx(pos_y));
|
||||
REQUIRE(proj_x == Catch::Approx(pos_x));
|
||||
REQUIRE(proj_y == Catch::Approx(pos_y));
|
||||
REQUIRE((recip - DetectorToRecip(x, proj_x, proj_y)).Length() < 0.00000001f);
|
||||
REQUIRE(DistFromEwaldSphere(x, recip) < 4e-4);
|
||||
}
|
||||
@@ -38,8 +38,8 @@ TEST_CASE("RecipToDetector_3", "[LinearAlgebra][Coord]") {
|
||||
|
||||
auto recip = DetectorToRecip(x, pos_x, pos_y);
|
||||
auto [proj_x, proj_y] = RecipToDector(x, recip);
|
||||
REQUIRE(proj_x == Approx(pos_x));
|
||||
REQUIRE(proj_y == Approx(pos_y));
|
||||
REQUIRE(proj_x == Catch::Approx(pos_x));
|
||||
REQUIRE(proj_y == Catch::Approx(pos_y));
|
||||
REQUIRE((recip - DetectorToRecip(x, proj_x, proj_y)).Length() < 0.00000001f);
|
||||
REQUIRE(DistFromEwaldSphere(x, recip) < 4e-4);
|
||||
}
|
||||
@@ -49,9 +49,9 @@ TEST_CASE("Phi","") {
|
||||
x.DetectorDistance_mm(75).PhotonEnergy_keV(WVL_1A_IN_KEV);
|
||||
x.BeamX_pxl(1000).BeamY_pxl(1000);
|
||||
|
||||
REQUIRE(Phi(x, 2000, 1000) == Approx(0.0));
|
||||
REQUIRE(Phi(x, 1000, 2000) == Approx(M_PI_2));
|
||||
REQUIRE(Phi(x, 2000, 2000) == Approx(M_PI_4));
|
||||
REQUIRE(Phi(x, 2000, 1000) == Catch::Approx(0.0));
|
||||
REQUIRE(Phi(x, 1000, 2000) == Catch::Approx(M_PI_2));
|
||||
REQUIRE(Phi(x, 2000, 2000) == Catch::Approx(M_PI_4));
|
||||
}
|
||||
|
||||
TEST_CASE("Cos2Theta","") {
|
||||
@@ -62,7 +62,7 @@ TEST_CASE("Cos2Theta","") {
|
||||
// det distance == 1000 pixel
|
||||
// theta = 30 deg
|
||||
// tan(2 * theta) = sqrt(3)
|
||||
REQUIRE(CosTwoTheta(x, 1000, 1000 * (1.0 + sqrt(3))) == Approx(0.5f));
|
||||
REQUIRE(CosTwoTheta(x, 1000, 1000 * (1.0 + sqrt(3))) == Catch::Approx(0.5f));
|
||||
}
|
||||
|
||||
TEST_CASE("PxlToRes","") {
|
||||
@@ -72,13 +72,13 @@ TEST_CASE("PxlToRes","") {
|
||||
// sin(theta) = 1/2
|
||||
// theta = 30 deg
|
||||
// tan(2 * theta) = sqrt(3)
|
||||
REQUIRE(PxlToRes(x, 0, 1000 * sqrt(3)) == Approx(1.0));
|
||||
REQUIRE(PxlToRes(x, 0, 1000 * sqrt(3)) == Catch::Approx(1.0));
|
||||
|
||||
// sin(theta) = 1/4
|
||||
// theta = 14.47 deg
|
||||
// tan(2 * theta) = 0.55328333517
|
||||
|
||||
REQUIRE(PxlToRes(x, 1000 * 0.55328333517 * cosf(1), 1000 * 0.55328333517 * sinf(1)) == Approx(2.0));
|
||||
REQUIRE(PxlToRes(x, 1000 * 0.55328333517 * cosf(1), 1000 * 0.55328333517 * sinf(1)) == Catch::Approx(2.0));
|
||||
}
|
||||
|
||||
TEST_CASE("ResToPxl","") {
|
||||
@@ -88,12 +88,12 @@ TEST_CASE("ResToPxl","") {
|
||||
// sin(theta) = 1/2
|
||||
// theta = 30 deg
|
||||
// tan(2 * theta) = sqrt(3)
|
||||
REQUIRE(ResToPxl(x, 1.0) == Approx(1000 * sqrt(3)));
|
||||
REQUIRE(ResToPxl(x, 1.0) == Catch::Approx(1000 * sqrt(3)));
|
||||
|
||||
// sin(theta) = 1/4
|
||||
// theta = 14.47 deg
|
||||
// tan(2 * theta) = 0.55328333517
|
||||
REQUIRE(ResToPxl(x, 2.0) == Approx(1000 * 0.55328333517));
|
||||
REQUIRE(ResToPxl(x, 2.0) == Catch::Approx(1000 * 0.55328333517));
|
||||
}
|
||||
|
||||
TEST_CASE("SolidAngleCorrection","") {
|
||||
@@ -102,12 +102,12 @@ TEST_CASE("SolidAngleCorrection","") {
|
||||
x.BeamX_pxl(1000).BeamY_pxl(1000).DetectorDistance_mm(75);
|
||||
|
||||
REQUIRE(CalcAzIntSolidAngleCorr(x, 0.0) == 1.0f);
|
||||
REQUIRE(CalcAzIntSolidAngleCorr(x, 2 * M_PI) == Approx(0.5f * 0.5f * 0.5f));
|
||||
REQUIRE(CalcAzIntSolidAngleCorr(x, 2 * M_PI) == Catch::Approx(0.5f * 0.5f * 0.5f));
|
||||
|
||||
// theta = 30 deg
|
||||
// cos (2 * theta) = 1/2
|
||||
REQUIRE(CalcAzIntSolidAngleCorr(x, 1000, 1000) == 1.0f);
|
||||
REQUIRE(CalcAzIntSolidAngleCorr(x, 1000 * (1.0 + sqrt(3)), 1000) == Approx(0.5f * 0.5f * 0.5f));
|
||||
REQUIRE(CalcAzIntSolidAngleCorr(x, 1000 * (1.0 + sqrt(3)), 1000) == Catch::Approx(0.5f * 0.5f * 0.5f));
|
||||
}
|
||||
|
||||
TEST_CASE("PolarizationCorrection","") {
|
||||
@@ -117,17 +117,17 @@ TEST_CASE("PolarizationCorrection","") {
|
||||
|
||||
// Circular polarization 0.5*(1+cos(2theta)^2)
|
||||
x.PolarizationFactor(0);
|
||||
REQUIRE(CalcAzIntPolarizationCorr(x, 1000 * (1.0 + sqrt(3)), 1000) == Approx(0.5f * (1 + 0.5f * 0.5f)));
|
||||
REQUIRE(CalcAzIntPolarizationCorr(x, 1000, 1000 * (1.0 + sqrt(3))) == Approx(0.5f * (1 + 0.5f * 0.5f)));
|
||||
REQUIRE(CalcAzIntPolarizationCorr(x, 1000 * (1.0 + sqrt(3)), 1000) == Catch::Approx(0.5f * (1 + 0.5f * 0.5f)));
|
||||
REQUIRE(CalcAzIntPolarizationCorr(x, 1000, 1000 * (1.0 + sqrt(3))) == Catch::Approx(0.5f * (1 + 0.5f * 0.5f)));
|
||||
|
||||
// Horizontal polarization
|
||||
x.PolarizationFactor(1);
|
||||
|
||||
// No correction in vertical direction
|
||||
REQUIRE(CalcAzIntPolarizationCorr(x, 1000, 1000 * (1.0 + sqrt(3))) == Approx(1.0f));
|
||||
REQUIRE(CalcAzIntPolarizationCorr(x, 1000, 1000 * (1.0 - sqrt(3))) == Approx(1.0f));
|
||||
REQUIRE(CalcAzIntPolarizationCorr(x, 1000, 1000 * (1.0 + sqrt(3))) == Catch::Approx(1.0f));
|
||||
REQUIRE(CalcAzIntPolarizationCorr(x, 1000, 1000 * (1.0 - sqrt(3))) == Catch::Approx(1.0f));
|
||||
|
||||
// cos(2*theta)^2 in horizontal direction
|
||||
REQUIRE(CalcAzIntPolarizationCorr(x, 1000 * (1.0 + sqrt(3)), 1000) == Approx(0.5f * 0.5f));
|
||||
REQUIRE(CalcAzIntPolarizationCorr(x, 1000 * (1.0 - sqrt(3)), 1000) == Approx(0.5f * 0.5f));
|
||||
REQUIRE(CalcAzIntPolarizationCorr(x, 1000 * (1.0 + sqrt(3)), 1000) == Catch::Approx(0.5f * 0.5f));
|
||||
REQUIRE(CalcAzIntPolarizationCorr(x, 1000 * (1.0 - sqrt(3)), 1000) == Catch::Approx(0.5f * 0.5f));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user