mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2026-03-25 19:22:47 +01:00
clang-format
This commit is contained in:
@@ -58,10 +58,8 @@ class ClusterFinderMTWrapper
|
||||
size_t m_sink_size() const { return this->m_sink.sizeGuess(); }
|
||||
};
|
||||
|
||||
|
||||
TEST_CASE("multithreaded cluster finder", "[.with-data]") {
|
||||
auto fpath =
|
||||
test_data_path() / "raw/moench03/cu_half_speed_master_4.json";
|
||||
auto fpath = test_data_path() / "raw/moench03/cu_half_speed_master_4.json";
|
||||
|
||||
REQUIRE(std::filesystem::exists(fpath));
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ using aare::Cluster;
|
||||
using aare::ClusterVector;
|
||||
using C1 = Cluster<int32_t, 2, 2>;
|
||||
|
||||
|
||||
TEST_CASE("A newly created ClusterVector is empty") {
|
||||
ClusterVector<C1> cv(4);
|
||||
REQUIRE(cv.empty());
|
||||
@@ -174,7 +173,8 @@ TEST_CASE("Push back more than initial capacity") {
|
||||
REQUIRE(initial_data != cv.data());
|
||||
}
|
||||
|
||||
TEST_CASE("Concatenate two cluster vectors where the first has enough capacity") {
|
||||
TEST_CASE(
|
||||
"Concatenate two cluster vectors where the first has enough capacity") {
|
||||
ClusterVector<Cluster<int32_t, 2, 2>> cv1(12);
|
||||
Cluster<int32_t, 2, 2> c1 = {1, 2, {3, 4, 5, 6}};
|
||||
cv1.push_back(c1);
|
||||
|
||||
@@ -5,9 +5,8 @@
|
||||
namespace aare {
|
||||
|
||||
CtbRawFile::CtbRawFile(const std::filesystem::path &fname) : m_master(fname) {
|
||||
if( (m_master.detector_type() != DetectorType::ChipTestBoard) &&
|
||||
(m_master.detector_type() != DetectorType::Xilinx_ChipTestBoard) )
|
||||
{
|
||||
if ((m_master.detector_type() != DetectorType::ChipTestBoard) &&
|
||||
(m_master.detector_type() != DetectorType::Xilinx_ChipTestBoard)) {
|
||||
throw std::runtime_error(LOCATION + "Not a Ctb file");
|
||||
}
|
||||
|
||||
@@ -15,8 +14,9 @@ CtbRawFile::CtbRawFile(const std::filesystem::path &fname) : m_master(fname) {
|
||||
|
||||
// open the first subfile
|
||||
m_file.open(m_master.data_fname(0, 0), std::ios::binary);
|
||||
if(!m_file)
|
||||
throw std::runtime_error(LOCATION + "Could not open: " + m_master.data_fname(0, 0).string());
|
||||
if (!m_file)
|
||||
throw std::runtime_error(
|
||||
LOCATION + "Could not open: " + m_master.data_fname(0, 0).string());
|
||||
}
|
||||
|
||||
void CtbRawFile::read_into(std::byte *image_buf, DetectorHeader *header) {
|
||||
@@ -63,7 +63,6 @@ void CtbRawFile::find_subfiles() {
|
||||
// we can semi safely assume that there is only one module for CTB
|
||||
while (std::filesystem::exists(m_master.data_fname(0, m_num_subfiles)))
|
||||
m_num_subfiles++;
|
||||
|
||||
}
|
||||
|
||||
void CtbRawFile::open_data_file(size_t subfile_index) {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
|
||||
#include "aare/Dtype.hpp"
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
|
||||
@@ -71,7 +71,8 @@ TEST_CASE("Seek in a JungfrauDataFile", "[.with-data]") {
|
||||
REQUIRE_THROWS(f.seek(86356)); // out of range
|
||||
}
|
||||
|
||||
TEST_CASE("Open a Jungfrau data file with non zero file index", "[.with-data]") {
|
||||
TEST_CASE("Open a Jungfrau data file with non zero file index",
|
||||
"[.with-data]") {
|
||||
|
||||
auto fpath = test_data_path() / "dat" / "AldoJF65k_000003.dat";
|
||||
REQUIRE(std::filesystem::exists(fpath));
|
||||
|
||||
@@ -105,43 +105,43 @@ TEST_CASE("Indexing of a 3D image") {
|
||||
REQUIRE(img(2, 3, 1) == 23);
|
||||
}
|
||||
|
||||
TEST_CASE("Access to data using a pointer"){
|
||||
TEST_CASE("Access to data using a pointer") {
|
||||
// This pattern is discouraged but sometimes useful
|
||||
NDArray<int,2> img{{4,5},0};
|
||||
int* data_ptr = img.data();
|
||||
for(int i=0; i < img.size(); ++i){
|
||||
data_ptr[i] = i*2;
|
||||
NDArray<int, 2> img{{4, 5}, 0};
|
||||
int *data_ptr = img.data();
|
||||
for (int i = 0; i < img.size(); ++i) {
|
||||
data_ptr[i] = i * 2;
|
||||
}
|
||||
|
||||
// Cross check using operator[]
|
||||
for(int i=0; i < img.size(); ++i){
|
||||
REQUIRE(img[i] == i*2);
|
||||
for (int i = 0; i < img.size(); ++i) {
|
||||
REQUIRE(img[i] == i * 2);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Access to data using a pointer for a const NDArray"){
|
||||
TEST_CASE("Access to data using a pointer for a const NDArray") {
|
||||
// This pattern is discouraged but sometimes useful
|
||||
|
||||
// Using a lambda to create a const NDArray with known data
|
||||
const NDArray<int,2> arr = [](){
|
||||
NDArray<int,2> img{{4,5},0};
|
||||
int* data_ptr = img.data();
|
||||
for(int i=0; i < img.size(); ++i){
|
||||
data_ptr[i] = i*3;
|
||||
const NDArray<int, 2> arr = []() {
|
||||
NDArray<int, 2> img{{4, 5}, 0};
|
||||
int *data_ptr = img.data();
|
||||
for (int i = 0; i < img.size(); ++i) {
|
||||
data_ptr[i] = i * 3;
|
||||
}
|
||||
return img;
|
||||
}();
|
||||
|
||||
// Cross check using data() pointer, if compiles we can get a const pointer
|
||||
const int* const_data_ptr = arr.data();
|
||||
for(int i=0; i < arr.size(); ++i){
|
||||
REQUIRE(const_data_ptr[i] == i*3);
|
||||
const int *const_data_ptr = arr.data();
|
||||
for (int i = 0; i < arr.size(); ++i) {
|
||||
REQUIRE(const_data_ptr[i] == i * 3);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Use *buffer"){
|
||||
// Another useful but discouraged pattern. But can be useful when getting data
|
||||
// from external sources
|
||||
TEST_CASE("Use *buffer") {
|
||||
// Another useful but discouraged pattern. But can be useful when getting
|
||||
// data from external sources
|
||||
Shape<2> shape{{4, 5}};
|
||||
NDArray<int, 2> src(shape);
|
||||
NDArray<int, 2> dst(shape);
|
||||
@@ -491,64 +491,60 @@ TEST_CASE("Construct an NDArray from an std::array") {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Copy construct an NDArray"){
|
||||
NDArray<int,2> a({{3,4}},0);
|
||||
a(1,1) = 42;
|
||||
a(2,3) = 84;
|
||||
TEST_CASE("Copy construct an NDArray") {
|
||||
NDArray<int, 2> a({{3, 4}}, 0);
|
||||
a(1, 1) = 42;
|
||||
a(2, 3) = 84;
|
||||
|
||||
NDArray<int,2> b(a);
|
||||
REQUIRE(b.shape() == Shape<2>{3,4});
|
||||
NDArray<int, 2> b(a);
|
||||
REQUIRE(b.shape() == Shape<2>{3, 4});
|
||||
REQUIRE(b.size() == 12);
|
||||
REQUIRE(b(1,1) == 42);
|
||||
REQUIRE(b(2,3) == 84);
|
||||
REQUIRE(b(1, 1) == 42);
|
||||
REQUIRE(b(2, 3) == 84);
|
||||
|
||||
// Modifying b should not affect a
|
||||
b(1,1) = 7;
|
||||
REQUIRE(a(1,1) == 42);
|
||||
b(1, 1) = 7;
|
||||
REQUIRE(a(1, 1) == 42);
|
||||
|
||||
REQUIRE(a.data() != b.data());
|
||||
}
|
||||
|
||||
TEST_CASE("Move construct an NDArray") {
|
||||
NDArray<int, 2> a({{3, 4}}, 0);
|
||||
a(1, 1) = 42;
|
||||
a(2, 3) = 84;
|
||||
|
||||
TEST_CASE("Move construct an NDArray"){
|
||||
NDArray<int,2> a({{3,4}},0);
|
||||
a(1,1) = 42;
|
||||
a(2,3) = 84;
|
||||
|
||||
NDArray<int,2> b(std::move(a));
|
||||
REQUIRE(b.shape() == Shape<2>{3,4});
|
||||
NDArray<int, 2> b(std::move(a));
|
||||
REQUIRE(b.shape() == Shape<2>{3, 4});
|
||||
REQUIRE(b.size() == 12);
|
||||
REQUIRE(b(1,1) == 42);
|
||||
REQUIRE(b(2,3) == 84);
|
||||
REQUIRE(b(1, 1) == 42);
|
||||
REQUIRE(b(2, 3) == 84);
|
||||
|
||||
// The moved from object should be in a unspecified but valid state.
|
||||
// This means original array pointer should be null, and size zero
|
||||
REQUIRE(a.size() == 0);
|
||||
REQUIRE(a.shape() == Shape<2>{0,0});
|
||||
REQUIRE(a.shape() == Shape<2>{0, 0});
|
||||
REQUIRE(a.data() == nullptr);
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("Move construct from an array with Ndim + 1") {
|
||||
NDArray<int, 3> a({{1,2,2}}, 0);
|
||||
NDArray<int, 3> a({{1, 2, 2}}, 0);
|
||||
a(0, 0, 0) = 1;
|
||||
a(0, 0, 1) = 2;
|
||||
a(0, 1, 0) = 3;
|
||||
a(0, 1, 1) = 4;
|
||||
|
||||
|
||||
NDArray<int, 2> b(std::move(a));
|
||||
REQUIRE(b.shape() == Shape<2>{2,2});
|
||||
REQUIRE(b.shape() == Shape<2>{2, 2});
|
||||
REQUIRE(b.size() == 4);
|
||||
REQUIRE(b(0, 0) == 1);
|
||||
REQUIRE(b(0, 1) == 2);
|
||||
REQUIRE(b(1, 0) == 3);
|
||||
REQUIRE(b(1, 1) == 4);
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("Move construct from an array with Ndim + 1 throws on size mismatch") {
|
||||
NDArray<int, 3> a({{2,2,2}}, 0);
|
||||
TEST_CASE(
|
||||
"Move construct from an array with Ndim + 1 throws on size mismatch") {
|
||||
NDArray<int, 3> a({{2, 2, 2}}, 0);
|
||||
REQUIRE_THROWS(NDArray<int, 2>(std::move(a)));
|
||||
}
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
#include "aare/NDView.hpp"
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
#include <iostream>
|
||||
#include <numeric>
|
||||
#include <vector>
|
||||
#include <cstddef>
|
||||
|
||||
using aare::NDView;
|
||||
using aare::Shape;
|
||||
@@ -23,7 +23,6 @@ TEST_CASE("Element reference 1D") {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("Assign elements through () and []") {
|
||||
std::vector<int> vec;
|
||||
for (int i = 0; i != 10; ++i) {
|
||||
@@ -31,11 +30,10 @@ TEST_CASE("Assign elements through () and []") {
|
||||
}
|
||||
NDView<int, 1> data(vec.data(), Shape<1>{10});
|
||||
REQUIRE(vec.size() == static_cast<size_t>(data.size()));
|
||||
|
||||
|
||||
data[3] = 187;
|
||||
data(4) = 512;
|
||||
|
||||
|
||||
REQUIRE(data(0) == 0);
|
||||
REQUIRE(data[0] == 0);
|
||||
REQUIRE(data(1) == 1);
|
||||
@@ -56,8 +54,6 @@ TEST_CASE("Assign elements through () and []") {
|
||||
REQUIRE(data[8] == 8);
|
||||
REQUIRE(data(9) == 9);
|
||||
REQUIRE(data[9] == 9);
|
||||
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("Element reference 1D with a const NDView") {
|
||||
@@ -73,7 +69,6 @@ TEST_CASE("Element reference 1D with a const NDView") {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("Element reference 2D") {
|
||||
std::vector<int> vec(12);
|
||||
std::iota(vec.begin(), vec.end(), 0);
|
||||
@@ -190,8 +185,6 @@ TEST_CASE("iterators") {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST_CASE("divide with another NDView") {
|
||||
std::vector<int> vec0{9, 12, 3};
|
||||
std::vector<int> vec1{3, 2, 1};
|
||||
@@ -229,7 +222,7 @@ TEST_CASE("compare two views") {
|
||||
REQUIRE((view1 == view2));
|
||||
}
|
||||
|
||||
TEST_CASE("Compare two views with different size"){
|
||||
TEST_CASE("Compare two views with different size") {
|
||||
std::vector<int> vec1(12);
|
||||
std::iota(vec1.begin(), vec1.end(), 0);
|
||||
NDView<int, 2> view1(vec1.data(), Shape<2>{3, 4});
|
||||
@@ -241,7 +234,7 @@ TEST_CASE("Compare two views with different size"){
|
||||
REQUIRE_FALSE(view1 == view2);
|
||||
}
|
||||
|
||||
TEST_CASE("Compare two views with same size but different shape"){
|
||||
TEST_CASE("Compare two views with same size but different shape") {
|
||||
std::vector<int> vec1(12);
|
||||
std::iota(vec1.begin(), vec1.end(), 0);
|
||||
NDView<int, 2> view1(vec1.data(), Shape<2>{3, 4});
|
||||
@@ -262,10 +255,9 @@ TEST_CASE("Create a view over a vector") {
|
||||
REQUIRE(v[11] == 11);
|
||||
}
|
||||
|
||||
TEST_CASE("NDView over byte"){
|
||||
TEST_CASE("NDView over byte") {
|
||||
std::vector<std::byte> buf(5);
|
||||
auto v = aare::make_view(buf);
|
||||
REQUIRE(v.shape()[0] == 5);
|
||||
REQUIRE(v[0] == std::byte{0});
|
||||
|
||||
}
|
||||
@@ -105,8 +105,8 @@ NDArray<ssize_t, 2> GenerateEigerFlipRowsPixelMap() {
|
||||
}
|
||||
|
||||
NDArray<ssize_t, 2> GenerateMH02SingleCounterPixelMap() {
|
||||
// This is the pixel map for a single counter Matterhorn02, i.e. 48x48 pixels.
|
||||
// Data is read from two transceivers in blocks of 4 pixels.
|
||||
// This is the pixel map for a single counter Matterhorn02, i.e. 48x48
|
||||
// pixels. Data is read from two transceivers in blocks of 4 pixels.
|
||||
NDArray<ssize_t, 2> order_map({48, 48});
|
||||
size_t offset = 0;
|
||||
size_t nSamples = 4;
|
||||
@@ -131,8 +131,7 @@ NDArray<ssize_t, 3> GenerateMH02FourCounterPixelMap() {
|
||||
for (int row = 0; row < 48; row++) {
|
||||
for (int col = 0; col < 48; col++) {
|
||||
order_map(counter, row, col) =
|
||||
single_counter_map(row, col) +
|
||||
counter * 48 * 48;
|
||||
single_counter_map(row, col) + counter * 48 * 48;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,6 @@ Frame RawFile::read_roi(const size_t roi_index) {
|
||||
return get_frame(m_current_frame++, roi_index);
|
||||
}
|
||||
|
||||
|
||||
std::vector<Frame> RawFile::read_rois() {
|
||||
|
||||
if (!m_master.rois()) {
|
||||
@@ -83,8 +82,6 @@ std::vector<Frame> RawFile::read_rois() {
|
||||
return frames;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Frame RawFile::read_frame() {
|
||||
if (m_master.rois().has_value() && m_master.rois()->size() > 1) {
|
||||
throw std::runtime_error(LOCATION +
|
||||
@@ -473,7 +470,7 @@ std::vector<Frame> RawFile::read_n(size_t n_frames) {
|
||||
}
|
||||
|
||||
std::vector<Frame> RawFile::read_n_with_roi(const size_t n_frames,
|
||||
const size_t roi_index) {
|
||||
const size_t roi_index) {
|
||||
if (roi_index >= num_rois()) {
|
||||
throw std::runtime_error(LOCATION + "ROI index out of range.");
|
||||
}
|
||||
|
||||
@@ -255,7 +255,7 @@ void RawMasterFile::parse_json(std::istream &is) {
|
||||
// TODO! Not valid for CTB but not changing api right now!
|
||||
// Not all detectors write the bitdepth but in case
|
||||
// its not there it is 16
|
||||
if(j.contains("Dynamic Range") && j["Dynamic Range"].is_number()){
|
||||
if (j.contains("Dynamic Range") && j["Dynamic Range"].is_number()) {
|
||||
m_bitdepth = j["Dynamic Range"];
|
||||
} else {
|
||||
m_bitdepth = 16;
|
||||
|
||||
@@ -398,7 +398,7 @@ TEST_CASE("Parse EIGER 7.2 master from string stream") {
|
||||
REQUIRE(f.timing_mode() == TimingMode::Auto);
|
||||
REQUIRE(f.geometry().col == 2);
|
||||
REQUIRE(f.geometry().row == 2);
|
||||
|
||||
|
||||
REQUIRE(f.image_size_in_bytes() == 524288);
|
||||
REQUIRE(f.pixels_x() == 512);
|
||||
REQUIRE(f.pixels_y() == 256);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
|
||||
#include <aare/algorithm.hpp>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
#include "aare/decode.hpp"
|
||||
#include <fmt/format.h>
|
||||
#include <cmath>
|
||||
#include <fmt/format.h>
|
||||
namespace aare {
|
||||
|
||||
uint16_t adc_sar_05_06_07_08decode64to16(uint64_t input) {
|
||||
@@ -24,7 +24,7 @@ uint16_t adc_sar_05_06_07_08decode64to16(uint64_t input) {
|
||||
}
|
||||
|
||||
void adc_sar_05_06_07_08decode64to16(NDView<uint64_t, 2> input,
|
||||
NDView<uint16_t, 2> output) {
|
||||
NDView<uint16_t, 2> output) {
|
||||
if (input.shape() != output.shape()) {
|
||||
throw std::invalid_argument(LOCATION +
|
||||
" input and output shapes must match");
|
||||
@@ -139,49 +139,50 @@ void apply_custom_weights(NDView<uint16_t, 1> input, NDView<double, 1> output,
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t mask32to24bits(uint32_t input, BitOffset offset){
|
||||
uint32_t mask32to24bits(uint32_t input, BitOffset offset) {
|
||||
constexpr uint32_t mask24bits{0xFFFFFF};
|
||||
return (input >> offset.value()) & mask24bits;
|
||||
}
|
||||
|
||||
void expand24to32bit(NDView<uint8_t,1> input, NDView<uint32_t,1> output, BitOffset bit_offset){
|
||||
void expand24to32bit(NDView<uint8_t, 1> input, NDView<uint32_t, 1> output,
|
||||
BitOffset bit_offset) {
|
||||
|
||||
ssize_t bytes_per_channel = 3; //24bit
|
||||
ssize_t min_input_size = output.size()*bytes_per_channel;
|
||||
ssize_t bytes_per_channel = 3; // 24bit
|
||||
ssize_t min_input_size = output.size() * bytes_per_channel;
|
||||
|
||||
//if we have an offset we need one more byte in the input data
|
||||
// if we have an offset we need one more byte in the input data
|
||||
if (bit_offset.value())
|
||||
min_input_size += 1;
|
||||
min_input_size += 1;
|
||||
|
||||
if (input.size() < min_input_size)
|
||||
throw std::runtime_error(fmt::format(
|
||||
"{} Mismatch between input and output size. Output "
|
||||
"size of {} with bit offset {} requires an input of at least {} "
|
||||
"bytes. Called with input size: {} output size: {}",
|
||||
LOCATION, output.size(), bit_offset.value(), min_input_size, input.size(), output.size()));
|
||||
LOCATION, output.size(), bit_offset.value(), min_input_size,
|
||||
input.size(), output.size()));
|
||||
|
||||
auto* in = input.data();
|
||||
auto *in = input.data();
|
||||
|
||||
if(bit_offset.value()){
|
||||
//If there is a bit_offset we copy 4 bytes and then
|
||||
//mask out the correct ones.
|
||||
for (auto& v : output){
|
||||
if (bit_offset.value()) {
|
||||
// If there is a bit_offset we copy 4 bytes and then
|
||||
// mask out the correct ones.
|
||||
for (auto &v : output) {
|
||||
uint32_t val{};
|
||||
std::memcpy(&val, in, sizeof(val));
|
||||
v = mask32to24bits(val, bit_offset);
|
||||
in += bytes_per_channel;
|
||||
}
|
||||
}else{
|
||||
//If there is no offset we can directly copy the bits
|
||||
//without masking
|
||||
for (auto& v : output){
|
||||
}
|
||||
} else {
|
||||
// If there is no offset we can directly copy the bits
|
||||
// without masking
|
||||
for (auto &v : output) {
|
||||
uint32_t val{};
|
||||
std::memcpy(&val, in, 3);
|
||||
v = val;
|
||||
in += bytes_per_channel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace aare
|
||||
|
||||
@@ -75,35 +75,32 @@ TEST_CASE("test_apply_custom_weights") {
|
||||
CHECK_THAT(output, WithinAbs(6.34, 0.001));
|
||||
}
|
||||
|
||||
TEST_CASE("Mask 32 bit unsigned integer to 24 bit"){
|
||||
//any number less than 2**24 (16777216) should be the same
|
||||
CHECK(aare::mask32to24bits(0)==0);
|
||||
CHECK(aare::mask32to24bits(19)==19);
|
||||
CHECK(aare::mask32to24bits(29875)==29875);
|
||||
CHECK(aare::mask32to24bits(1092177)==1092177);
|
||||
CHECK(aare::mask32to24bits(0xFFFF)==0xFFFF);
|
||||
CHECK(aare::mask32to24bits(0xFFFFFFFF)==0xFFFFFF);
|
||||
TEST_CASE("Mask 32 bit unsigned integer to 24 bit") {
|
||||
// any number less than 2**24 (16777216) should be the same
|
||||
CHECK(aare::mask32to24bits(0) == 0);
|
||||
CHECK(aare::mask32to24bits(19) == 19);
|
||||
CHECK(aare::mask32to24bits(29875) == 29875);
|
||||
CHECK(aare::mask32to24bits(1092177) == 1092177);
|
||||
CHECK(aare::mask32to24bits(0xFFFF) == 0xFFFF);
|
||||
CHECK(aare::mask32to24bits(0xFFFFFFFF) == 0xFFFFFF);
|
||||
|
||||
// Offset specifies that the should ignore 0-7 bits
|
||||
// at the start
|
||||
CHECK(aare::mask32to24bits(0xFFFF, BitOffset(4))==0xFFF);
|
||||
CHECK(aare::mask32to24bits(0xFF0000d9)==0xd9);
|
||||
CHECK(aare::mask32to24bits(0xFF000d9F, BitOffset(4))==0xF000d9);
|
||||
CHECK(aare::mask32to24bits(16777217)==1);
|
||||
CHECK(aare::mask32to24bits(15,BitOffset(7))==0);
|
||||
|
||||
//Highest bit set to 1 should just be excluded
|
||||
//lowest 4 bits set to 1
|
||||
CHECK(aare::mask32to24bits(0x8000000f,BitOffset(7))==0);
|
||||
|
||||
CHECK(aare::mask32to24bits(0xFFFF, BitOffset(4)) == 0xFFF);
|
||||
CHECK(aare::mask32to24bits(0xFF0000d9) == 0xd9);
|
||||
CHECK(aare::mask32to24bits(0xFF000d9F, BitOffset(4)) == 0xF000d9);
|
||||
CHECK(aare::mask32to24bits(16777217) == 1);
|
||||
CHECK(aare::mask32to24bits(15, BitOffset(7)) == 0);
|
||||
|
||||
// Highest bit set to 1 should just be excluded
|
||||
// lowest 4 bits set to 1
|
||||
CHECK(aare::mask32to24bits(0x8000000f, BitOffset(7)) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("Expand container with 24 bit data to 32"){
|
||||
TEST_CASE("Expand container with 24 bit data to 32") {
|
||||
{
|
||||
uint8_t buffer[] = {
|
||||
0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
|
||||
aare::NDView<uint8_t, 1> input(&buffer[0], {9});
|
||||
@@ -116,9 +113,7 @@ TEST_CASE("Expand container with 24 bit data to 32"){
|
||||
}
|
||||
{
|
||||
uint8_t buffer[] = {
|
||||
0x0F, 0x00, 0x00,
|
||||
0xFF, 0x00, 0x00,
|
||||
0xFF, 0xFF, 0xFF,
|
||||
0x0F, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF,
|
||||
};
|
||||
|
||||
aare::NDView<uint8_t, 1> input(&buffer[0], {9});
|
||||
@@ -131,9 +126,7 @@ TEST_CASE("Expand container with 24 bit data to 32"){
|
||||
}
|
||||
{
|
||||
uint8_t buffer[] = {
|
||||
0x00, 0x00, 0xFF,
|
||||
0xFF, 0xFF, 0x00,
|
||||
0x00, 0xFF, 0x00,
|
||||
0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0x00,
|
||||
};
|
||||
|
||||
aare::NDView<uint8_t, 1> input(&buffer[0], {9});
|
||||
@@ -147,20 +140,16 @@ TEST_CASE("Expand container with 24 bit data to 32"){
|
||||
REQUIRE_THROWS(aare::expand24to32bit(input, out.view(), BitOffset(4)));
|
||||
}
|
||||
{
|
||||
//For use with offset we need an extra byte
|
||||
uint8_t buffer[] = {
|
||||
0x00, 0x00, 0xFF,
|
||||
0xFF, 0xFF, 0x00,
|
||||
0x00, 0xFF, 0x00, 0x00
|
||||
};
|
||||
// For use with offset we need an extra byte
|
||||
uint8_t buffer[] = {0x00, 0x00, 0xFF, 0xFF, 0xFF,
|
||||
0x00, 0x00, 0xFF, 0x00, 0x00};
|
||||
|
||||
aare::NDView<uint8_t, 1> input(&buffer[0], {10});
|
||||
aare::NDArray<uint32_t, 1> out({3}); //still output.size == 3
|
||||
aare::NDArray<uint32_t, 1> out({3}); // still output.size == 3
|
||||
aare::expand24to32bit(input, out.view(), BitOffset(4));
|
||||
|
||||
CHECK(out(0) == 0xFFF000);
|
||||
CHECK(out(1) == 0xFFF);
|
||||
CHECK(out(2) == 0xFF0);
|
||||
}
|
||||
|
||||
}
|
||||
23
src/defs.cpp
23
src/defs.cpp
@@ -51,23 +51,20 @@ void assert_failed(const std::string &msg) {
|
||||
// throw std::runtime_error("Could not decode detector to string");
|
||||
// }
|
||||
|
||||
|
||||
BitOffset::BitOffset(uint32_t offset){
|
||||
if (offset>7)
|
||||
throw std::runtime_error(fmt::format("{} BitOffset needs to be <8: Called with {}", LOCATION, offset));
|
||||
BitOffset::BitOffset(uint32_t offset) {
|
||||
if (offset > 7)
|
||||
throw std::runtime_error(fmt::format(
|
||||
"{} BitOffset needs to be <8: Called with {}", LOCATION, offset));
|
||||
|
||||
m_offset = static_cast<uint8_t>(offset);
|
||||
|
||||
}
|
||||
|
||||
bool BitOffset::operator==(const BitOffset& other) const {
|
||||
return m_offset == other.m_offset;
|
||||
}
|
||||
|
||||
bool BitOffset::operator<(const BitOffset& other) const {
|
||||
return m_offset < other.m_offset;
|
||||
}
|
||||
|
||||
bool BitOffset::operator==(const BitOffset &other) const {
|
||||
return m_offset == other.m_offset;
|
||||
}
|
||||
|
||||
bool BitOffset::operator<(const BitOffset &other) const {
|
||||
return m_offset < other.m_offset;
|
||||
}
|
||||
|
||||
} // namespace aare
|
||||
@@ -4,8 +4,6 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <string>
|
||||
|
||||
|
||||
|
||||
TEST_CASE("Enum values") {
|
||||
// Since some of the enums are written to file we need to make sure
|
||||
// they match the value in the slsDetectorPackage
|
||||
@@ -38,23 +36,22 @@ TEST_CASE("DynamicCluster creation") {
|
||||
REQUIRE(c2.data() != nullptr);
|
||||
}
|
||||
|
||||
TEST_CASE("Basic ops on BitOffset"){
|
||||
TEST_CASE("Basic ops on BitOffset") {
|
||||
REQUIRE_THROWS(aare::BitOffset(10));
|
||||
|
||||
aare::BitOffset offset(5);
|
||||
REQUIRE(offset.value()==5);
|
||||
REQUIRE(offset.value() == 5);
|
||||
|
||||
aare::BitOffset offset2;
|
||||
REQUIRE(offset2.value()==0);
|
||||
REQUIRE(offset2.value() == 0);
|
||||
|
||||
aare::BitOffset offset3(offset);
|
||||
REQUIRE(offset3.value()==5);
|
||||
REQUIRE(offset3.value() == 5);
|
||||
|
||||
REQUIRE(offset==offset3);
|
||||
REQUIRE(offset == offset3);
|
||||
|
||||
//Now assign offset to offset2 which should get the value 5
|
||||
// Now assign offset to offset2 which should get the value 5
|
||||
offset2 = offset;
|
||||
REQUIRE(offset2.value()==5);
|
||||
REQUIRE(offset2==offset);
|
||||
REQUIRE(offset2.value() == 5);
|
||||
REQUIRE(offset2 == offset);
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,6 @@ template <> FrameDiscardPolicy string_to(const std::string &arg) {
|
||||
arg + "\"");
|
||||
}
|
||||
|
||||
|
||||
template <> DACIndex string_to(const std::string &arg) {
|
||||
if (arg == "dac 0")
|
||||
return DACIndex::DAC_0;
|
||||
@@ -236,12 +235,12 @@ template <> DACIndex string_to(const std::string &arg) {
|
||||
"\"");
|
||||
}
|
||||
|
||||
|
||||
std::string remove_unit(std::string &str) {
|
||||
auto it = str.begin();
|
||||
while (it != str.end()) {
|
||||
if (std::isalpha(*it)) {
|
||||
// Check if this is scientific notation (e or E followed by optional sign and digits)
|
||||
// Check if this is scientific notation (e or E followed by optional
|
||||
// sign and digits)
|
||||
if (((*it == 'e' || *it == 'E') && (it + 1) != str.end())) {
|
||||
auto next = it + 1;
|
||||
// Skip optional sign
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
namespace aare {
|
||||
|
||||
|
||||
std::string remove_unit(std::string &str);
|
||||
|
||||
template <typename T>
|
||||
@@ -40,7 +39,6 @@ T string_to(const std::string &t, const std::string &unit) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// if T has a constructor that takes a string, lets use it.
|
||||
// template <class T> T string_to(const std::string &arg) { return T{arg}; }
|
||||
template <typename T> T string_to(const std::string &arg) {
|
||||
@@ -81,10 +79,4 @@ template <> FrameDiscardPolicy string_to(const std::string &arg);
|
||||
*/
|
||||
template <> DACIndex string_to(const std::string &arg);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace aare
|
||||
@@ -10,7 +10,8 @@ using aare::string_to;
|
||||
TEST_CASE("DetectorType string to enum") {
|
||||
REQUIRE(string_to<aare::DetectorType>("Generic") ==
|
||||
aare::DetectorType::Generic);
|
||||
REQUIRE(string_to<aare::DetectorType>("Eiger") == aare::DetectorType::Eiger);
|
||||
REQUIRE(string_to<aare::DetectorType>("Eiger") ==
|
||||
aare::DetectorType::Eiger);
|
||||
REQUIRE(string_to<aare::DetectorType>("Gotthard") ==
|
||||
aare::DetectorType::Gotthard);
|
||||
REQUIRE(string_to<aare::DetectorType>("Jungfrau") ==
|
||||
@@ -36,7 +37,8 @@ TEST_CASE("DetectorType string to enum") {
|
||||
|
||||
TEST_CASE("TimingMode string to enum") {
|
||||
REQUIRE(string_to<aare::TimingMode>("auto") == aare::TimingMode::Auto);
|
||||
REQUIRE(string_to<aare::TimingMode>("trigger") == aare::TimingMode::Trigger);
|
||||
REQUIRE(string_to<aare::TimingMode>("trigger") ==
|
||||
aare::TimingMode::Trigger);
|
||||
REQUIRE_THROWS(string_to<aare::TimingMode>("invalid_mode"));
|
||||
}
|
||||
|
||||
@@ -88,34 +90,50 @@ TEST_CASE("DACIndex string to enum") {
|
||||
REQUIRE(string_to<aare::DACIndex>("vcp") == aare::DACIndex::VCP);
|
||||
REQUIRE(string_to<aare::DACIndex>("vcn") == aare::DACIndex::VCN);
|
||||
REQUIRE(string_to<aare::DACIndex>("vishaper") == aare::DACIndex::VISHAPER);
|
||||
REQUIRE(string_to<aare::DACIndex>("vthreshold") == aare::DACIndex::VTHRESHOLD);
|
||||
REQUIRE(string_to<aare::DACIndex>("vthreshold") ==
|
||||
aare::DACIndex::VTHRESHOLD);
|
||||
REQUIRE(string_to<aare::DACIndex>("vref_ds") == aare::DACIndex::VREF_DS);
|
||||
REQUIRE(string_to<aare::DACIndex>("vout_cm") == aare::DACIndex::VOUT_CM);
|
||||
REQUIRE(string_to<aare::DACIndex>("vin_cm") == aare::DACIndex::VIN_CM);
|
||||
REQUIRE(string_to<aare::DACIndex>("vref_comp") == aare::DACIndex::VREF_COMP);
|
||||
REQUIRE(string_to<aare::DACIndex>("vref_comp") ==
|
||||
aare::DACIndex::VREF_COMP);
|
||||
REQUIRE(string_to<aare::DACIndex>("vb_comp") == aare::DACIndex::VB_COMP);
|
||||
REQUIRE(string_to<aare::DACIndex>("vdd_prot") == aare::DACIndex::VDD_PROT);
|
||||
REQUIRE(string_to<aare::DACIndex>("vin_com") == aare::DACIndex::VIN_COM);
|
||||
REQUIRE(string_to<aare::DACIndex>("vref_prech") == aare::DACIndex::VREF_PRECH);
|
||||
REQUIRE(string_to<aare::DACIndex>("vb_pixbuf") == aare::DACIndex::VB_PIXBUF);
|
||||
REQUIRE(string_to<aare::DACIndex>("vref_prech") ==
|
||||
aare::DACIndex::VREF_PRECH);
|
||||
REQUIRE(string_to<aare::DACIndex>("vb_pixbuf") ==
|
||||
aare::DACIndex::VB_PIXBUF);
|
||||
REQUIRE(string_to<aare::DACIndex>("vb_ds") == aare::DACIndex::VB_DS);
|
||||
REQUIRE(string_to<aare::DACIndex>("vref_h_adc") == aare::DACIndex::VREF_H_ADC);
|
||||
REQUIRE(string_to<aare::DACIndex>("vb_comp_fe") == aare::DACIndex::VB_COMP_FE);
|
||||
REQUIRE(string_to<aare::DACIndex>("vb_comp_adc") == aare::DACIndex::VB_COMP_ADC);
|
||||
REQUIRE(string_to<aare::DACIndex>("vref_h_adc") ==
|
||||
aare::DACIndex::VREF_H_ADC);
|
||||
REQUIRE(string_to<aare::DACIndex>("vb_comp_fe") ==
|
||||
aare::DACIndex::VB_COMP_FE);
|
||||
REQUIRE(string_to<aare::DACIndex>("vb_comp_adc") ==
|
||||
aare::DACIndex::VB_COMP_ADC);
|
||||
REQUIRE(string_to<aare::DACIndex>("vcom_cds") == aare::DACIndex::VCOM_CDS);
|
||||
REQUIRE(string_to<aare::DACIndex>("vref_rstore") == aare::DACIndex::VREF_RSTORE);
|
||||
REQUIRE(string_to<aare::DACIndex>("vb_opa_1st") == aare::DACIndex::VB_OPA_1ST);
|
||||
REQUIRE(string_to<aare::DACIndex>("vref_comp_fe") == aare::DACIndex::VREF_COMP_FE);
|
||||
REQUIRE(string_to<aare::DACIndex>("vcom_adc1") == aare::DACIndex::VCOM_ADC1);
|
||||
REQUIRE(string_to<aare::DACIndex>("vref_l_adc") == aare::DACIndex::VREF_L_ADC);
|
||||
REQUIRE(string_to<aare::DACIndex>("vref_rstore") ==
|
||||
aare::DACIndex::VREF_RSTORE);
|
||||
REQUIRE(string_to<aare::DACIndex>("vb_opa_1st") ==
|
||||
aare::DACIndex::VB_OPA_1ST);
|
||||
REQUIRE(string_to<aare::DACIndex>("vref_comp_fe") ==
|
||||
aare::DACIndex::VREF_COMP_FE);
|
||||
REQUIRE(string_to<aare::DACIndex>("vcom_adc1") ==
|
||||
aare::DACIndex::VCOM_ADC1);
|
||||
REQUIRE(string_to<aare::DACIndex>("vref_l_adc") ==
|
||||
aare::DACIndex::VREF_L_ADC);
|
||||
REQUIRE(string_to<aare::DACIndex>("vref_cds") == aare::DACIndex::VREF_CDS);
|
||||
REQUIRE(string_to<aare::DACIndex>("vb_cs") == aare::DACIndex::VB_CS);
|
||||
REQUIRE(string_to<aare::DACIndex>("vb_opa_fd") == aare::DACIndex::VB_OPA_FD);
|
||||
REQUIRE(string_to<aare::DACIndex>("vcom_adc2") == aare::DACIndex::VCOM_ADC2);
|
||||
REQUIRE(string_to<aare::DACIndex>("vb_opa_fd") ==
|
||||
aare::DACIndex::VB_OPA_FD);
|
||||
REQUIRE(string_to<aare::DACIndex>("vcom_adc2") ==
|
||||
aare::DACIndex::VCOM_ADC2);
|
||||
REQUIRE(string_to<aare::DACIndex>("vcassh") == aare::DACIndex::VCASSH);
|
||||
REQUIRE(string_to<aare::DACIndex>("vth2") == aare::DACIndex::VTH2);
|
||||
REQUIRE(string_to<aare::DACIndex>("vrshaper_n") == aare::DACIndex::VRSHAPER_N);
|
||||
REQUIRE(string_to<aare::DACIndex>("vipre_out") == aare::DACIndex::VIPRE_OUT);
|
||||
REQUIRE(string_to<aare::DACIndex>("vrshaper_n") ==
|
||||
aare::DACIndex::VRSHAPER_N);
|
||||
REQUIRE(string_to<aare::DACIndex>("vipre_out") ==
|
||||
aare::DACIndex::VIPRE_OUT);
|
||||
REQUIRE(string_to<aare::DACIndex>("vth3") == aare::DACIndex::VTH3);
|
||||
REQUIRE(string_to<aare::DACIndex>("vth1") == aare::DACIndex::VTH1);
|
||||
REQUIRE(string_to<aare::DACIndex>("vicin") == aare::DACIndex::VICIN);
|
||||
@@ -124,31 +142,47 @@ TEST_CASE("DACIndex string to enum") {
|
||||
REQUIRE(string_to<aare::DACIndex>("vipre") == aare::DACIndex::VIPRE);
|
||||
REQUIRE(string_to<aare::DACIndex>("vcal_p") == aare::DACIndex::VCAL_P);
|
||||
REQUIRE(string_to<aare::DACIndex>("vdcsh") == aare::DACIndex::VDCSH);
|
||||
REQUIRE(string_to<aare::DACIndex>("vbp_colbuf") == aare::DACIndex::VBP_COLBUF);
|
||||
REQUIRE(string_to<aare::DACIndex>("vbp_colbuf") ==
|
||||
aare::DACIndex::VBP_COLBUF);
|
||||
REQUIRE(string_to<aare::DACIndex>("vb_sda") == aare::DACIndex::VB_SDA);
|
||||
REQUIRE(string_to<aare::DACIndex>("vcasc_sfp") == aare::DACIndex::VCASC_SFP);
|
||||
REQUIRE(string_to<aare::DACIndex>("vipre_cds") == aare::DACIndex::VIPRE_CDS);
|
||||
REQUIRE(string_to<aare::DACIndex>("ibias_sfp") == aare::DACIndex::IBIAS_SFP);
|
||||
REQUIRE(string_to<aare::DACIndex>("trimbits") == aare::DACIndex::TRIMBIT_SCAN);
|
||||
REQUIRE(string_to<aare::DACIndex>("highvoltage") == aare::DACIndex::HIGH_VOLTAGE);
|
||||
REQUIRE(string_to<aare::DACIndex>("vcasc_sfp") ==
|
||||
aare::DACIndex::VCASC_SFP);
|
||||
REQUIRE(string_to<aare::DACIndex>("vipre_cds") ==
|
||||
aare::DACIndex::VIPRE_CDS);
|
||||
REQUIRE(string_to<aare::DACIndex>("ibias_sfp") ==
|
||||
aare::DACIndex::IBIAS_SFP);
|
||||
REQUIRE(string_to<aare::DACIndex>("trimbits") ==
|
||||
aare::DACIndex::TRIMBIT_SCAN);
|
||||
REQUIRE(string_to<aare::DACIndex>("highvoltage") ==
|
||||
aare::DACIndex::HIGH_VOLTAGE);
|
||||
REQUIRE(string_to<aare::DACIndex>("iodelay") == aare::DACIndex::IO_DELAY);
|
||||
REQUIRE(string_to<aare::DACIndex>("temp_adc") == aare::DACIndex::TEMPERATURE_ADC);
|
||||
REQUIRE(string_to<aare::DACIndex>("temp_fpga") == aare::DACIndex::TEMPERATURE_FPGA);
|
||||
REQUIRE(string_to<aare::DACIndex>("temp_fpgaext") == aare::DACIndex::TEMPERATURE_FPGAEXT);
|
||||
REQUIRE(string_to<aare::DACIndex>("temp_10ge") == aare::DACIndex::TEMPERATURE_10GE);
|
||||
REQUIRE(string_to<aare::DACIndex>("temp_dcdc") == aare::DACIndex::TEMPERATURE_DCDC);
|
||||
REQUIRE(string_to<aare::DACIndex>("temp_sodl") == aare::DACIndex::TEMPERATURE_SODL);
|
||||
REQUIRE(string_to<aare::DACIndex>("temp_sodr") == aare::DACIndex::TEMPERATURE_SODR);
|
||||
REQUIRE(string_to<aare::DACIndex>("temp_fpgafl") == aare::DACIndex::TEMPERATURE_FPGA2);
|
||||
REQUIRE(string_to<aare::DACIndex>("temp_fpgafr") == aare::DACIndex::TEMPERATURE_FPGA3);
|
||||
REQUIRE(string_to<aare::DACIndex>("temp_slowadc") == aare::DACIndex::SLOW_ADC_TEMP);
|
||||
|
||||
REQUIRE(string_to<aare::DACIndex>("temp_adc") ==
|
||||
aare::DACIndex::TEMPERATURE_ADC);
|
||||
REQUIRE(string_to<aare::DACIndex>("temp_fpga") ==
|
||||
aare::DACIndex::TEMPERATURE_FPGA);
|
||||
REQUIRE(string_to<aare::DACIndex>("temp_fpgaext") ==
|
||||
aare::DACIndex::TEMPERATURE_FPGAEXT);
|
||||
REQUIRE(string_to<aare::DACIndex>("temp_10ge") ==
|
||||
aare::DACIndex::TEMPERATURE_10GE);
|
||||
REQUIRE(string_to<aare::DACIndex>("temp_dcdc") ==
|
||||
aare::DACIndex::TEMPERATURE_DCDC);
|
||||
REQUIRE(string_to<aare::DACIndex>("temp_sodl") ==
|
||||
aare::DACIndex::TEMPERATURE_SODL);
|
||||
REQUIRE(string_to<aare::DACIndex>("temp_sodr") ==
|
||||
aare::DACIndex::TEMPERATURE_SODR);
|
||||
REQUIRE(string_to<aare::DACIndex>("temp_fpgafl") ==
|
||||
aare::DACIndex::TEMPERATURE_FPGA2);
|
||||
REQUIRE(string_to<aare::DACIndex>("temp_fpgafr") ==
|
||||
aare::DACIndex::TEMPERATURE_FPGA3);
|
||||
REQUIRE(string_to<aare::DACIndex>("temp_slowadc") ==
|
||||
aare::DACIndex::SLOW_ADC_TEMP);
|
||||
|
||||
REQUIRE_THROWS(string_to<aare::DACIndex>("invalid_dac"));
|
||||
}
|
||||
|
||||
TEST_CASE("Remove unit from string") {
|
||||
using aare::remove_unit;
|
||||
|
||||
|
||||
// Test basic numeric value with unit
|
||||
{
|
||||
std::string input = "123.45 V";
|
||||
@@ -156,7 +190,7 @@ TEST_CASE("Remove unit from string") {
|
||||
REQUIRE(unit == "V");
|
||||
REQUIRE(input == "123.45");
|
||||
}
|
||||
|
||||
|
||||
// Test integer value with unit
|
||||
{
|
||||
std::string input = "42 Hz";
|
||||
@@ -164,7 +198,7 @@ TEST_CASE("Remove unit from string") {
|
||||
REQUIRE(unit == "Hz");
|
||||
REQUIRE(input == "42");
|
||||
}
|
||||
|
||||
|
||||
// Test negative value with unit
|
||||
{
|
||||
std::string input = "-50.5 mV";
|
||||
@@ -172,7 +206,7 @@ TEST_CASE("Remove unit from string") {
|
||||
REQUIRE(unit == "mV");
|
||||
REQUIRE(input == "-50.5");
|
||||
}
|
||||
|
||||
|
||||
// Test value with no unit (only numbers)
|
||||
{
|
||||
std::string input = "123.45";
|
||||
@@ -180,7 +214,7 @@ TEST_CASE("Remove unit from string") {
|
||||
REQUIRE(unit == "");
|
||||
REQUIRE(input == "123.45");
|
||||
}
|
||||
|
||||
|
||||
// Test value with only unit (letters at start)
|
||||
{
|
||||
std::string input = "kHz";
|
||||
@@ -188,7 +222,7 @@ TEST_CASE("Remove unit from string") {
|
||||
REQUIRE(unit == "kHz");
|
||||
REQUIRE(input == "");
|
||||
}
|
||||
|
||||
|
||||
// Test with multiple word units
|
||||
{
|
||||
std::string input = "100 degrees Celsius";
|
||||
@@ -196,7 +230,7 @@ TEST_CASE("Remove unit from string") {
|
||||
REQUIRE(unit == "degrees Celsius");
|
||||
REQUIRE(input == "100");
|
||||
}
|
||||
|
||||
|
||||
// Test with scientific notation
|
||||
{
|
||||
std::string input = "1.23e-5 A";
|
||||
@@ -212,7 +246,7 @@ TEST_CASE("Remove unit from string") {
|
||||
REQUIRE(unit == "m/s");
|
||||
REQUIRE(input == "-4.56E6");
|
||||
}
|
||||
|
||||
|
||||
// Test with scientific notation uppercase
|
||||
{
|
||||
std::string input = "5.67E+3 Hz";
|
||||
@@ -220,7 +254,7 @@ TEST_CASE("Remove unit from string") {
|
||||
REQUIRE(unit == "Hz");
|
||||
REQUIRE(input == "5.67E+3");
|
||||
}
|
||||
|
||||
|
||||
// Test with leading zeros
|
||||
{
|
||||
std::string input = "00123 ohm";
|
||||
@@ -236,7 +270,7 @@ TEST_CASE("Remove unit from string") {
|
||||
REQUIRE(unit == "ohm");
|
||||
REQUIRE(input == "00123");
|
||||
}
|
||||
|
||||
|
||||
// Test empty string
|
||||
{
|
||||
std::string input = "";
|
||||
@@ -260,7 +294,8 @@ TEST_CASE("Conversions from time string to chrono durations") {
|
||||
REQUIRE(string_to<microseconds>("2.5 ms") == microseconds(2500));
|
||||
REQUIRE(string_to<milliseconds>("3.5 s") == milliseconds(3500));
|
||||
|
||||
REQUIRE(string_to<seconds>("2") == seconds(2)); // No unit defaults to seconds
|
||||
REQUIRE(string_to<seconds>("2") ==
|
||||
seconds(2)); // No unit defaults to seconds
|
||||
|
||||
REQUIRE_THROWS(string_to<seconds>("10 min")); // Unsupported unit
|
||||
}
|
||||
Reference in New Issue
Block a user