Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/bugfix/8358_dataobjects_test_mem…
Browse files Browse the repository at this point in the history
…ory_leaks'
  • Loading branch information
wdzhou committed May 2, 2014
2 parents 28c03aa + dc98709 commit 6f0cc73
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 108 deletions.
130 changes: 65 additions & 65 deletions Code/Mantid/Framework/DataObjects/test/EventListTest.h
Expand Up @@ -345,8 +345,10 @@ class EventListTest : public CxxTest::TestSuite
//Put a single big bin with all events
lhs.setX(one_big_bin() );
//But the total neutrons is 0.0! They've been cancelled out :)
TS_ASSERT_DELTA( (*lhs.makeDataY())[0], 0.0, 1e-6);
TS_ASSERT_DELTA( (*lhs.makeDataE())[0], sqrt((double)lhs.getNumberEvents()), 1e-6);
boost::scoped_ptr<MantidVec> Y(lhs.makeDataY());
boost::scoped_ptr<MantidVec> E(lhs.makeDataE());
TS_ASSERT_DELTA( (*Y)[0], 0.0, 1e-6);
TS_ASSERT_DELTA( (*E)[0], sqrt((double)lhs.getNumberEvents()), 1e-6);
}
}
}
Expand All @@ -373,8 +375,10 @@ class EventListTest : public CxxTest::TestSuite
//Put a single big bin with all events
lhs.setX(one_big_bin() );
//But the total neutrons is 0.0! They've been cancelled out :)
TS_ASSERT_DELTA( (*lhs.makeDataY())[0], 0.0, 1e-6);
TS_ASSERT_DELTA( (*lhs.makeDataE())[0], sqrt((double)lhs.getNumberEvents()), 1e-6);
boost::scoped_ptr<MantidVec> Y(lhs.makeDataY());
boost::scoped_ptr<MantidVec> E(lhs.makeDataE());
TS_ASSERT_DELTA( (*Y)[0], 0.0, 1e-6);
TS_ASSERT_DELTA( (*E)[0], sqrt((double)lhs.getNumberEvents()), 1e-6);
}
}

Expand Down Expand Up @@ -871,18 +875,18 @@ class EventListTest : public CxxTest::TestSuite
const EventList el2(el);

//Getting data before setting X returns empty vector
TS_ASSERT_EQUALS(el2.makeDataY()->size(), 0);
boost::scoped_ptr<MantidVec> Y2(el2.makeDataY());
TS_ASSERT_EQUALS(Y2->size(), 0);

//Now do set up an X axis.
this->test_setX();
MantidVec X, Y;
const EventList el3(el);
X = el3.constDataX();
Y = *el3.makeDataY();
MantidVec X = el3.constDataX();
boost::scoped_ptr<MantidVec> Y3(el3.makeDataY());
//Histogram is 0, since I cleared all the events
for (std::size_t i=0; i<X.size()-1; i++)
{
TS_ASSERT_EQUALS(Y[i], 0);
TS_ASSERT_EQUALS((*Y3)[i], 0);
}
}

Expand All @@ -893,7 +897,8 @@ class EventListTest : public CxxTest::TestSuite
//Now give it some fake data, with NUMEVENTS events in it.
this->fake_data();
const EventList el4(el);
TS_ASSERT_EQUALS(el4.makeDataY()->size(), 0);
boost::scoped_ptr<MantidVec> Y(el4.makeDataY());
TS_ASSERT_EQUALS(Y->size(), 0);
}

void test_histogram_all_types()
Expand All @@ -905,18 +910,17 @@ class EventListTest : public CxxTest::TestSuite
el.switchTo(static_cast<EventType>(this_type));

this->test_setX(); //Set it up
MantidVec X, Y, E;
const EventList el3(el); //need to copy to a const method in order to access the data directly.
X = el3.constDataX();
Y = *el3.makeDataY();
E = *el3.makeDataE();
TS_ASSERT_EQUALS(Y.size(), X.size()-1);
MantidVec X = el3.constDataX();
boost::scoped_ptr<MantidVec> Y(el3.makeDataY());
boost::scoped_ptr<MantidVec> E(el3.makeDataE());
TS_ASSERT_EQUALS(Y->size(), X.size()-1);
//The data was created so that there should be exactly 2 events per bin
// The last bin entry will be 0 since we use it as the top boundary of i-1.
for (std::size_t i=0; i<Y.size(); i++)
for (std::size_t i=0; i<Y->size(); i++)
{
TS_ASSERT_EQUALS(Y[i], 2.0);
TS_ASSERT_DELTA(E[i], sqrt(2.0), 1e-5);
TS_ASSERT_EQUALS((*Y)[i], 2.0);
TS_ASSERT_DELTA((*E)[i], sqrt(2.0), 1e-5);
}
}
}
Expand Down Expand Up @@ -999,18 +1003,17 @@ class EventListTest : public CxxTest::TestSuite

TS_ASSERT_EQUALS( el.getEventType(), WEIGHTED );

MantidVec X, Y, E;
const EventList el3(el); //need to copy to a const method in order to access the data directly.
X = el3.constDataX();
Y = *el3.makeDataY();
E = *el3.makeDataE();
TS_ASSERT_EQUALS(Y.size(), X.size()-1);
for (std::size_t i=0; i<Y.size(); i++)
MantidVec X = el3.constDataX();
boost::scoped_ptr<MantidVec> Y(el3.makeDataY());
boost::scoped_ptr<MantidVec> E(el3.makeDataE());
TS_ASSERT_EQUALS(Y->size(), X.size()-1);
for (std::size_t i=0; i<Y->size(); i++)
{
// 5 events, each with a weight of 3.2
TS_ASSERT_DELTA(Y[i], 5 * 3.2, 1e-6);
TS_ASSERT_DELTA((*Y)[i], 5 * 3.2, 1e-6);
// Error should be scaled the same, by a factor of 3.2 - maintaining the same signal/error ratio.
TS_ASSERT_DELTA(E[i], sqrt((double)5.0) * 3.2, 1e-6);
TS_ASSERT_DELTA((*E)[i], sqrt((double)5.0) * 3.2, 1e-6);
}
}

Expand All @@ -1020,19 +1023,18 @@ class EventListTest : public CxxTest::TestSuite
this->fake_uniform_data_weights();

this->test_setX(); //Set it up
MantidVec X, Y, E;
const EventList el3(el); //need to copy to a const method in order to access the data directly.
X = el3.constDataX();
Y = *el3.makeDataY();
E = *el3.makeDataE();
TS_ASSERT_EQUALS(Y.size(), X.size()-1);
MantidVec X = el3.constDataX();
boost::scoped_ptr<MantidVec> Y(el3.makeDataY());
boost::scoped_ptr<MantidVec> E(el3.makeDataE());
TS_ASSERT_EQUALS(Y->size(), X.size()-1);
//The data was created so that there should be exactly 2 events per bin
// The last bin entry will be 0 since we use it as the top boundary of i-1.
for (std::size_t i=0; i<Y.size(); i++)
for (std::size_t i=0; i<Y->size(); i++)
{
TS_ASSERT_EQUALS(Y[i], 4.0);
TS_ASSERT_EQUALS((*Y)[i], 4.0);
//Two errors of (2.5) adds up to sqrt(2 * 2.5*2.5)
TS_ASSERT_DELTA(E[i], sqrt(2 * 2.5*2.5), 1e-5);
TS_ASSERT_DELTA((*E)[i], sqrt(2 * 2.5*2.5), 1e-5);
}
}

Expand All @@ -1050,16 +1052,15 @@ class EventListTest : public CxxTest::TestSuite
el.setX(shared_x);

//Get them back
MantidVec X, Y;
const EventList el3(el); //need to copy to a const method in order to access the data directly.
X = el3.constDataX();
Y = *el3.makeDataY();
TS_ASSERT_EQUALS(Y.size(), X.size()-1);
MantidVec X = el3.constDataX();
boost::scoped_ptr<MantidVec> Y(el3.makeDataY());
TS_ASSERT_EQUALS(Y->size(), X.size()-1);

//The data was created so that there should be exactly 2 events per bin. The first 10 bins (20 events) are empty.
for (std::size_t i=0; i<Y.size(); i++)
for (std::size_t i=0; i<Y->size(); i++)
{
TS_ASSERT_EQUALS(Y[i], 2.0);
TS_ASSERT_EQUALS((*Y)[i], 2.0);
}
}

Expand All @@ -1072,31 +1073,29 @@ class EventListTest : public CxxTest::TestSuite
for (double tof=BIN_DELTA*10; tof<BIN_DELTA*(NUMBINS+1); tof += BIN_DELTA)
shared_x.push_back(tof);
el.setX(shared_x);
MantidVec X, Y;
const EventList el3(el); //need to copy to a const method in order to access the data directly.
X = el3.constDataX();
Y = *el3.makeDataY();
TS_ASSERT_EQUALS(Y.size(), X.size()-1);
for (std::size_t i=0; i<Y.size(); i++)
MantidVec X = el3.constDataX();
boost::scoped_ptr<MantidVec> Y(el3.makeDataY());
TS_ASSERT_EQUALS(Y->size(), X.size()-1);
for (std::size_t i=0; i<Y->size(); i++)
{
TS_ASSERT_EQUALS(Y[i], 4.0);
TS_ASSERT_EQUALS((*Y)[i], 4.0);
}
}

void test_random_histogram()
{
this->fake_data();
this->test_setX();
MantidVec X, Y;
const EventList el3(el);
X = el3.constDataX();
Y = *el3.makeDataY();
TS_ASSERT_EQUALS(Y.size(), X.size()-1);
MantidVec X = el3.constDataX();
boost::scoped_ptr<MantidVec> Y(el3.makeDataY());
TS_ASSERT_EQUALS(Y->size(), X.size()-1);
for (std::size_t i=0; i<X.size()-1; i++)
{
//No data was generated above 10 ms.
if (X[i] > 10e6)
TS_ASSERT_EQUALS(Y[i], 0.0);
TS_ASSERT_EQUALS((*Y)[i], 0.0);
}
}

Expand Down Expand Up @@ -1348,27 +1347,27 @@ class EventListTest : public CxxTest::TestSuite
//-----------------------------------------------------------------------------------------------
void test_convertUnitsViaTof_failures()
{
Unit * fromUnit = new DummyUnit1();
Unit * toUnit = new DummyUnit2();
DummyUnit1 fromUnit;
DummyUnit2 toUnit;
TS_ASSERT_THROWS_ANYTHING(el.convertUnitsViaTof(NULL,NULL));
// Not initalized
TS_ASSERT_THROWS_ANYTHING(el.convertUnitsViaTof(fromUnit,toUnit));
TS_ASSERT_THROWS_ANYTHING(el.convertUnitsViaTof(&fromUnit,&toUnit));
}

//-----------------------------------------------------------------------------------------------
void test_convertUnitsViaTof_allTypes()
{
Unit * fromUnit = new DummyUnit1();
Unit * toUnit = new DummyUnit2();
fromUnit->initialize(1,2,3,4,5,6);
toUnit->initialize(1,2,3,4,5,6);
DummyUnit1 fromUnit;
DummyUnit2 toUnit;
fromUnit.initialize(1,2,3,4,5,6);
toUnit.initialize(1,2,3,4,5,6);
// Go through each possible EventType as the input
for (int this_type=0; this_type<3; this_type++)
{
this->fake_uniform_data();
el.switchTo(static_cast<EventType>(this_type));
size_t old_num = this->el.getNumberEvents();
this->el.convertUnitsViaTof(fromUnit, toUnit);
this->el.convertUnitsViaTof(&fromUnit, &toUnit);
//Unchanged size
TS_ASSERT_EQUALS(old_num, this->el.getNumberEvents());
//Original tofs were 100, 5100, 10100, etc.). This becomes x * 200.
Expand Down Expand Up @@ -1629,6 +1628,8 @@ class EventListTest : public CxxTest::TestSuite

TS_ASSERT_EQUALS( outputs[0]->getEventType(), curType);
}

for (size_t i=0; i<10; i++) delete outputs[i];
}
}

Expand All @@ -1638,9 +1639,7 @@ class EventListTest : public CxxTest::TestSuite
{
this->fake_uniform_time_data();

std::vector< EventList * > outputs;
for (size_t i=0; i<1; i++)
outputs.push_back( new EventList() );
std::vector< EventList * > outputs(1, new EventList());

TimeSplitterType split;
split.push_back( SplittingInterval(100, 200, 0) );
Expand All @@ -1650,8 +1649,8 @@ class EventListTest : public CxxTest::TestSuite
el.splitByTime(split, outputs);

//No events in the first ouput 0-99
TS_ASSERT_EQUALS( outputs[0]->getNumberEvents(), 150);

TS_ASSERT_EQUALS( outputs.front()->getNumberEvents(), 150);
delete outputs.front();
}


