From 3597c207f2cbd334fdd5a80c625368d50b5ef95a Mon Sep 17 00:00:00 2001 From: Jimoh Yusuf Date: Wed, 8 Jan 2025 12:24:34 +0000 Subject: [PATCH] removed helper methods from namespace to class as private methods in PolarizationCorrectionWildesTest --- .../test/PolarizationCorrectionWildesTest.h | 222 +++++++++--------- 1 file changed, 111 insertions(+), 111 deletions(-) diff --git a/Framework/Algorithms/test/PolarizationCorrectionWildesTest.h b/Framework/Algorithms/test/PolarizationCorrectionWildesTest.h index 2fab3d274225..68416734c634 100644 --- a/Framework/Algorithms/test/PolarizationCorrectionWildesTest.h +++ b/Framework/Algorithms/test/PolarizationCorrectionWildesTest.h @@ -32,117 +32,7 @@ using namespace Mantid::Kernel; using namespace Mantid::Algorithms; using namespace Mantid::Algorithms::PolarizationCorrectionsHelpers; -namespace { - -MatrixWorkspace_sptr createWorkspace(size_t nHist = 2, std::optional edges = std::nullopt, - std::optional counts = std::nullopt) { - if (!edges) { - edges = BinEdges{0.3, 0.6, 0.9, 1.2}; - } - - const auto yVal = 2.3; - if (!counts) { - counts = Counts{yVal, 4.2 * (yVal), yVal}; - } - - return create(nHist, Histogram(*edges, *counts)); -} - -MatrixWorkspace_sptr createWorkspace(size_t nHist, const Counts &counts) { - return createWorkspace(nHist, std::nullopt, counts); -} - -MatrixWorkspace_sptr createWorkspace(const Counts &counts) { return createWorkspace(2, std::nullopt, counts); } - -std::vector cloneWorkspaces(const MatrixWorkspace_sptr &sourceWorkspace, const size_t numClones) { - std::vector clonedWorkspaces; - - clonedWorkspaces.push_back(sourceWorkspace); - for (size_t i = 1; i < numClones; ++i) { - clonedWorkspaces.push_back(sourceWorkspace->clone()); - } - - return clonedWorkspaces; -} - -std::vector generateWorkspaceNames(const size_t numClones) { - std::vector wsNames; - - for (size_t i = 0; i < numClones; ++i) { - wsNames.push_back("ws" + std::to_string(i)); - } - - return wsNames; -} -void addWorkspacesToService(const std::vector &wsNames, const std::vector &wsList, - const size_t numWorkspaces) { - for (size_t i = 0; i < numWorkspaces; ++i) { - AnalysisDataService::Instance().addOrReplace(wsNames[i], wsList[i]); - } -} - -void addWorkspaceToService(const std::string &wsName, const MatrixWorkspace_sptr &ws) { - AnalysisDataService::Instance().addOrReplace(wsName, ws); -} - -void prepareAndRegisterWorkspaces(std::vector &wsNames, - const std::vector &wsList, const size_t nHist) { - - for (size_t i = 0; i != wsNames.size(); ++i) { - for (size_t j = 0; j != nHist; ++j) { - wsList[i]->mutableY(j) *= static_cast(i + 1); - wsList[i]->mutableE(j) *= static_cast(i + 1); - } - addWorkspacesToService(wsNames, wsList, wsNames.size()); - } -} - -std::vector createWorkspaceList(const std::optional counts, const size_t numClones) { - auto baseWorkspace = counts.has_value() ? createWorkspace(*counts) : createWorkspace(); - - return cloneWorkspaces(baseWorkspace, numClones); -} - -std::vector createWorkspaceList(const size_t numClones) { - return createWorkspaceList(std::nullopt, numClones); -} - -void setupWorkspacesForIdealCasesTwoInput(const std::vector &wsNames, - const std::vector &wsList, - const size_t nHist) { - - for (size_t i = 0; i != nHist; ++i) { - wsList[1]->mutableY(i) *= 2.; - wsList[1]->mutableE(i) *= 2.; - } - - AnalysisDataService::Instance().addOrReplace(wsNames.front(), wsList.front()); - AnalysisDataService::Instance().addOrReplace(wsNames.back(), wsList.back()); -} - -void validateNumberOfEntries(const WorkspaceGroup_sptr workspaceGroup, const size_t expectedEntries) { - TS_ASSERT_EQUALS(workspaceGroup->getNumberOfEntries(), expectedEntries); -} - -void validateSpinStateLogs(const WorkspaceGroup_sptr &outputWS, const std::vector &expectedLogValues) { - const auto logName = SpinStatesORSO::LOG_NAME; - for (size_t i = 0; i < expectedLogValues.size(); ++i) { - MatrixWorkspace_sptr ws = std::dynamic_pointer_cast(outputWS->getItem(i)); - TS_ASSERT(ws); - const auto &run = ws->run(); - TS_ASSERT(run.hasProperty(logName)); - TS_ASSERT_EQUALS(run.getPropertyValueAsType(logName), expectedLogValues[i]); - } -} - -void validateNoSpinStateLogs(const WorkspaceGroup_sptr &outputWS, size_t numClones) { - for (size_t i = 0; i < numClones; ++i) { - MatrixWorkspace_sptr ws = std::dynamic_pointer_cast(outputWS->getItem(i)); - TS_ASSERT(ws); - TS_ASSERT(!ws->run().hasProperty(SpinStatesORSO::LOG_NAME)); - } -} -} // namespace +// namespace class PolarizationCorrectionWildesTest : public CxxTest::TestSuite { public: // This pair of boilerplate methods prevent the suite being created statically @@ -1524,6 +1414,116 @@ class PolarizationCorrectionWildesTest : public CxxTest::TestSuite { validateNoSpinStateLogs(outputWS, numClones); } } + + MatrixWorkspace_sptr createWorkspace(size_t nHist = 2, std::optional edges = std::nullopt, + std::optional counts = std::nullopt) { + if (!edges) { + edges = BinEdges{0.3, 0.6, 0.9, 1.2}; + } + + const auto yVal = 2.3; + if (!counts) { + counts = Counts{yVal, 4.2 * (yVal), yVal}; + } + + return create(nHist, Histogram(*edges, *counts)); + } + + MatrixWorkspace_sptr createWorkspace(size_t nHist, const Counts &counts) { + return createWorkspace(nHist, std::nullopt, counts); + } + + MatrixWorkspace_sptr createWorkspace(const Counts &counts) { return createWorkspace(2, std::nullopt, counts); } + + std::vector cloneWorkspaces(const MatrixWorkspace_sptr &sourceWorkspace, + const size_t numClones) { + std::vector clonedWorkspaces; + + clonedWorkspaces.push_back(sourceWorkspace); + for (size_t i = 1; i < numClones; ++i) { + clonedWorkspaces.push_back(sourceWorkspace->clone()); + } + + return clonedWorkspaces; + } + + std::vector generateWorkspaceNames(const size_t numClones) { + std::vector wsNames; + + for (size_t i = 0; i < numClones; ++i) { + wsNames.push_back("ws" + std::to_string(i)); + } + + return wsNames; + } + void addWorkspacesToService(const std::vector &wsNames, const std::vector &wsList, + const size_t numWorkspaces) { + for (size_t i = 0; i < numWorkspaces; ++i) { + AnalysisDataService::Instance().addOrReplace(wsNames[i], wsList[i]); + } + } + + void addWorkspaceToService(const std::string &wsName, const MatrixWorkspace_sptr &ws) { + AnalysisDataService::Instance().addOrReplace(wsName, ws); + } + + void prepareAndRegisterWorkspaces(std::vector &wsNames, + const std::vector &wsList, const size_t nHist) { + + for (size_t i = 0; i != wsNames.size(); ++i) { + for (size_t j = 0; j != nHist; ++j) { + wsList[i]->mutableY(j) *= static_cast(i + 1); + wsList[i]->mutableE(j) *= static_cast(i + 1); + } + addWorkspacesToService(wsNames, wsList, wsNames.size()); + } + } + + std::vector createWorkspaceList(const std::optional counts, const size_t numClones) { + auto baseWorkspace = counts.has_value() ? createWorkspace(*counts) : createWorkspace(); + + return cloneWorkspaces(baseWorkspace, numClones); + } + + std::vector createWorkspaceList(const size_t numClones) { + return createWorkspaceList(std::nullopt, numClones); + } + + void setupWorkspacesForIdealCasesTwoInput(const std::vector &wsNames, + const std::vector &wsList, + const size_t nHist) { + + for (size_t i = 0; i != nHist; ++i) { + wsList[1]->mutableY(i) *= 2.; + wsList[1]->mutableE(i) *= 2.; + } + + AnalysisDataService::Instance().addOrReplace(wsNames.front(), wsList.front()); + AnalysisDataService::Instance().addOrReplace(wsNames.back(), wsList.back()); + } + + void validateNumberOfEntries(const WorkspaceGroup_sptr workspaceGroup, const size_t expectedEntries) { + TS_ASSERT_EQUALS(workspaceGroup->getNumberOfEntries(), expectedEntries); + } + + void validateSpinStateLogs(const WorkspaceGroup_sptr &outputWS, const std::vector &expectedLogValues) { + const auto logName = SpinStatesORSO::LOG_NAME; + for (size_t i = 0; i < expectedLogValues.size(); ++i) { + MatrixWorkspace_sptr ws = std::dynamic_pointer_cast(outputWS->getItem(i)); + TS_ASSERT(ws); + const auto &run = ws->run(); + TS_ASSERT(run.hasProperty(logName)); + TS_ASSERT_EQUALS(run.getPropertyValueAsType(logName), expectedLogValues[i]); + } + } + + void validateNoSpinStateLogs(const WorkspaceGroup_sptr &outputWS, size_t numClones) { + for (size_t i = 0; i < numClones; ++i) { + MatrixWorkspace_sptr ws = std::dynamic_pointer_cast(outputWS->getItem(i)); + TS_ASSERT(ws); + TS_ASSERT(!ws->run().hasProperty(SpinStatesORSO::LOG_NAME)); + } + } }; class PolarizationCorrectionWildesTestPerformance : public CxxTest::TestSuite {