From be398aa9a963f9dc9a8800fd9af338cc90188704 Mon Sep 17 00:00:00 2001 From: Russell Taylor Date: Tue, 11 Dec 2012 17:34:14 -0500 Subject: [PATCH] Re #6267. Allow default values for min/max log value. Can now leave MinimumValue or MaximumValue empty in FilterByLogValue and the filter will be one-sided on the value that is given. Required addition of minValue & maxValue methods on TimeSeriesProperty. --- .../Algorithms/src/FilterByLogValue.cpp | 8 +- .../Algorithms/src/SumEventsByLogValue.cpp | 13 +- .../Algorithms/test/FilterByLogValueTest.h | 62 +++++-- .../inc/MantidKernel/TimeSeriesProperty.h | 9 + .../Kernel/src/TimeSeriesProperty.cpp | 32 +++- .../Kernel/test/TimeSeriesPropertyTest.h | 161 ++++++------------ 6 files changed, 154 insertions(+), 131 deletions(-) diff --git a/Code/Mantid/Framework/Algorithms/src/FilterByLogValue.cpp b/Code/Mantid/Framework/Algorithms/src/FilterByLogValue.cpp index 23cda108f7b1..c9db2e4e395b 100644 --- a/Code/Mantid/Framework/Algorithms/src/FilterByLogValue.cpp +++ b/Code/Mantid/Framework/Algorithms/src/FilterByLogValue.cpp @@ -165,9 +165,9 @@ void FilterByLogValue::exec() // Get the properties. double min = getProperty("MinimumValue"); double max = getProperty("MaximumValue"); - double tolerance = getProperty("TimeTolerance"); - std::string logname = getPropertyValue("LogName"); - bool PulseFilter = getProperty("PulseFilter"); + const double tolerance = getProperty("TimeTolerance"); + const std::string logname = getPropertyValue("LogName"); + const bool PulseFilter = getProperty("PulseFilter"); // Find the start and stop times of the run, but handle it if they are not found. DateAndTime run_start(0), run_stop("2100-01-01"); @@ -208,8 +208,6 @@ void FilterByLogValue::exec() else { // ----- Filter by value ------ - if (max < min) - throw std::invalid_argument("MaximumValue should be >= MinimumValue. Aborting."); //This function creates the splitter vector we will use to filter out stuff. const std::string logBoundary(this->getPropertyValue("LogBoundary")); diff --git a/Code/Mantid/Framework/Algorithms/src/SumEventsByLogValue.cpp b/Code/Mantid/Framework/Algorithms/src/SumEventsByLogValue.cpp index 11166987c87e..3b2eeaf725f1 100644 --- a/Code/Mantid/Framework/Algorithms/src/SumEventsByLogValue.cpp +++ b/Code/Mantid/Framework/Algorithms/src/SumEventsByLogValue.cpp @@ -64,9 +64,8 @@ namespace Algorithms // This is the int log version that ignores binning parameters and has a data point per log value // TODO: add the ability to specify binning for integer logs - const auto values = intLog->valuesAsVector(); - const int minVal = *std::min_element(values.begin(),values.end()); - const int maxVal = *std::max_element(values.begin(),values.end()); + const int minVal = intLog->minValue(); + const int maxVal = intLog->maxValue(); const int xLength = maxVal - minVal + 1; // Create a point-like workspace to hold the sum. The factory will give back a Workspace2Ds MatrixWorkspace_sptr outputWorkspace = WorkspaceFactory::Instance().create(inputWorkspace,1,xLength,xLength); @@ -116,13 +115,9 @@ namespace Algorithms // If only the number of bins was given, add the min & max values of the log if ( binningParams.size() == 1 ) { - // TODO: Move determination of min/max into property itself - const auto values = dblLog->valuesAsVector(); - const double minVal = *std::min_element(values.begin(),values.end()); - const double maxVal = *std::max_element(values.begin(),values.end()); // TODO: What if min & max are the same (for example if there's only one entry in the property) - binningParams.insert(binningParams.begin(),minVal); - binningParams.push_back(maxVal*1.000001); // Make it a tiny bit larger to cover full range + binningParams.insert( binningParams.begin(), dblLog->minValue() ); + binningParams.push_back(dblLog->maxValue()*1.000001); // Make it a tiny bit larger to cover full range } MantidVec XValues; const int XLength = VectorHelper::createAxisFromRebinParams(binningParams, XValues); diff --git a/Code/Mantid/Framework/Algorithms/test/FilterByLogValueTest.h b/Code/Mantid/Framework/Algorithms/test/FilterByLogValueTest.h index 3495b1b91d67..c037f71e9b20 100644 --- a/Code/Mantid/Framework/Algorithms/test/FilterByLogValueTest.h +++ b/Code/Mantid/Framework/Algorithms/test/FilterByLogValueTest.h @@ -184,17 +184,9 @@ class FilterByLogValueTest : public CxxTest::TestSuite * temp = 10 C at 10 sec up to 50C at 50 sec, every 10 seconds * press = -10 seconds to +150 seconds, every 10 seconds * - * @param log_name - * @param min - * @param max - * @param seconds_kept * @param add_proton_charge - * @param do_in_place - * @param PulseFilter :: PulseFilter parameter */ - void do_test_fake(std::string log_name, double min, double max, int seconds_kept, - bool add_proton_charge = true, bool do_in_place = false, - bool PulseFilter = false) + EventWorkspace_sptr createInputWS(bool add_proton_charge = true) { // Default Event Workspace with times from 0-99 EventWorkspace_sptr ew = WorkspaceCreationHelper::CreateEventWorkspace2(); @@ -243,10 +235,27 @@ class FilterByLogValueTest : public CxxTest::TestSuite // Finalize the needed stuff WorkspaceCreationHelper::EventWorkspace_Finalize(ew); + return ew; + } + + /** Run the algorithm on a workspace generated by createInputWS() + * + * @param log_name + * @param min + * @param max + * @param seconds_kept + * @param add_proton_charge + * @param do_in_place + * @param PulseFilter :: PulseFilter parameter + */ + void do_test_fake(std::string log_name, double min, double max, int seconds_kept, + bool add_proton_charge = true, bool do_in_place = false, + bool PulseFilter = false) + { + EventWorkspace_sptr ew = createInputWS(add_proton_charge); std::string inputName = "input_filtering"; AnalysisDataService::Instance().addOrReplace(inputName, boost::dynamic_pointer_cast(ew) ); - // Save some of the starting values size_t start_blocksize = ew->blocksize(); size_t num_events = ew->getNumberEvents(); @@ -385,6 +394,39 @@ class FilterByLogValueTest : public CxxTest::TestSuite do_test_fake("single_middle", 0, 0, 99, true, false /* not in place*/, true /*PulseFilter*/); } + std::size_t min_max_helper(bool useMin, bool useMax, double min, double max) + { + FilterByLogValue alg; + alg.initialize(); + alg.setChild(true); + alg.setProperty("InputWorkspace",createInputWS()); + alg.setProperty("OutputWorkspace","dontmatter"); + alg.setProperty("LogName","press"); + alg.setProperty("LogBoundary","Left"); + if ( useMin ) alg.setProperty("MinimumValue",min); + if ( useMax ) alg.setProperty("MaximumValue",max); + + TS_ASSERT( alg.execute() ); + + EventWorkspace_const_sptr outWS = alg.getProperty("OutputWorkspace"); + return outWS->getNumberEvents(); + } + + // Test that leaving one or both of MinimumValue & MaximumValue properties empty does the right thing + void test_default_min_max() + { + // Test that leaving both empty gives back an unchanged workspace + TS_ASSERT_EQUALS( min_max_helper(false,false,0.0,0.0), 10000 ); + // Test that setting min higher that max value in log wipes out all events + TS_ASSERT_EQUALS( min_max_helper(true,false,200.0,0.0), 0 ); + // Test that setting max lower that min value in log wipes out all events + TS_ASSERT_EQUALS( min_max_helper(false,true,0.0,-20.0), 0 ); + // Test that default max on it's own works for an in-range min + TS_ASSERT_EQUALS( min_max_helper(true,false,70.0,0.0), 3000 ); + // Test that default min on it's own works for an in-range max + TS_ASSERT_EQUALS( min_max_helper(false,true,0.0,70.0), 8000 ); + } + // // Very slow // void xtest_HYSPEC() // { diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/TimeSeriesProperty.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/TimeSeriesProperty.h index ea69758a96dc..5e0499e4e8b8 100644 --- a/Code/Mantid/Framework/Kernel/inc/MantidKernel/TimeSeriesProperty.h +++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/TimeSeriesProperty.h @@ -105,6 +105,10 @@ namespace Mantid return mvalue; } + static bool valueCmp(const TimeValueUnit& lhs, const TimeValueUnit& rhs) + { + return ( lhs.mvalue < rhs.mvalue ); + } }; //================================================================================================ @@ -199,6 +203,11 @@ namespace Mantid /// Returns the last value TYPE lastValue() const; + /// Returns the minimum value found in the series + TYPE minValue() const; + /// Returns the maximum value found in the series + TYPE maxValue() const; + /// Returns the number of values at UNIQUE time intervals in the time series int size() const; /// Returns the real size of the time series property map: diff --git a/Code/Mantid/Framework/Kernel/src/TimeSeriesProperty.cpp b/Code/Mantid/Framework/Kernel/src/TimeSeriesProperty.cpp index 6498454cbfa9..2831eb5bdb36 100644 --- a/Code/Mantid/Framework/Kernel/src/TimeSeriesProperty.cpp +++ b/Code/Mantid/Framework/Kernel/src/TimeSeriesProperty.cpp @@ -1,4 +1,5 @@ #include "MantidKernel/TimeSeriesProperty.h" +#include "MantidKernel/EmptyValues.h" #include "MantidKernel/Exception.h" #include @@ -440,6 +441,7 @@ namespace Mantid * Fill a TimeSplitterType that will filter the events by matching * log values >= min and <= max. Creates SplittingInterval's where * times match the log values, and going to index==0. + * This method is used by the FilterByLogValue algorithm. * * @param split :: Splitter that will be filled. * @param min :: min value @@ -450,7 +452,10 @@ namespace Mantid template void TimeSeriesProperty::makeFilterByValue(TimeSplitterType& split, double min, double max, double TimeTolerance, bool centre) const { - if ( max < min ) + const bool emptyMin = (min == EMPTY_DBL()); + const bool emptyMax = (max == EMPTY_DBL()); + + if ( !emptyMin && !emptyMax && max < min ) { std::stringstream ss; ss << "TimeSeriesProperty::makeFilterByValue: 'max' argument must be greater than 'min' " @@ -458,6 +463,10 @@ namespace Mantid throw std::invalid_argument(ss.str()); } + // If min or max were unset ("empty") in the algorithm, set to the min or max value of the log + if ( emptyMin ) min = minValue(); + if ( emptyMax ) max = maxValue(); + // Make sure the splitter starts out empty split.clear(); @@ -529,6 +538,7 @@ namespace Mantid /** If the first and/or last values in a log are between min & max, expand and existing TimeSplitter * (created by makeFilterByValue) if necessary to cover the full TimeInterval given. + * This method is used by the FilterByLogValue algorithm. * @param split The splitter to modify if necessary * @param min The minimum 'good' value * @param max The maximum 'good' value @@ -537,7 +547,10 @@ namespace Mantid template void TimeSeriesProperty::expandFilterToRange(TimeSplitterType& split, double min, double max, const TimeInterval & range) const { - if ( max < min ) + const bool emptyMin = (min == EMPTY_DBL()); + const bool emptyMax = (max == EMPTY_DBL()); + + if ( !emptyMin && !emptyMax && max < min ) { std::stringstream ss; ss << "TimeSeriesProperty::expandFilterToRange: 'max' argument must be greater than 'min' " @@ -545,6 +558,10 @@ namespace Mantid throw std::invalid_argument(ss.str()); } + // If min or max were unset ("empty") in the algorithm, set to the min or max value of the log + if ( emptyMin ) min = minValue(); + if ( emptyMax ) max = maxValue(); + // Assume everything before the 1st value is constant double val = firstValue(); if ((val >= min) && (val <= max)) @@ -795,6 +812,17 @@ namespace Mantid return m_values.rbegin()->value(); } + template + TYPE TimeSeriesProperty::minValue() const + { + return std::min_element(m_values.begin(),m_values.end(),TimeValueUnit::valueCmp)->value(); + } + + template + TYPE TimeSeriesProperty::maxValue() const + { + return std::max_element(m_values.begin(),m_values.end(),TimeValueUnit::valueCmp)->value(); + } /// Returns the number of values at UNIQUE time intervals in the time series /// @returns The number of unique time interfaces diff --git a/Code/Mantid/Framework/Kernel/test/TimeSeriesPropertyTest.h b/Code/Mantid/Framework/Kernel/test/TimeSeriesPropertyTest.h index 2e231b5a8b86..ccbb384ff749 100644 --- a/Code/Mantid/Framework/Kernel/test/TimeSeriesPropertyTest.h +++ b/Code/Mantid/Framework/Kernel/test/TimeSeriesPropertyTest.h @@ -15,6 +15,30 @@ using namespace Mantid::Kernel; class TimeSeriesPropertyTest : public CxxTest::TestSuite { + // Create a small TSP. Callee owns the returned object. + TimeSeriesProperty * createDoubleTSP() + { + TimeSeriesProperty * p = new TimeSeriesProperty("doubleProp"); + TS_ASSERT_THROWS_NOTHING( p->addValue("2007-11-30T16:17:00",9.99) ); + TS_ASSERT_THROWS_NOTHING( p->addValue("2007-11-30T16:17:10",7.55) ); + TS_ASSERT_THROWS_NOTHING( p->addValue("2007-11-30T16:17:20",5.55) ); + TS_ASSERT_THROWS_NOTHING( p->addValue("2007-11-30T16:17:30",10.55) ); + return p; + } + + // Create a small TSP. Callee owns the returned object. + TimeSeriesProperty * createIntegerTSP(int numberOfValues) + { + TimeSeriesProperty * log = new TimeSeriesProperty("intProp"); + DateAndTime startTime("2007-11-30T16:17:00"); + for ( int value = 0; value < numberOfValues; ++value) + { + DateAndTime time = startTime + value*10.0; + TS_ASSERT_THROWS_NOTHING( log->addValue(time,value+1) ); + } + return log; + } + public: void setUp() { @@ -185,9 +209,7 @@ class TimeSeriesPropertyTest : public CxxTest::TestSuite /// Ticket 2097: This caused an infinite loop void test_AdditionOperatorOnYourself() { - TimeSeriesProperty * log = new TimeSeriesProperty("MyIntLog"); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:00",1) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:10",2) ); + TimeSeriesProperty * log = createIntegerTSP(2); (*log) += log; // There is now a check and trying to do this does nothing. @@ -199,14 +221,7 @@ class TimeSeriesPropertyTest : public CxxTest::TestSuite //---------------------------------------------------------------------------- void test_filterByTime() { - TimeSeriesProperty * log = new TimeSeriesProperty("MyIntLog"); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:00",1) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:10",2) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:20",3) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:30",4) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:40",5) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:50",6) ); - + TimeSeriesProperty * log = createIntegerTSP(6); TS_ASSERT_EQUALS( log->realSize(), 6); DateAndTime start = DateAndTime("2007-11-30T16:17:10"); DateAndTime stop = DateAndTime("2007-11-30T16:17:40"); @@ -223,20 +238,7 @@ class TimeSeriesPropertyTest : public CxxTest::TestSuite //------------------------------------------------------------------------------- void test_filterByTimes1() { - TimeSeriesProperty * log = new TimeSeriesProperty("MyIntLog"); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:00",1) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:10",2) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:20",3) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:30",4) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:40",5) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:50",6) ); - /* - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:18:00",7) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:18:10",8) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:18:20",9) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:18:30",10) ); - */ - + TimeSeriesProperty * log = createIntegerTSP(6); TS_ASSERT_EQUALS( log->realSize(), 6); Mantid::Kernel::SplittingInterval interval0(DateAndTime("2007-11-30T16:17:10"), @@ -257,18 +259,7 @@ class TimeSeriesPropertyTest : public CxxTest::TestSuite void test_filterByTimesN() { - TimeSeriesProperty * log = new TimeSeriesProperty("MyIntLog"); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:00",1) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:10",2) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:20",3) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:30",4) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:40",5) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:50",6) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:18:00",7) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:18:10",8) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:18:20",9) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:18:30",10) ); - + TimeSeriesProperty * log = createIntegerTSP(10); TS_ASSERT_EQUALS( log->realSize(), 10); Mantid::Kernel::SplittingInterval interval0(DateAndTime("2007-11-30T16:17:10"), @@ -296,8 +287,7 @@ class TimeSeriesPropertyTest : public CxxTest::TestSuite /// Ticket #2591 void test_filterByTime_ifOnlyOneValue_assumes_constant_instead() { - TimeSeriesProperty * log = new TimeSeriesProperty("MyIntLog"); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:00",1) ); + TimeSeriesProperty * log = createIntegerTSP(1); TS_ASSERT_EQUALS( log->realSize(), 1); DateAndTime start = DateAndTime("2007-11-30T16:17:10"); @@ -463,29 +453,13 @@ class TimeSeriesPropertyTest : public CxxTest::TestSuite //---------------------------------------------------------------------------- void test_splitByTime_and_getTotalValue() { - TimeSeriesProperty * log = new TimeSeriesProperty("MyIntLog"); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:00",1) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:10",2) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:20",3) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:30",4) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:40",5) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:50",6) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:18:00",7) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:18:10",8) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:18:20",9) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:18:30",10) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:18:40",11) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:18:50",12) ); - TS_ASSERT_EQUALS( log->realSize(), 12); - + TimeSeriesProperty * log = createIntegerTSP(12); //Make the outputs - // std::vector< TimeSeriesProperty * > outputs2; std::vector< Property * > outputs; for (std::size_t i=0; i<5; i++) { TimeSeriesProperty * newlog = new TimeSeriesProperty("MyIntLog"); outputs.push_back(newlog); - //outputs2.push_back(newlog); } //Make a splitter @@ -531,23 +505,9 @@ class TimeSeriesPropertyTest : public CxxTest::TestSuite //---------------------------------------------------------------------------- void test_splitByTime_withOverlap() { - TimeSeriesProperty * log = new TimeSeriesProperty("MyIntLog"); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:00",1) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:10",2) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:20",3) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:30",4) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:40",5) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:50",6) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:18:00",7) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:18:10",8) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:18:20",9) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:18:30",10) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:18:40",11) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:18:50",12) ); - TS_ASSERT_EQUALS( log->realSize(), 12); + TimeSeriesProperty * log = createIntegerTSP(12); //Make the outputs - // std::vector< TimeSeriesProperty * > outputs2; std::vector< Property * > outputs; for (std::size_t i=0; i<1; i++) { @@ -664,11 +624,7 @@ class TimeSeriesPropertyTest : public CxxTest::TestSuite */ void test_getSingleValue() { - TimeSeriesProperty * p = new TimeSeriesProperty("doubleProp"); - TS_ASSERT_THROWS_NOTHING( p->addValue("2007-11-30T16:17:00",9.99) ); - TS_ASSERT_THROWS_NOTHING( p->addValue("2007-11-30T16:17:10",7.55) ); - TS_ASSERT_THROWS_NOTHING( p->addValue("2007-11-30T16:17:20",5.55) ); - TS_ASSERT_THROWS_NOTHING( p->addValue("2007-11-30T16:17:30",10.55) ); + TimeSeriesProperty * p = createDoubleTSP(); DateAndTime time1("2007-11-30T16:17:23"); double v1 = p->getSingleValue(time1); @@ -698,11 +654,7 @@ class TimeSeriesPropertyTest : public CxxTest::TestSuite */ void test_firstLastTimeValue() { - TimeSeriesProperty * p = new TimeSeriesProperty("doubleProp"); - TS_ASSERT_THROWS_NOTHING( p->addValue("2007-11-30T16:17:00",9.99) ); - TS_ASSERT_THROWS_NOTHING( p->addValue("2007-11-30T16:17:10",7.55) ); - TS_ASSERT_THROWS_NOTHING( p->addValue("2007-11-30T16:17:20",5.55) ); - TS_ASSERT_THROWS_NOTHING( p->addValue("2007-11-30T16:17:30",10.55) ); + TimeSeriesProperty * p = createDoubleTSP(); Mantid::Kernel::DateAndTime t0 = p->firstTime(); Mantid::Kernel::DateAndTime tf = p->lastTime(); @@ -724,20 +676,34 @@ class TimeSeriesPropertyTest : public CxxTest::TestSuite return; } + void test_min_max_value() + { + // Test a double property + const TimeSeriesProperty * p = createDoubleTSP(); + TS_ASSERT_EQUALS( p->minValue(), 5.55 ); + TS_ASSERT_EQUALS( p->maxValue(), 10.55 ); + + // Test an integer property + const TimeSeriesProperty * i = createIntegerTSP(8); + TS_ASSERT_EQUALS( i->minValue(), 1 ); + TS_ASSERT_EQUALS( i->maxValue(), 8 ); + + // Test a string property + sProp->addValue("2007-11-30T16:17:05","White"); + sProp->addValue("2007-12-30T16:17:15","Black"); + sProp->addValue("2008-11-30T16:18:05","Grey"); + TS_ASSERT_EQUALS( sProp->minValue(), "Black" ); + TS_ASSERT_EQUALS( sProp->maxValue(), "White" ); + } /* * Test merge() */ void test_Merge() { - TimeSeriesProperty *p1 = new TimeSeriesProperty("doubleProp1"); - TimeSeriesProperty *p2 = new TimeSeriesProperty("doubleProp2"); - // 1. Construct p1 and p2 - TS_ASSERT_THROWS_NOTHING( p1->addValue("2007-11-30T16:17:00",9.99) ); - TS_ASSERT_THROWS_NOTHING( p1->addValue("2007-11-30T16:17:10",7.55) ); - TS_ASSERT_THROWS_NOTHING( p1->addValue("2007-11-30T16:17:20",5.55) ); - TS_ASSERT_THROWS_NOTHING( p1->addValue("2007-11-30T16:17:30",10.55) ); + TimeSeriesProperty *p1 = createDoubleTSP(); + TimeSeriesProperty *p2 = new TimeSeriesProperty("doubleProp2"); TS_ASSERT_THROWS_NOTHING( p2->addValue("2007-11-30T16:17:05",19.99) ); TS_ASSERT_THROWS_NOTHING( p2->addValue("2007-11-30T16:17:15",17.55) ); @@ -772,10 +738,6 @@ class TimeSeriesPropertyTest : public CxxTest::TestSuite void test_Name() { TimeSeriesProperty * p = new TimeSeriesProperty("doubleProp"); - TS_ASSERT_THROWS_NOTHING( p->addValue("2007-11-30T16:17:00",9.99) ); - TS_ASSERT_THROWS_NOTHING( p->addValue("2007-11-30T16:17:10",7.55) ); - TS_ASSERT_THROWS_NOTHING( p->addValue("2007-11-30T16:17:20",5.55) ); - TS_ASSERT_THROWS_NOTHING( p->addValue("2007-11-30T16:17:30",10.55) ); std::string propertyname("UnitTest"); @@ -791,11 +753,7 @@ class TimeSeriesPropertyTest : public CxxTest::TestSuite */ void test_Value() { - TimeSeriesProperty * p = new TimeSeriesProperty("doubleProp"); - TS_ASSERT_THROWS_NOTHING( p->addValue("2007-11-30T16:17:00",9.99) ); - TS_ASSERT_THROWS_NOTHING( p->addValue("2007-11-30T16:17:10",7.55) ); - TS_ASSERT_THROWS_NOTHING( p->addValue("2007-11-30T16:17:20",5.55) ); - TS_ASSERT_THROWS_NOTHING( p->addValue("2007-11-30T16:17:30",10.55) ); + TimeSeriesProperty * p = createDoubleTSP(); std::string pvalue = p->value(); std::string svalue("2007-Nov-30 16:17:00 9.99\n2007-Nov-30 16:17:10 7.55\n2007-Nov-30 16:17:20 5.55\n2007-Nov-30 16:17:30 10.55\n"); @@ -1683,14 +1641,7 @@ class TimeSeriesPropertyTest : public CxxTest::TestSuite */ void test_filterByTime_out_of_range_filters_nothing() { - TimeSeriesProperty * log = new TimeSeriesProperty("MyIntLog"); - - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:00",1) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:10",2) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:20",3) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:30",4) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:40",5) ); - TS_ASSERT_THROWS_NOTHING( log->addValue("2007-11-30T16:17:50",6) ); + TimeSeriesProperty * log = createIntegerTSP(6); size_t original_size = log->realSize();