Skip to content
Snippets Groups Projects
Commit d12a7968 authored by Gagik Vardanyan's avatar Gagik Vardanyan
Browse files

Re #22728 improved unit tests

parent 70ca6077
No related branches found
No related tags found
No related merge requests found
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/AlgorithmManager.h"
#include "MantidAPI/SpectrumInfo.h" #include "MantidAPI/SpectrumInfo.h"
#include "MantidAlgorithms/CreateSampleWorkspace.h"
#include "MantidAlgorithms/CropToComponent.h" #include "MantidAlgorithms/CropToComponent.h"
#include "MantidDataHandling/LoadRaw3.h" #include "MantidDataHandling/LoadRaw3.h"
#include "MantidTestHelpers/WorkspaceCreationHelper.h" #include "MantidTestHelpers/WorkspaceCreationHelper.h"
...@@ -201,6 +202,34 @@ public: ...@@ -201,6 +202,34 @@ public:
} }
} }
void test_scanning_workspace() {
// Create a sample scanning workspace
Mantid::Algorithms::CreateSampleWorkspace creator;
creator.setChild(true);
creator.initialize();
creator.setProperty("NumBanks", 2);
creator.setProperty("NumScanPoints", 5);
creator.setProperty("OutputWorkspace", "__unused_for_child");
creator.execute();
Mantid::API::MatrixWorkspace_sptr workspace =
creator.getProperty("OutputWorkspace");
// Act
Mantid::Algorithms::CropToComponent crop;
crop.setChild(true);
crop.initialize();
crop.setRethrows(true);
crop.setProperty("InputWorkspace", workspace);
crop.setProperty("OutputWorkspace", "__cropped");
crop.setProperty("ComponentNames", "bank1");
TS_ASSERT_THROWS_NOTHING(crop.execute())
TS_ASSERT(crop.isExecuted())
Mantid::API::MatrixWorkspace_sptr cropped =
crop.getProperty("OutputWorkspace");
TS_ASSERT(cropped)
}
private: private:
Mantid::API::MatrixWorkspace_sptr Mantid::API::MatrixWorkspace_sptr
getSampleWorkspace(int numberOfBanks, int numbersOfPixelPerBank) { getSampleWorkspace(int numberOfBanks, int numbersOfPixelPerBank) {
......
...@@ -333,17 +333,25 @@ public: ...@@ -333,17 +333,25 @@ public:
"Some of the requested detectors do not have a corresponding spectrum"); "Some of the requested detectors do not have a corresponding spectrum");
} }
void test_globalSpectrumIndicesFromDetectorIndices_scanning() { void
test_globalSpectrumIndicesFromDetectorIndices_scanning_different_time_indices() {
IndexInfo info(3); IndexInfo info(3);
std::vector<size_t> detectorIndices{6, 8}; std::vector<size_t> detectorIndices{6, 8};
std::vector<SpectrumDefinition> specDefs(3); std::vector<SpectrumDefinition> specDefs(3);
// Two indices map to same detector; typical for time-indexed workspaces. // Two indices map to the same detector at different time indices; typical
specDefs[0].add(6); // for time-indexed workspaces.
specDefs[1].add(6); specDefs[0].add(6, 1);
specDefs[2].add(8); specDefs[1].add(6, 2);
specDefs[2].add(8, 1);
info.setSpectrumDefinitions(specDefs); info.setSpectrumDefinitions(specDefs);
TS_ASSERT_THROWS_NOTHING( TS_ASSERT_THROWS_NOTHING(
info.globalSpectrumIndicesFromDetectorIndices(detectorIndices)); info.globalSpectrumIndicesFromDetectorIndices(detectorIndices));
const auto &indices =
info.globalSpectrumIndicesFromDetectorIndices(detectorIndices);
TS_ASSERT_EQUALS(indices.size(), 3);
TS_ASSERT_EQUALS(indices[0], 0);
TS_ASSERT_EQUALS(indices[1], 1);
TS_ASSERT_EQUALS(indices[2], 2);
} }
void test_globalSpectrumIndicesFromDetectorIndices_fails_conflict_miss() { void test_globalSpectrumIndicesFromDetectorIndices_fails_conflict_miss() {
...@@ -351,8 +359,8 @@ public: ...@@ -351,8 +359,8 @@ public:
std::vector<size_t> detectorIndices{6, 8}; std::vector<size_t> detectorIndices{6, 8};
std::vector<SpectrumDefinition> specDefs(3); std::vector<SpectrumDefinition> specDefs(3);
// Two indices map to same detector, but additionally one is missing. // Two indices map to same detector, but additionally one is missing.
specDefs[0].add(6); specDefs[0].add(6, 1);
specDefs[1].add(6); specDefs[1].add(6, 2);
info.setSpectrumDefinitions(specDefs); info.setSpectrumDefinitions(specDefs);
TS_ASSERT_THROWS_EQUALS( TS_ASSERT_THROWS_EQUALS(
info.globalSpectrumIndicesFromDetectorIndices(detectorIndices), info.globalSpectrumIndicesFromDetectorIndices(detectorIndices),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment