#include "aare/defs.hpp" #include #include using aare::ToString; using aare::StringTo; TEST_CASE("Enum to string conversion") { // TODO! By the way I don't think the enum string conversions should be in the defs.hpp file // but let's use this to show a test REQUIRE(ToString(aare::DetectorType::Generic) == "Generic"); REQUIRE(ToString(aare::DetectorType::Eiger) == "Eiger"); REQUIRE(ToString(aare::DetectorType::Gotthard) == "Gotthard"); REQUIRE(ToString(aare::DetectorType::Jungfrau) == "Jungfrau"); REQUIRE(ToString(aare::DetectorType::ChipTestBoard) == "ChipTestBoard"); REQUIRE(ToString(aare::DetectorType::Moench) == "Moench"); REQUIRE(ToString(aare::DetectorType::Mythen3) == "Mythen3"); REQUIRE(ToString(aare::DetectorType::Gotthard2) == "Gotthard2"); REQUIRE(ToString(aare::DetectorType::Xilinx_ChipTestBoard) == "Xilinx_ChipTestBoard"); REQUIRE(ToString(aare::DetectorType::Moench03) == "Moench03"); REQUIRE(ToString(aare::DetectorType::Moench03_old) == "Moench03_old"); REQUIRE(ToString(aare::DetectorType::Unknown) == "Unknown"); } TEST_CASE("String to enum"){ REQUIRE(StringTo("Generic") == aare::DetectorType::Generic); REQUIRE(StringTo("Eiger") == aare::DetectorType::Eiger); REQUIRE(StringTo("Gotthard") == aare::DetectorType::Gotthard); REQUIRE(StringTo("Jungfrau") == aare::DetectorType::Jungfrau); REQUIRE(StringTo("ChipTestBoard") == aare::DetectorType::ChipTestBoard); REQUIRE(StringTo("Moench") == aare::DetectorType::Moench); REQUIRE(StringTo("Mythen3") == aare::DetectorType::Mythen3); REQUIRE(StringTo("Gotthard2") == aare::DetectorType::Gotthard2); REQUIRE(StringTo("Xilinx_ChipTestBoard") == aare::DetectorType::Xilinx_ChipTestBoard); REQUIRE(StringTo("Moench03") == aare::DetectorType::Moench03); REQUIRE(StringTo("Moench03_old") == aare::DetectorType::Moench03_old); REQUIRE(StringTo("Unknown") == aare::DetectorType::Unknown); } 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 REQUIRE(static_cast(aare::DetectorType::Generic) == 0); REQUIRE(static_cast(aare::DetectorType::Eiger) == 1); REQUIRE(static_cast(aare::DetectorType::Gotthard) == 2); REQUIRE(static_cast(aare::DetectorType::Jungfrau) == 3); REQUIRE(static_cast(aare::DetectorType::ChipTestBoard) == 4); REQUIRE(static_cast(aare::DetectorType::Moench) == 5); REQUIRE(static_cast(aare::DetectorType::Mythen3) == 6); REQUIRE(static_cast(aare::DetectorType::Gotthard2) == 7); REQUIRE(static_cast(aare::DetectorType::Xilinx_ChipTestBoard) == 8); //Not included REQUIRE(static_cast(aare::DetectorType::Moench03) == 100); } TEST_CASE("DynamicCluster creation") { aare::DynamicCluster c(13, 15); REQUIRE(c.cluster_sizeX == 13); REQUIRE(c.cluster_sizeY == 15); REQUIRE(c.dt == aare::Dtype(typeid(int32_t))); REQUIRE(c.data() != nullptr); aare::DynamicCluster c2(c); REQUIRE(c2.cluster_sizeX == 13); REQUIRE(c2.cluster_sizeY == 15); REQUIRE(c2.dt == aare::Dtype(typeid(int32_t))); REQUIRE(c2.data() != nullptr); } // TEST_CASE("cluster set and get data") { // aare::DynamicCluster c2(33, 44, aare::Dtype(typeid(double))); // REQUIRE(c2.cluster_sizeX == 33); // REQUIRE(c2.cluster_sizeY == 44); // REQUIRE(c2.dt == aare::Dtype::DOUBLE); // double v = 3.14; // c2.set(0, v); // double v2 = c2.get(0); // REQUIRE(aare::compare_floats(v, v2)); // c2.set(33 * 44 - 1, 123.11); // double v3 = c2.get(33 * 44 - 1); // REQUIRE(aare::compare_floats(123.11, v3)); // REQUIRE_THROWS_AS(c2.set(0, 1), std::invalid_argument); // set int to double // }