Expand Down Expand Up @@ -1814,7 +1813,6 @@ class EventListTest : public CxxTest::TestSuite

el.switchTo(static_cast<EventType>(this_type));

// int num_old = el.getNumberEvents();
double mult = 1.0;
if (this_type > 0)
{
Expand Down Expand Up @@ -1853,6 +1851,8 @@ class EventListTest : public CxxTest::TestSuite
// Now the memory must be well used
TS_ASSERT_EQUALS( el_out->getWeightedEventsNoTime().capacity(), 3);
}

if ( !inplace ) delete el_out;
}// inplace
}// starting event type
}
Expand Down
25 changes: 14 additions & 11 deletions Code/Mantid/Framework/DataObjects/test/EventWorkspaceTest.h
Expand Up @@ -173,8 +173,10 @@ class EventWorkspaceTest : public CxxTest::TestSuite
//Are the returned arrays the right size?
const EventList el(ew->getEventList(1));
TS_ASSERT_EQUALS( el.constDataX().size(), NUMBINS);
TS_ASSERT_EQUALS( el.makeDataY()->size(), NUMBINS-1);
TS_ASSERT_EQUALS( el.makeDataE()->size(), NUMBINS-1);
boost::scoped_ptr<MantidVec> Y(el.makeDataY());
boost::scoped_ptr<MantidVec> E(el.makeDataE());
TS_ASSERT_EQUALS( Y->size(), NUMBINS-1);
TS_ASSERT_EQUALS( E->size(), NUMBINS-1);
TS_ASSERT( el.hasDetectorID(1) );
}

Expand Down Expand Up @@ -249,10 +251,10 @@ class EventWorkspaceTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS( el.constDataX().size(), 2);
TS_ASSERT_EQUALS( el.constDataX()[0], 0.0);
TS_ASSERT_EQUALS( el.constDataX()[1], std::numeric_limits<double>::min());
MantidVec* Y = el.makeDataY();
boost::scoped_ptr<MantidVec> Y(el.makeDataY());
TS_ASSERT_EQUALS( Y->size(), 1);
TS_ASSERT_EQUALS( (*Y)[0], 0.0);
MantidVec* E = el.makeDataE();
boost::scoped_ptr<MantidVec> E(el.makeDataE());
TS_ASSERT_EQUALS( E->size(), 1);
TS_ASSERT_EQUALS( (*E)[0], 0.0);
}
Expand Down Expand Up @@ -401,19 +403,20 @@ class EventWorkspaceTest : public CxxTest::TestSuite
//Are the returned arrays the right size?
TS_ASSERT_EQUALS( el.constDataX().size(), NUMBINS/2);

MantidVec & Y = (*el.makeDataY());
MantidVec & E = (*el.makeDataE());
TS_ASSERT_EQUALS( Y.size(), NUMBINS/2-1);
TS_ASSERT_EQUALS( E.size(), NUMBINS/2-1);
boost::scoped_ptr<MantidVec> Y(el.makeDataY());
boost::scoped_ptr<MantidVec> E(el.makeDataE());
TS_ASSERT_EQUALS( Y->size(), NUMBINS/2-1);
TS_ASSERT_EQUALS( E->size(), NUMBINS/2-1);

//Now there are 4 events in each bin
TS_ASSERT_EQUALS( Y[0], 4);
TS_ASSERT_EQUALS( Y[NUMBINS/2-2], 4);
TS_ASSERT_EQUALS( (*Y)[0], 4);
TS_ASSERT_EQUALS( (*Y)[NUMBINS/2-2], 4);

//But pixel 1 is the same, 2 events in the bin
const EventList el1(ew->getEventList(1));
TS_ASSERT_EQUALS( el1.constDataX()[1], BIN_DELTA*1);
TS_ASSERT_EQUALS( (*el1.makeDataY())[1], 2);
boost::scoped_ptr<MantidVec> Y1(el1.makeDataY());
TS_ASSERT_EQUALS( (*Y1)[1], 2);
}


Expand Down

0 comments on commit 6f0cc73

Please sign in to comment.