40 lines
973 B
C++
40 lines
973 B
C++
// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include <catch2/catch_all.hpp>
|
|
|
|
#include "../common/hkl_key.h"
|
|
|
|
TEST_CASE("HKL key round-trip", "[hkl_key]") {
|
|
struct Case { int64_t h, k, l; };
|
|
const Case cases[] = {
|
|
{0, 0, 0},
|
|
{1, -2, 3},
|
|
{-511, 0, 511},
|
|
{512 - 1, -(512 - 1), 7},
|
|
{-128, 255, -7}
|
|
};
|
|
|
|
for (const auto& c : cases) {
|
|
const uint64_t key = hkl_key(c.h, c.k, c.l);
|
|
int64_t h = 0, k = 0, l = 0;
|
|
hkl_from_key(key, h, k, l);
|
|
|
|
CHECK(h == c.h);
|
|
CHECK(k == c.k);
|
|
CHECK(l == c.l);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("HKL key boundaries", "[hkl_key]") {
|
|
const int64_t min = -512;
|
|
const int64_t max = 511;
|
|
|
|
const uint64_t key = hkl_key(min, 0, max);
|
|
int64_t h = 0, k = 0, l = 0;
|
|
hkl_from_key(key, h, k, l);
|
|
|
|
CHECK(h == min);
|
|
CHECK(k == 0);
|
|
CHECK(l == max);
|
|
} |