89 lines
3.2 KiB
C++
89 lines
3.2 KiB
C++
// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include <catch2/catch_all.hpp>
|
|
|
|
#include "../common/UnitCell.h"
|
|
|
|
#include <limits>
|
|
#include <vector>
|
|
|
|
TEST_CASE("UnitCell_is_finite") {
|
|
UnitCell cell{50, 60, 70, 90, 90, 120};
|
|
CHECK(cell.is_finite());
|
|
|
|
cell.a = std::numeric_limits<float>::quiet_NaN();
|
|
CHECK_FALSE(cell.is_finite());
|
|
|
|
cell = UnitCell{50, 60, 70, 90, 90, 120};
|
|
cell.beta = std::numeric_limits<float>::infinity();
|
|
CHECK_FALSE(cell.is_finite());
|
|
|
|
cell = UnitCell{50, 60, 70, 90, -std::numeric_limits<float>::infinity(), 120};
|
|
CHECK_FALSE(cell.is_finite());
|
|
}
|
|
|
|
TEST_CASE("UnitCell_is_close_accepts_cells_within_tolerance") {
|
|
const UnitCell ref{100, 120, 150, 90, 95, 120};
|
|
|
|
CHECK(UnitCell{100, 120, 150, 90, 95, 120}.is_close(ref, 0.05f, 5.0f));
|
|
|
|
CHECK(UnitCell{105, 126, 157.5, 95, 100, 125}.is_close(ref, 0.05f, 5.0f));
|
|
CHECK(UnitCell{95, 114, 142.5, 85, 90, 115}.is_close(ref, 0.05f, 5.0f));
|
|
}
|
|
|
|
TEST_CASE("UnitCell_is_close_rejects_length_outliers") {
|
|
const UnitCell ref{100, 120, 150, 90, 95, 120};
|
|
|
|
CHECK_FALSE(UnitCell{105.1f, 120, 150, 90, 95, 120}.is_close(ref, 0.05f, 5.0f));
|
|
CHECK_FALSE(UnitCell{100, 126.1f, 150, 90, 95, 120}.is_close(ref, 0.05f, 5.0f));
|
|
CHECK_FALSE(UnitCell{100, 120, 157.6f, 90, 95, 120}.is_close(ref, 0.05f, 5.0f));
|
|
|
|
CHECK_FALSE(UnitCell{94.9f, 120, 150, 90, 95, 120}.is_close(ref, 0.05f, 5.0f));
|
|
CHECK_FALSE(UnitCell{100, 113.9f, 150, 90, 95, 120}.is_close(ref, 0.05f, 5.0f));
|
|
CHECK_FALSE(UnitCell{100, 120, 142.4f, 90, 95, 120}.is_close(ref, 0.05f, 5.0f));
|
|
}
|
|
|
|
TEST_CASE("UnitCell_is_close_rejects_angle_outliers") {
|
|
const UnitCell ref{100, 120, 150, 90, 95, 120};
|
|
|
|
CHECK_FALSE(UnitCell{100, 120, 150, 95.1f, 95, 120}.is_close(ref, 0.05f, 5.0f));
|
|
CHECK_FALSE(UnitCell{100, 120, 150, 90, 100.1f, 120}.is_close(ref, 0.05f, 5.0f));
|
|
CHECK_FALSE(UnitCell{100, 120, 150, 90, 95, 125.1f}.is_close(ref, 0.05f, 5.0f));
|
|
|
|
CHECK_FALSE(UnitCell{100, 120, 150, 84.9f, 95, 120}.is_close(ref, 0.05f, 5.0f));
|
|
CHECK_FALSE(UnitCell{100, 120, 150, 90, 89.9f, 120}.is_close(ref, 0.05f, 5.0f));
|
|
CHECK_FALSE(UnitCell{100, 120, 150, 90, 95, 114.9f}.is_close(ref, 0.05f, 5.0f));
|
|
}
|
|
|
|
TEST_CASE("UnitCell_is_close_rejects_non_finite_cells") {
|
|
const UnitCell ref{100, 120, 150, 90, 95, 120};
|
|
|
|
UnitCell cell{100, 120, 150, 90, 95, 120};
|
|
cell.a = std::numeric_limits<float>::quiet_NaN();
|
|
CHECK_FALSE(cell.is_close(ref, 0.05f, 5.0f));
|
|
|
|
UnitCell bad_ref{100, 120, 150, 90, 95, 120};
|
|
bad_ref.gamma = std::numeric_limits<float>::infinity();
|
|
CHECK_FALSE(ref.is_close(bad_ref, 0.05f, 5.0f));
|
|
}
|
|
|
|
TEST_CASE("UnitCell_MeanUnitCell") {
|
|
const std::vector<UnitCell> cells{
|
|
{100, 120, 150, 90, 95, 120},
|
|
{102, 122, 152, 92, 97, 122},
|
|
{98, 118, 148, 88, 93, 118}
|
|
};
|
|
|
|
const auto mean = MeanUnitCell(cells);
|
|
REQUIRE(mean.has_value());
|
|
|
|
CHECK(mean->a == Catch::Approx(100));
|
|
CHECK(mean->b == Catch::Approx(120));
|
|
CHECK(mean->c == Catch::Approx(150));
|
|
CHECK(mean->alpha == Catch::Approx(90));
|
|
CHECK(mean->beta == Catch::Approx(95));
|
|
CHECK(mean->gamma == Catch::Approx(120));
|
|
|
|
CHECK_FALSE(MeanUnitCell({}).has_value());
|
|
} |