mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 01:58:00 +02:00
trimEn now takes vector
This commit is contained in:
@ -1 +1,5 @@
|
||||
target_sources(tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test-SharedMemory.cpp)
|
||||
target_sources(tests PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test-SharedMemory.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test-slsDetector.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test-multiSlsDetector.cpp
|
||||
)
|
63
slsDetectorSoftware/tests/test-multiSlsDetector.cpp
Normal file
63
slsDetectorSoftware/tests/test-multiSlsDetector.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "container_utils.h"
|
||||
#include "multiSlsDetector.h"
|
||||
#include "slsDetector.h"
|
||||
#include "string_utils.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace sls;
|
||||
|
||||
SCENARIO("Multi detector operation", "[detector]") {
|
||||
|
||||
multiSlsDetector::freeSharedMemory(0, -1);
|
||||
|
||||
GIVEN("An empty multi detector") {
|
||||
multiSlsDetector m(0);
|
||||
THEN("the size is zero") {
|
||||
CHECK(m.getNumberOfDetectors() == 0);
|
||||
CHECK(m.getDataBytes() == 0);
|
||||
CHECK(m.getTotalNumberOfChannels() == 0);
|
||||
}
|
||||
|
||||
WHEN("we add a detector") {
|
||||
m.addSlsDetector(sls::make_unique<slsDetector>(
|
||||
slsDetectorDefs::detectorType::EIGER, 0, 0));
|
||||
THEN("the size and number of detector changes") {
|
||||
CHECK(m.getNumberOfDetectors() == 1);
|
||||
CHECK(m.getTotalNumberOfChannels() == 256 * 1024);
|
||||
}
|
||||
|
||||
WHEN("we add another detector") {
|
||||
m.addSlsDetector(sls::make_unique<slsDetector>(
|
||||
slsDetectorDefs::detectorType::EIGER, 0, 1));
|
||||
THEN("the size and number of detector changes") {
|
||||
CHECK(m.getNumberOfDetectors() == 2);
|
||||
CHECK(m.getTotalNumberOfChannels() == 2 * 256 * 1024);
|
||||
}
|
||||
|
||||
WHEN("We set the trimen") {
|
||||
std::vector<int> energies{5000, 6000, 7000, 8000, 9000};
|
||||
m.setTrimEn(energies);
|
||||
THEN("we read back the same values") {
|
||||
CHECK(m.getTrimEn() == energies);
|
||||
}
|
||||
}
|
||||
WHEN("We set the trimen to different values") {
|
||||
std::vector<int> en0{5000, 6000, 7000, 8000, 9000};
|
||||
std::vector<int> en1{6000, 7000, 8000, 9000};
|
||||
m.setTrimEn(en0, 0);
|
||||
m.setTrimEn(en1, 1);
|
||||
THEN("we read back the same values") {
|
||||
CHECK(m.getTrimEn(0) == en0);
|
||||
CHECK(m.getTrimEn(1) == en1);
|
||||
CHECK(m.getTrimEn() == std::vector<int>{-1});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m.freeSharedMemory();
|
||||
}
|
||||
}
|
49
slsDetectorSoftware/tests/test-slsDetector.cpp
Normal file
49
slsDetectorSoftware/tests/test-slsDetector.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "container_utils.h"
|
||||
#include "slsDetector.h"
|
||||
#include "string_utils.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace sls;
|
||||
|
||||
TEST_CASE("Set and get trimen", "[detector]") {
|
||||
// Free shared memory to be sure that we start in a clean state
|
||||
slsDetector::freeSharedMemory(0, 0);
|
||||
|
||||
// Create a detector and check that the type is set correctly
|
||||
slsDetector d(slsDetectorDefs::detectorType::EIGER, 0, 0);
|
||||
CHECK(d.getDetectorTypeAsEnum() == slsDetectorDefs::detectorType::EIGER);
|
||||
|
||||
// At the beginning there should be no trimen set
|
||||
auto res = d.getTrimEn();
|
||||
CHECK(res.size() == 0);
|
||||
|
||||
std::vector<int> energies{5200, 6400, 8500, 9900, 12000};
|
||||
d.setTrimEn(energies);
|
||||
auto res2 = d.getTrimEn();
|
||||
|
||||
// Check that the size and every element matches what we set
|
||||
CHECK(res2.size() == energies.size());
|
||||
for (size_t i = 0; i != res2.size(); ++i)
|
||||
CHECK(res2[i] == energies[i]);
|
||||
|
||||
|
||||
|
||||
// Setting trimen with too many vales throws an exception and keeps the
|
||||
// old values
|
||||
std::vector<int> too_many(150, 1000);
|
||||
CHECK_THROWS(d.setTrimEn(too_many));
|
||||
auto res3 = d.getTrimEn();
|
||||
CHECK(res3.size() == energies.size());
|
||||
for (size_t i = 0; i != res3.size(); ++i)
|
||||
CHECK(res3[i] == energies[i]);
|
||||
|
||||
// Setting trimen without arguments resets to zero
|
||||
d.setTrimEn();
|
||||
CHECK(d.getTrimEn().size() == 0);
|
||||
|
||||
// Clean up before next test
|
||||
d.freeSharedMemory();
|
||||
}
|
Reference in New Issue
Block a user