Commit 203786f2 authored by Tom Perkins's avatar Tom Perkins
Browse files

Test getPropertyAsSingleValue for numeric types

Add tests for double, float, int, long, unsigned int, unsigned long
(All but double fail at the moment)

re #17087
parent 4f1864cb
......@@ -10,6 +10,7 @@
#include <cxxtest/TestSuite.h>
#include "MantidTestHelpers/NexusTestHelper.h"
#include "MantidGeometry/Instrument/Goniometer.h"
#include <cmath>
using namespace Mantid::Kernel;
using namespace Mantid::API;
......@@ -36,8 +37,9 @@ public:
Property &operator+=(Property const *) override { return *this; }
};
template <typename T>
void addTestTimeSeries(LogManager &run, const std::string &name) {
auto timeSeries = new TimeSeriesProperty<double>(name);
auto timeSeries = new TimeSeriesProperty<T>(name);
timeSeries->addValue("2012-07-19T16:17:00", 2);
timeSeries->addValue("2012-07-19T16:17:10", 3);
timeSeries->addValue("2012-07-19T16:17:20", 4);
......@@ -229,11 +231,35 @@ public:
std::invalid_argument);
}
void test_GetPropertyAsSingleValue_SingleValue_DoubleType() {
doTest_GetPropertyAsSingleValue_SingleType<double>(1.0);
}
void test_GetPropertyAsSingleValue_SingleValue_FloatType() {
doTest_GetPropertyAsSingleValue_SingleType<float>(1.0F);
}
void test_GetPropertyAsSingleValue_SingleValue_Int32Type() {
doTest_GetPropertyAsSingleValue_SingleType<int32_t>(1);
}
void test_GetPropertyAsSingleValue_SingleValue_Int64Type() {
doTest_GetPropertyAsSingleValue_SingleType<int64_t>(1L);
}
void test_GetPropertyAsSingleValue_SingleValue_Uint32Type() {
doTest_GetPropertyAsSingleValue_SingleType<uint32_t>(1U);
}
void test_GetPropertyAsSingleValue_SingleValue_Uint64Type() {
doTest_GetPropertyAsSingleValue_SingleType<uint64_t>(1UL);
}
void
test_GetPropertyAsSingleValue_Throws_If_Type_Is_Not_Double_Or_TimeSeries_Double() {
test_GetPropertyAsSingleValue_Throws_If_Type_Is_Not_Numeric_Or_TimeSeries_Numeric() {
LogManager runInfo;
const std::string name = "int_prop";
runInfo.addProperty(name, 1); // Adds an int property
const std::string name = "string_prop";
runInfo.addProperty<std::string>(name, "hello"); // Adds a string property
TS_ASSERT_THROWS(runInfo.getPropertyAsSingleValue(name),
std::invalid_argument);
......@@ -243,7 +269,7 @@ public:
test_GetPropertyAsSingleValue_Returns_Simple_Mean_By_Default_For_Time_Series() {
LogManager runInfo;
const std::string name = "series";
addTestTimeSeries(runInfo, name);
addTestTimeSeries<double>(runInfo, name);
const double expectedValue(13.0);
TS_ASSERT_DELTA(runInfo.getPropertyAsSingleValue(name), expectedValue,
......@@ -254,7 +280,7 @@ public:
test_GetPropertyAsSingleValue_Returns_Correct_SingleValue_For_Each_StatisticType() {
LogManager runInfo;
const std::string name = "series";
addTestTimeSeries(runInfo, name);
addTestTimeSeries<double>(runInfo, name);
TS_ASSERT_DELTA(runInfo.getPropertyAsSingleValue(name, Math::Mean), 13.0,
1e-12);
......@@ -274,7 +300,7 @@ public:
test_GetPropertyAsSingleValue_Returns_Expected_Single_Value_On_Successive_Calls_With_Different_Stat_Types() {
LogManager run;
const std::string name = "series";
addTestTimeSeries(run, name);
addTestTimeSeries<double>(run, name);
TS_ASSERT_EQUALS(run.getPropertyAsSingleValue(name, Math::Mean), 13.0);
TS_ASSERT_EQUALS(run.getPropertyAsSingleValue(name, Math::Mean), 13.0);
......@@ -308,7 +334,7 @@ public:
const std::string intProp("anIntProp");
runInfo.addProperty(intProp, 99);
const std::string tspProp("tsp");
addTestTimeSeries(runInfo, "tsp");
addTestTimeSeries<double>(runInfo, "tsp");
// Check it's set up right
TS_ASSERT_EQUALS(runInfo.getProperties().size(), 3);
......@@ -336,7 +362,7 @@ public:
const std::string intProp("anIntProp");
runInfo.addProperty(intProp, 99);
const std::string tspProp("tsp");
addTestTimeSeries(runInfo, "tsp");
addTestTimeSeries<double>(runInfo, "tsp");
// Check it's set up right
TS_ASSERT_EQUALS(runInfo.getProperties().size(), 3);
......@@ -412,6 +438,17 @@ public:
LogManager run3;
run3.loadNexus(th.file, "");
}
private:
template <typename T>
void doTest_GetPropertyAsSingleValue_SingleType(const T value) {
LogManager runInfo;
const std::string name = "T_prop";
runInfo.addProperty<T>(name, value);
double result = std::nan("1");
TS_ASSERT_THROWS_NOTHING(result = runInfo.getPropertyAsSingleValue(name));
TS_ASSERT_EQUALS(value, static_cast<T>(result));
}
};
//---------------------------------------------------------------------------------------
......@@ -428,7 +465,7 @@ public:
static void destroySuite(LogManagerTestPerformance *suite) { delete suite; }
LogManagerTestPerformance() : m_testRun(), m_propName("test") {
addTestTimeSeries(m_testRun, m_propName);
addTestTimeSeries<double>(m_testRun, m_propName);
}
void test_Accessing_Single_Value_From_Times_Series_A_Large_Number_Of_Times() {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment