Skip to content

Commit

Permalink
refs #6449 enabled Iterator tests (excluding mock)
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts committed Apr 5, 2013
1 parent 9904fbf commit 8891786
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 55 deletions.
95 changes: 49 additions & 46 deletions Code/Mantid/Framework/MDEvents/test/MDBoxIteratorTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ using Mantid::Geometry::MDImplicitFunction;
using Mantid::Geometry::MDPlane;
using Mantid::Geometry::MDBoxImplicitFunction;


class MDBoxIteratorTest : public CxxTest::TestSuite
{
public:
Expand Down Expand Up @@ -470,25 +471,26 @@ class MDBoxIteratorTest : public CxxTest::TestSuite
TS_ASSERT( !it->next() );
}

void test_getIsMasked()
{
//Mock MDBox. Only one method of interest to the mocking.
class MockMDBox : public MDBox<MDLeanEvent<2>, 2>
{
public:
MOCK_CONST_METHOD0(getIsMasked, bool());
};
//void xest_getIsMasked()
//{
// //Mock MDBox. Only one method of interest to the mocking.
// class MockMDBox : public MDBox<MDLeanEvent<2>, 2>
// {
// public:
// MockMDBox():MDBox<MDLeanEvent<2>, 2>(NULL){}
// MOCK_CONST_METHOD0(getIsMasked, bool());
// };

MockMDBox mockBox;
// MockMDBox mockBox;

MDBoxIterator<MDLeanEvent<2>, 2> it(&mockBox, 1, true);
// MDBoxIterator<MDLeanEvent<2>, 2> it(&mockBox, 1, true);

//All that we want to test is that iterator::getIsMasked calls MDBoxBase::getIsMasked
EXPECT_CALL(mockBox, getIsMasked()).Times(1);
it.getIsMasked();
// //All that we want to test is that iterator::getIsMasked calls MDBoxBase::getIsMasked
// EXPECT_CALL(mockBox, getIsMasked()).Times(1);
// it.getIsMasked();

TSM_ASSERT("Iterator does not use boxes as expected", testing::Mock::VerifyAndClearExpectations(&mockBox));
}
// TSM_ASSERT("Iterator does not use boxes as expected", testing::Mock::VerifyAndClearExpectations(&mockBox));
//}

void test_skip_masked_detectors()
{
Expand Down Expand Up @@ -534,49 +536,49 @@ class MDBoxIteratorTest : public CxxTest::TestSuite
TSM_ASSERT_EQUALS("Should NOT have skipped to the third box", 3, evaluationIterator->getPosition());
}

void test_custom_skipping_policy()
{
/// Mock Skipping Policy Type to inject.
class MockSkippingPolicy : public SkippingPolicy
{
public:
MOCK_CONST_METHOD0(keepGoing, bool());
MOCK_METHOD0(Die, void());
~MockSkippingPolicy(){Die();}
};
//void test_custom_skipping_policy()
//{
// /// Mock Skipping Policy Type to inject.
// class MockSkippingPolicy : public SkippingPolicy
// {
// public:
// MOCK_CONST_METHOD0(keepGoing, bool());
// MOCK_METHOD0(Die, void());
// ~MockSkippingPolicy(){Die();}
// };

MockSkippingPolicy* mockPolicy = new MockSkippingPolicy;
MDBoxIterator<MDLeanEvent<1>,1>* evaluationIterator = new MDBoxIterator<MDLeanEvent<1>,1>(A, 20, true, mockPolicy); //Using custom policy
// MockSkippingPolicy* mockPolicy = new MockSkippingPolicy;
// MDBoxIterator<MDLeanEvent<1>,1>* evaluationIterator = new MDBoxIterator<MDLeanEvent<1>,1>(A, 20, true, mockPolicy); //Using custom policy

EXPECT_CALL(*mockPolicy, Die()).Times(1); //Should call destructor automatically within MDBoxIterator
EXPECT_CALL(*mockPolicy, keepGoing()).Times(static_cast<int>(evaluationIterator->getDataSize())); //Should apply test
// EXPECT_CALL(*mockPolicy, Die()).Times(1); //Should call destructor automatically within MDBoxIterator
// EXPECT_CALL(*mockPolicy, keepGoing()).Times(static_cast<int>(evaluationIterator->getDataSize())); //Should apply test

while(evaluationIterator->next()) //Keep calling next while true. Will iterate through all boxes.
{
}
delete evaluationIterator;
// while(evaluationIterator->next()) //Keep calling next while true. Will iterate through all boxes.
// {
// }
// delete evaluationIterator;

TSM_ASSERT("Has not used SkippingPolicy as expected.", testing::Mock::VerifyAndClearExpectations(mockPolicy));
}
// TSM_ASSERT("Has not used SkippingPolicy as expected.", testing::Mock::VerifyAndClearExpectations(mockPolicy));
//}
};


