From f57191d83d087140ba8c49abf59d9b4437ec6ace Mon Sep 17 00:00:00 2001 From: Verena Reimund <reimund@ill.eu> Date: Thu, 8 Nov 2018 16:18:28 +0100 Subject: [PATCH] Initial tests for join & merge Refs #23947 --- .../SampleLogsBehaviour.h | 1 + .../Algorithms/test/SampleLogsBehaviourTest.h | 64 ++++++++++++++++++- 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/Framework/Algorithms/inc/MantidAlgorithms/RunCombinationHelpers/SampleLogsBehaviour.h b/Framework/Algorithms/inc/MantidAlgorithms/RunCombinationHelpers/SampleLogsBehaviour.h index 842a7c34378..9ac1533d055 100644 --- a/Framework/Algorithms/inc/MantidAlgorithms/RunCombinationHelpers/SampleLogsBehaviour.h +++ b/Framework/Algorithms/inc/MantidAlgorithms/RunCombinationHelpers/SampleLogsBehaviour.h @@ -23,6 +23,7 @@ class MANTID_ALGORITHMS_DLL SampleLogsBehaviour { public: enum class MergeLogType { Sum, TimeSeries, List, Warn, Fail }; + // names of parameters in IPF const std::string SUM_MERGE; const std::string TIME_SERIES_MERGE; const std::string LIST_MERGE; diff --git a/Framework/Algorithms/test/SampleLogsBehaviourTest.h b/Framework/Algorithms/test/SampleLogsBehaviourTest.h index f5e92a8aad4..7b44c0eb118 100644 --- a/Framework/Algorithms/test/SampleLogsBehaviourTest.h +++ b/Framework/Algorithms/test/SampleLogsBehaviourTest.h @@ -24,12 +24,18 @@ #include "MantidKernel/make_cow.h" #include "MantidTestHelpers/WorkspaceCreationHelper.h" +#include "MantidDataHandling/LoadParameterFile.h" +#include "MantidGeometry/Instrument.h" +#include "MantidGeometry/Instrument/ParameterMap.h" + using Mantid::Algorithms::CreateSampleWorkspace; using Mantid::Algorithms::GroupWorkspaces; using Mantid::Algorithms::SampleLogsBehaviour; using namespace Mantid::API; +using namespace Mantid::DataHandling; using namespace Mantid::DataObjects; using namespace Mantid::HistogramData; +using namespace Mantid::Geometry; using namespace Mantid::Kernel; using namespace WorkspaceCreationHelper; @@ -42,9 +48,65 @@ public: } static void destroySuite(SampleLogsBehaviourTest *suite) { delete suite; } + // Please note that many tests are currently present in MergeRunsTest. -private: + void testMergeRunsIPFNames() { + // Using default values of the constructor + Logger log("testLog"); + MatrixWorkspace_sptr ws = create2DWorkspaceWithFullInstrument( + 3, 3, true, false, true, "INSTRUMENT"); + // Add sample logs + ws->mutableRun().addLogData(new PropertyWithValue<double>("A", 2.65)); + ws->mutableRun().addLogData(new PropertyWithValue<double>("B", 1.56)); + ws->mutableRun().addLogData(new PropertyWithValue<double>("C", 8.55)); + // Load test parameter file + LoadParameterFile paramLoader; + paramLoader.initialize(); + paramLoader.setPropertyValue( + "Filename", "IDFs_for_UNIT_TESTING/SampleLogsBehaviour_Parameters.xml"); + paramLoader.setProperty("Workspace", ws); + paramLoader.execute(); + SampleLogsBehaviour sbh = SampleLogsBehaviour(ws, log); + sbh.mergeSampleLogs(ws, ws); + const std::string A = ws->run().getLogData("A")->value(); + const std::string B = ws->run().getLogData("B")->value(); + const std::string C = ws->run().getLogData("C")->value(); + TS_ASSERT_EQUALS(A, "2.6499999999999999") + TS_ASSERT_EQUALS(B, "1.5600000000000001") + TS_ASSERT_EQUALS(C, "8.5500000000000007") + } + void testConjoinXRunsIPFNames() { + // Using suffix conjoin_ + default value names for constructing + Logger log("testLog"); + MatrixWorkspace_sptr ws = create2DWorkspaceWithFullInstrument( + 3, 3, true, false, true, "INSTRUMENT"); + // Add sample logs + ws->mutableRun().addLogData(new PropertyWithValue<double>("A", 2.65)); + ws->mutableRun().addLogData(new PropertyWithValue<double>("B", 1.56)); + ws->mutableRun().addLogData(new PropertyWithValue<double>("C", 8.55)); + // Load test parameter file + LoadParameterFile paramLoader; + paramLoader.initialize(); + paramLoader.setPropertyValue( + "Filename", "IDFs_for_UNIT_TESTING/SampleLogsBehaviour_Parameters.xml"); + paramLoader.setProperty("Workspace", ws); + paramLoader.execute(); + SampleLogsBehaviour sbh = SampleLogsBehaviour( + ws, log, "", "", "", "", "", "", "", "conjoin_sample_logs_sum", + "conjoin_sample_logs_time_series", "conjoin_sample_logs_list", + "conjoin_sample_logs_warn", "conjoin_sample_logs_warn_tolerances", + "conjoin_sample_logs_fail", "conjoin_sample_logs_fail_tolerances"); + sbh.mergeSampleLogs(ws, ws); + const std::string A = ws->run().getLogData("A")->value(); + const std::string B = ws->run().getLogData("B")->value(); + const std::string C = ws->run().getLogData("C")->value(); + TS_ASSERT_EQUALS(A, "2.6499999999999999") + TS_ASSERT_EQUALS(B, "1.5600000000000001") + TS_ASSERT_EQUALS(C, "8.5500000000000007") + } + +private: }; #endif /* MANTID_ALGORITHMS_SAMPLELOGSBEHAVIOURTEST_H_ */ -- GitLab