Skip to content

Commit

Permalink
refs #7200 Unit tests for MDBoxFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts committed May 29, 2013
1 parent fe8994a commit 31700d3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Code/Mantid/Framework/MDEvents/src/MDEventFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,16 @@ namespace Mantid
throw std::invalid_argument(" there are more dimensions requested then instantiated");

size_t id = nDimensions*MDEventFactory::NumBoxTypes + Type;
if(extentsVector.size()!=nDimensions) // set defaults
{
std::vector<Mantid::Geometry::MDDimensionExtents<coord_t> > defaultExtents(nDimensions);
for(size_t i=0;i<nDimensions;i++)
{
defaultExtents[i].setExtents(-FLT_MAX,FLT_MAX);
}
return (*(boxCreatorFP[id]))(splitter.get(),defaultExtents,depth,nBoxEvents,boxID);
}


return (*(boxCreatorFP[id]))(splitter.get(),extentsVector,depth,nBoxEvents,boxID);
}
Expand Down
39 changes: 39 additions & 0 deletions Code/Mantid/Framework/MDEvents/test/MDEventFactoryTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <MantidMDEvents/MDEventFactory.h>


using namespace Mantid::MDEvents;
using namespace Mantid::API;

Expand All @@ -31,6 +32,44 @@ class MDEventFactoryTest : public CxxTest::TestSuite
}


void test_box_factory()
{
BoxController_sptr bc = boost::shared_ptr<BoxController>(new BoxController(4));

IMDNode *Box = MDEventFactory::createBox(4,MDEventFactory::BoxType::MDBoxWithLean,bc);
TS_ASSERT_EQUALS( Box->getNumDims(), 4);
MDBox<MDLeanEvent<4>,4>* leanBox = dynamic_cast<MDBox<MDLeanEvent<4>,4>*>(Box);
TS_ASSERT(leanBox!=NULL);
delete Box;

bc.reset(new BoxController(9));
Box = MDEventFactory::createBox(9,MDEventFactory::BoxType::MDBoxWithFat,bc);
TS_ASSERT_EQUALS( Box->getNumDims(), 9);
MDBox<MDEvent<9>,9>* fatBox = dynamic_cast<MDBox<MDEvent<9>,9>*>(Box);
TS_ASSERT(fatBox!=NULL);
delete Box;



bc.reset(new BoxController(3));
Box = MDEventFactory::createBox(3,MDEventFactory::BoxType::MDGridBoxWithLean,bc);
TS_ASSERT_EQUALS( Box->getNumDims(), 3);
MDGridBox<MDLeanEvent<3>,3>* leanGridBox = dynamic_cast<MDGridBox<MDLeanEvent<3>,3>*>(Box);
TS_ASSERT(leanGridBox!=NULL);
delete Box;

bc.reset(new BoxController(1));
Box = MDEventFactory::createBox(1,MDEventFactory::BoxType::MDGridBoxWithFat,bc);
TS_ASSERT_EQUALS( Box->getNumDims(), 1);
MDGridBox<MDEvent<1>,1>* fatGridBox = dynamic_cast<MDGridBox<MDEvent<1>,1>*>(Box);
TS_ASSERT(fatGridBox!=NULL);
delete Box;

TS_ASSERT_THROWS(MDEventFactory::createBox(0,MDEventFactory::BoxType::MDBoxWithLean,bc), std::invalid_argument);
TS_ASSERT_THROWS(MDEventFactory::createBox(10,MDEventFactory::BoxType::MDGridBoxWithFat,bc), std::invalid_argument);
}


// Templated function that will be called for a specific MDEW
template<typename MDE, size_t nd>
void functionTest(typename MDEventWorkspace<MDE, nd>::sptr ws)
Expand Down

0 comments on commit 31700d3

Please sign in to comment.