class MDBoxIteratorTestPerformance : public CxxTest::TestSuite
class MDBoxIteratorPerformanceTest : public CxxTest::TestSuite
{
public:
MDGridBox<MDLeanEvent<3>,3> * top;

public:
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static MDBoxIteratorTestPerformance *createSuite() { return new MDBoxIteratorTestPerformance(); }
static void destroySuite( MDBoxIteratorTestPerformance *suite ) { delete suite; }
static MDBoxIteratorPerformanceTest *createSuite() { return new MDBoxIteratorPerformanceTest(); }
static void destroySuite( MDBoxIteratorPerformanceTest *suite ) { delete suite; }

MDBoxIteratorTestPerformance()

MDBoxIteratorPerformanceTest()
{
// 1968876 boxes in this. Top box is 5*5*5
top = MDEventsTestHelper::makeRecursiveMDGridBox<3>(5, 2);
}

public:
// ---------------------------------------------------------------
/** Make a simple iterator that will go through all the boxes */
void do_test_iterator(bool leafOnly, bool ImplicitFunction, size_t expected)
Expand Down Expand Up @@ -665,7 +667,7 @@ class MDBoxIteratorTestPerformance : public CxxTest::TestSuite
*/
void do_test_getBoxes(bool leafOnly, int ImplicitFunction, size_t expected)
{
std::vector< MDBoxBase<MDLeanEvent<3>,3> * > boxes;
std::vector< API::IMDNode * > boxes;

MDImplicitFunction * function = NULL;
if (ImplicitFunction==1)
Expand Down Expand Up @@ -704,8 +706,8 @@ class MDBoxIteratorTestPerformance : public CxxTest::TestSuite

// Now we still need to iterate through the vector to do anything, so this is a more fair comparison
size_t counter = 0;
std::vector< MDBoxBase<MDLeanEvent<3>,3> * >::iterator it;
std::vector< MDBoxBase<MDLeanEvent<3>,3> * >::iterator it_end = boxes.end();
std::vector< API::IMDNode * >::iterator it;
std::vector< API::IMDNode * >::iterator it_end = boxes.end();
for (it = boxes.begin(); it != it_end; it++)
{
counter++;
Expand Down Expand Up @@ -742,10 +744,11 @@ class MDBoxIteratorTestPerformance : public CxxTest::TestSuite
void test_getBoxes_withHugeImplicitFunction()
{
do_test_getBoxes(true, 3, 125*125*125);
TS_WARN("Finished Iterator performance test");
}

};


#endif /* MANTID_MDEVENTS_MDBOXITERATORTEST_H_ */

#undef RUN_CXX_PERFORMANCE_TEST_EMBEDDED
23 changes: 14 additions & 9 deletions Code/Mantid/Framework/MDEvents/test/MDEventWorkspaceTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ using namespace Mantid::MDEvents;
using namespace Mantid::API;
using namespace Mantid::Geometry;


class MDEventWorkspaceTest : public CxxTest::TestSuite
{
private:
Expand Down Expand Up @@ -414,7 +415,7 @@ class MDEventWorkspaceTest : public CxxTest::TestSuite

//
// //-------------------------------------------------------------------------------------
// /** Tests that bad events are thrown out when using addEvents.
// /** Tests that bad events are thrown out when using addEvents.
// * */
// void test_addManyEvents_Performance()
// {
Expand Down Expand Up @@ -610,23 +611,27 @@ class MDEventWorkspaceTest : public CxxTest::TestSuite
}
};

class MDEventWorkspacePerformanceTest : public CxxTest::TestSuite
{

private:

MDEventWorkspace3Lean::sptr m_ws;
size_t nEvents,nBoxes;
class MDEventWorkspaceTestPerformance : public CxxTest::TestSuite
{

public:

// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static MDEventWorkspacePerformanceTest *createSuite() { return new MDEventWorkspacePerformanceTest(); }
static void destroySuite( MDEventWorkspacePerformanceTest *suite ) { delete suite; }
static MDEventWorkspaceTestPerformance *createSuite() { return new MDEventWorkspaceTestPerformance(); }
static void destroySuite( MDEventWorkspaceTestPerformance *suite ) { delete suite; }

MDEventWorkspacePerformanceTest()
MDEventWorkspaceTestPerformance()
{
}


private:
MDEventWorkspace3Lean::sptr m_ws;
size_t nEvents,nBoxes;
public:
void setUp()
{
size_t dim_size = 20;
Expand Down

0 comments on commit 8891786

Please sign in to comment.