"Framework/git@code.ornl.gov:mantidproject/mantid.git" did not exist on "e36e12e74ac349878384a88eae5fc43e0e0403e2"
Newer
Older
Janik Zikovsky
committed
#ifndef MANTID_MDEVENTS_CREATEMDEVENTWORKSPACETEST_H_
#define MANTID_MDEVENTS_CREATEMDEVENTWORKSPACETEST_H_
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/IMDEventWorkspace.h"
#include "MantidKernel/System.h"
#include "MantidKernel/Timer.h"
#include "MantidMDEvents/MDEventFactory.h"
#include "MantidMDAlgorithms/CreateMDWorkspace.h"
#include "MantidAPI/FrameworkManager.h"
Janik Zikovsky
committed
#include <cxxtest/TestSuite.h>
#include <iomanip>
#include <iostream>
#include <Poco/File.h>
Janik Zikovsky
committed
using namespace Mantid::API;
using namespace Mantid::Geometry;
using namespace Mantid::MDEvents;
using namespace Mantid::MDAlgorithms;
Janik Zikovsky
committed
class CreateMDWorkspaceTest : public CxxTest::TestSuite
Janik Zikovsky
committed
{
public:
Janik Zikovsky
committed
Janik Zikovsky
committed
void test_Init()
{
CreateMDWorkspace alg;
Janik Zikovsky
committed
TS_ASSERT_THROWS_NOTHING( alg.initialize() )
TS_ASSERT( alg.isInitialized() )
}
Janik Zikovsky
committed
void test_default_properties()
{
TS_ASSERT( FrameworkManager::Instance().exec("CreateMDWorkspace", 10,
"OutputWorkspace","simple_md",
"Dimensions", "3",
"Extents", "-1,1,-2,2,3,3",
"Names", "One,Two,Three",
"Units", "One,Two,Three"
)->isExecuted() );
}
/** Validate bad inputs. */
void test_validation()
{
Janik Zikovsky
committed
TS_ASSERT( !FrameworkManager::Instance().exec("CreateMDWorkspace", 4,
"OutputWorkspace","failed_output",
"Dimensions", "0")->isExecuted() );
Janik Zikovsky
committed
TS_ASSERT( !FrameworkManager::Instance().exec("CreateMDWorkspace", 6,
"OutputWorkspace","failed_output",
"Dimensions", "3",
"Extents", "-1,1,-2,2")->isExecuted() );
Janik Zikovsky
committed
TS_ASSERT( !FrameworkManager::Instance().exec("CreateMDWorkspace", 6,
"OutputWorkspace","failed_output",
"Dimensions", "3",
"Extents", "-1,1,-2,2,3,3,4,4")->isExecuted() );
Janik Zikovsky
committed
TS_ASSERT( !FrameworkManager::Instance().exec("CreateMDWorkspace", 8,
"OutputWorkspace","failed_output",
"Dimensions", "3", "Extents", "-1,1,-2,2,3,3",
"Names", "One,Two")->isExecuted() );
Janik Zikovsky
committed
TS_ASSERT( !FrameworkManager::Instance().exec("CreateMDWorkspace", 12,
"OutputWorkspace","failed_output",
"Dimensions", "3", "Extents", "-1,1,-2,2,3,3",
"Names", "One,Two,Three",
"MinRecursionDepth", "5",
"MaxRecursionDepth", "4")->isExecuted() );
Janik Zikovsky
committed
// Uses too much memory
Janik Zikovsky
committed
TS_ASSERT( !FrameworkManager::Instance().exec("CreateMDWorkspace", 14,
Janik Zikovsky
committed
"OutputWorkspace","failed_output",
"Dimensions", "3", "Extents", "-1,1,-2,2,3,3",
"Names", "One,Two,Three",
"Units", "One,Two,Three",
"SplitInto", "10",
"MinRecursionDepth", "5",
"MaxRecursionDepth", "5")->isExecuted() );
}
void do_test_exec(std::string Filename, bool lean, int MinRecursionDepth=0, int expectedNumMDBoxes=216)
Janik Zikovsky
committed
{
std::string wsName = "CreateMDWorkspaceTest_out";
CreateMDWorkspace alg;
Janik Zikovsky
committed
TS_ASSERT_THROWS_NOTHING( alg.initialize() )
TS_ASSERT( alg.isInitialized() )
alg.setPropertyValue("Dimensions", "3");
Janik Zikovsky
committed
alg.setPropertyValue("EventType", lean ? "MDLeanEvent" : "MDEvent");
Janik Zikovsky
committed
alg.setPropertyValue("Extents", "-1,1,-2,2,-3,3");
alg.setPropertyValue("Names", "x,y,z");
alg.setPropertyValue("Units", "m,mm,um");
Janik Zikovsky
committed
alg.setPropertyValue("SplitInto", "6");
alg.setPropertyValue("SplitThreshold", "500");
alg.setProperty("MinRecursionDepth", MinRecursionDepth);
alg.setProperty("MaxRecursionDepth", 7);
Janik Zikovsky
committed
alg.setPropertyValue("OutputWorkspace",wsName);
alg.setPropertyValue("Filename", Filename);
alg.setPropertyValue("Memory", "1");
Janik Zikovsky
committed
TS_ASSERT_THROWS_NOTHING( alg.execute(); );
TS_ASSERT( alg.isExecuted() );
// Get it from data service
IMDEventWorkspace_sptr ws;
TS_ASSERT_THROWS_NOTHING(ws = boost::dynamic_pointer_cast<IMDEventWorkspace>( AnalysisDataService::Instance().retrieve(wsName) ));
TS_ASSERT( ws );
// Correct info?
TS_ASSERT_EQUALS( ws->getNumDims(), 3);
TS_ASSERT_EQUALS( ws->getNPoints(), 0);
Janik Zikovsky
committed
IMDDimension_const_sptr dim;
Janik Zikovsky
committed
dim = ws->getDimension(0);
TS_ASSERT_DELTA( dim->getMaximum(), 1.0, 1e-6);
TS_ASSERT_EQUALS( dim->getName(), "x");
TS_ASSERT_EQUALS( dim->getUnits(), "m");
Janik Zikovsky
committed
dim = ws->getDimension(1);
TS_ASSERT_DELTA( dim->getMaximum(), 2.0, 1e-6);
TS_ASSERT_EQUALS( dim->getName(), "y");
TS_ASSERT_EQUALS( dim->getUnits(), "mm");
Janik Zikovsky
committed
dim = ws->getDimension(2);
TS_ASSERT_DELTA( dim->getMaximum(), 3.0, 1e-6);
TS_ASSERT_EQUALS( dim->getName(), "z");
TS_ASSERT_EQUALS( dim->getUnits(), "um");
Janik Zikovsky
committed
// What about the box controller
Janik Zikovsky
committed
BoxController_sptr bc;
if (lean)
{
MDEventWorkspace3Lean::sptr ews = boost::dynamic_pointer_cast<MDEventWorkspace3Lean>(ws);
TS_ASSERT( ews ); if (!ews) return;
bc = ews->getBoxController();
}
else
{
MDEventWorkspace3::sptr ews = boost::dynamic_pointer_cast<MDEventWorkspace3>(ws);
TS_ASSERT( ews ); if (!ews) return;
bc = ews->getBoxController();
}
Janik Zikovsky
committed
TS_ASSERT( bc );
if (!bc) return;
TS_ASSERT_EQUALS(bc->getSplitInto(0), 6 );
TS_ASSERT_EQUALS(bc->getSplitThreshold(), 500 );
TS_ASSERT_EQUALS(bc->getMaxDepth(), 7 );
TS_ASSERT_EQUALS(bc->getTotalNumMDBoxes(), expectedNumMDBoxes);
if (Filename != "")
{
std::string s = alg.getPropertyValue("Filename");
TSM_ASSERT( "File for the back-end was created.", Poco::File(s).exists() );
std::cout << "Closing the file." << std::endl;
bc->closeFile();
if (Poco::File(s).exists()) Poco::File(s).remove();
Janik Zikovsky
committed
}
Janik Zikovsky
committed
void test_exec_MDEvent()
{
do_test_exec("", false);
}
void test_exec_MDEvent_fileBacked()
{
do_test_exec("CreateMDWorkspaceTest.nxs", false);
Janik Zikovsky
committed
}
void test_exec_MDLeanEvent()
Janik Zikovsky
committed
do_test_exec("", true);
Janik Zikovsky
committed
void test_exec_MDLeanEvent_fileBacked()
do_test_exec("CreateMDWorkspaceTest.nxs", true);
}
void test_exec_MinRecursionDepth()
{
do_test_exec("", true, 2, 216*216);
}
Janik Zikovsky
committed
};
#endif /* MANTID_MDEVENTS_CREATEMDEVENTWORKSPACETEST_H_ */