Skip to content

Commit

Permalink
Fix and add unit tests. Refs #6037.
Browse files Browse the repository at this point in the history
  • Loading branch information
wdzhou committed Oct 29, 2012
1 parent 40b8cce commit 50fbb28
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Code/Mantid/Framework/DataHandling/test/LoadEventNexusTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ class LoadEventNexusTest : public CxxTest::TestSuite
auto outWs = AnalysisDataService::Instance().retrieveWS<EventWorkspace>(wsName);

Property* prop = outWs->run().getLogData("SampleTemp");
TSM_ASSERT_EQUALS("Should have 14 elements after filtering.", 14, prop->size());
if(prop->size() != 14)
TSM_ASSERT_EQUALS("Should have 16 elements after filtering.", 16, prop->size());
if(prop->size() != 16)
return;
//Further tests
TimeSeriesProperty<double>* sampleTemps = dynamic_cast<TimeSeriesProperty<double>* >(prop);
auto filteredLogStartTime = sampleTemps->nthTime(0);
auto filteredLogEndTime = sampleTemps->nthTime(sampleTemps->size()-1);
TS_ASSERT_EQUALS("2010-Mar-25 16:09:31.511000032",filteredLogStartTime.toSimpleString());
TS_ASSERT_EQUALS("2010-Mar-25 16:11:41.558003540",filteredLogEndTime.toSimpleString());
TS_ASSERT_EQUALS("2010-Mar-25 16:09:27.620000000",filteredLogStartTime.toSimpleString());
TS_ASSERT_EQUALS("2010-Mar-25 16:11:51.558003540",filteredLogEndTime.toSimpleString());
}

public:
Expand Down
30 changes: 30 additions & 0 deletions Code/Mantid/Framework/Kernel/test/TimeSeriesPropertyTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,36 @@ class TimeSeriesPropertyTest : public CxxTest::TestSuite
TSM_ASSERT_EQUALS("Filtering by Median Time is not working.", expectedFilteredValue, actualFilteredValue);
}

//----------------------------------------------------------------------------

/** A test for filter nothing
*/
void test_filterByTime_out_of_range_filters_nothing()
{
TimeSeriesProperty<int> * log = new TimeSeriesProperty<int>("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) );

size_t original_size = log->realSize();

TS_ASSERT_EQUALS(original_size, 6);

DateAndTime start = DateAndTime("2007-11-30T15:00:00"); // Much earlier than first time series value
DateAndTime stop = DateAndTime("2007-11-30T17:00:00"); // Much later than last time series value

log->filterByTime(start, stop);

TSM_ASSERT_EQUALS("Shouldn't be filtering anything!", original_size, log->realSize());

delete log;
}


private:
TimeSeriesProperty<int> *iProp;
TimeSeriesProperty<double> *dProp;
Expand Down

0 comments on commit 50fbb28

Please sign in to comment.