Skip to content

Commit

Permalink
refs #4201 Tests for alg ID components
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts committed Dec 5, 2011
1 parent d5a79ed commit bb2172a
Show file tree
Hide file tree
Showing 2 changed files with 206 additions and 8 deletions.
19 changes: 14 additions & 5 deletions Code/Mantid/Framework/MDAlgorithms/src/ConvertToMDEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@ ConvertToMDEvents::parseConvMode(const std::string &Q_MODE_ID,const std::string
convert_log.error() <<" Unknown unit"<<ws_dim_units[0]<<" along X-axis provided for conversion\n";
throw(std::invalid_argument("ConvertToMDEvents needs to known units conversion"));
}
}else{ // NoQ mode -- no conversion
CONV_MODE_ID =ConvModes[ConvertNo];
return CONV_MODE_ID;
}
// are the existing units already what is needed, so no conversion?
if(ws_dim_units[0].compare(natural_units)==0){
Expand Down Expand Up @@ -395,6 +398,12 @@ std::string
ConvertToMDEvents::parseDEMode(const std::string &Q_MODE_ID,const std::string &dE_mode_req,const Strings &ws_dim_units,Strings &out_dim_names,Strings &out_dim_units,
int &ndE_dims,std::string &natural_units)
{
if(is_member(dE_modes,dE_mode_req)<0){
convert_log.error()<<" dE-mode: "<<dE_mode_req<<" not recognized\n";
throw(std::invalid_argument(" Non-existing dE-mode"));
}
ndE_dims = 0;

std::string DE_MODE_ID= dE_mode_req;
// no_Q mode can only be compartible with no_dE mode
if((Q_MODE_ID.compare(Q_modes[NoQ])==0)){
Expand All @@ -409,8 +418,6 @@ ConvertToMDEvents::parseDEMode(const std::string &Q_MODE_ID,const std::string &d
out_dim_units.push_back("DeltaE");
// natural units defined in subalgorithm doing the conversion and their ID has to be defined correctly in class constructor
natural_units = native_inelastic_unitID;
}else{
ndE_dims = 0;
}

if(DE_MODE_ID.compare(dE_modes[Elastic])==0){
Expand All @@ -436,7 +443,11 @@ ConvertToMDEvents::parseDEMode(const std::string &Q_MODE_ID,const std::string &d
std::string
ConvertToMDEvents::parseQMode(const std::string &Q_mode_req,const Strings &ws_dim_names,const Strings &ws_dim_units,Strings &out_dim_names,Strings &out_dim_units, int &nQ_dims)
{
std::string Q_MODE_ID("Unknown");
std::string Q_MODE_ID("Unknown");
if(is_member(Q_modes,Q_mode_req)<0){
convert_log.error()<<" Q-mode: "<<Q_mode_req<<" not recognized\n";
throw(std::invalid_argument(" Non-existing Q-mode"));
}
// Q_mode (one of 3 possible)
if(Q_mode_req.compare(Q_modes[NoQ])==0)
{
Expand Down Expand Up @@ -469,8 +480,6 @@ ConvertToMDEvents::parseQMode(const std::string &Q_mode_req,const Strings &ws_di
return Q_MODE_ID;
}



/** function processes the input arguments and tries to establish what algorithm should be deployed;
*
* @param inWS2D -- input 2D workspace
Expand Down
195 changes: 192 additions & 3 deletions Code/Mantid/Framework/MDAlgorithms/test/ConvertToMDEventsTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ class Convert2AnyTestHelper: public ConvertToMDEvents
return ConvertToMDEvents::parseDEMode(Q_MODE_ID,dE_mode_req,ws_dim_units,out_dim_names,out_dim_units,ndE_dims,natural_units);

}

std::string parseConvMode(const std::string &Q_MODE_ID,const std::string &natural_units,const std::vector<std::string> &ws_dim_units){
return ConvertToMDEvents::parseConvMode(Q_MODE_ID,natural_units,ws_dim_units);
}


//std::string identify_requested_alg(const std::vector<std::string> &dim_names_availible, const std::string &QOption,const std::vector<std::string> &dim_selected,size_t &nDims)
Expand Down Expand Up @@ -97,12 +99,199 @@ void testInit(){

TSM_ASSERT_EQUALS("algortithm should have 8 propeties",8,(size_t)(pAlg->getProperties().size()));
}
// TEST QMode
void testParseQMode_WrongThrows()
{
std::vector<std::string> ws_dim_names;
std::vector<std::string> ws_dim_units;
std::vector<std::string> out_dim_names,out_dim_units;
int nQ_dims;
TS_ASSERT_THROWS(pAlg->parseQMode("WrongMode",ws_dim_names,ws_dim_units,out_dim_names,out_dim_units, nQ_dims),std::invalid_argument);

}
void testParseQMode_NoQ()
{
std::string MODE;
//MODE=pAlg->parseQMode("",const std::vector<std::string> &ws_dim_names,const std::vector<std::string> &ws_dim_units,
std::vector<std::string> ws_dim_names(2,"A");
std::vector<std::string> ws_dim_units(2,"UnA");
std::vector<std::string> out_dim_names,out_dim_units;
int nQ_dims;
std::string MODE;
TS_ASSERT_THROWS_NOTHING(MODE=pAlg->parseQMode("",ws_dim_names,ws_dim_units,out_dim_names,out_dim_units, nQ_dims));
TS_ASSERT_EQUALS(2,nQ_dims);
TS_ASSERT_EQUALS("",MODE);
TS_ASSERT_EQUALS(ws_dim_names[0],out_dim_names[0]);
TS_ASSERT_EQUALS(ws_dim_names[1],out_dim_names[1]);
TS_ASSERT_EQUALS(ws_dim_units[0],out_dim_units[0]);
TS_ASSERT_EQUALS(ws_dim_units[1],out_dim_units[1]);
}
void testParseQMode_modQ()
{
std::vector<std::string> ws_dim_names(2,"A");
std::vector<std::string> ws_dim_units(2,"UnA");
std::vector<std::string> out_dim_names,out_dim_units;
int nQ_dims;
std::string MODE;
TS_ASSERT_THROWS_NOTHING(MODE=pAlg->parseQMode("|Q|",ws_dim_names,ws_dim_units,out_dim_names,out_dim_units, nQ_dims));
TS_ASSERT_EQUALS(1,nQ_dims);
TS_ASSERT_EQUALS("|Q|",MODE);
TS_ASSERT_EQUALS("|Q|",out_dim_names[0]);
TS_ASSERT_EQUALS("dSpacing",out_dim_units[0]);
}
void testParseQMode_Q3D()
{
std::vector<std::string> ws_dim_names(2,"A");
std::vector<std::string> ws_dim_units(2,"UnA");
std::vector<std::string> out_dim_names,out_dim_units;
int nQ_dims;
std::string MODE;
TS_ASSERT_THROWS_NOTHING(MODE=pAlg->parseQMode("QxQyQz",ws_dim_names,ws_dim_units,out_dim_names,out_dim_units, nQ_dims));
TS_ASSERT_EQUALS(3,nQ_dims);
TS_ASSERT_EQUALS("QxQyQz",MODE);
TS_ASSERT_EQUALS("Q_h",out_dim_names[0]);
TS_ASSERT_EQUALS("Q_k",out_dim_names[1]);
TS_ASSERT_EQUALS("Q_l",out_dim_names[2]);
TS_ASSERT_EQUALS("MomentumTransfer",out_dim_units[0]);
TS_ASSERT_EQUALS("MomentumTransfer",out_dim_units[1]);
TS_ASSERT_EQUALS("MomentumTransfer",out_dim_units[2]);
}
// TEST dE mode
void testParseDEMode_WrongThrows()
{

std::vector<std::string> ws_dim_units;
std::vector<std::string> out_dim_names,out_dim_units;
int ndE_dims;
std::string natural_units;

TS_ASSERT_THROWS(pAlg->parseDEMode("SOMEQMODE","WrongMode",ws_dim_units,out_dim_names,out_dim_units,ndE_dims,natural_units),std::invalid_argument);
}
void testParseDEMode_NoQ()
{
std::vector<std::string> ws_dim_units(1,"some");
std::vector<std::string> out_dim_names,out_dim_units;
int ndE_dims;
std::string natural_units;
std::string EID;

TS_ASSERT_THROWS_NOTHING(EID=pAlg->parseDEMode("","Elastic",ws_dim_units,out_dim_names,out_dim_units,ndE_dims,natural_units));
TS_ASSERT_EQUALS(0,ndE_dims);
TS_ASSERT_EQUALS("",EID);
TS_ASSERT(out_dim_names.empty());
TS_ASSERT(out_dim_units.empty());
TS_ASSERT_EQUALS(ws_dim_units[0],natural_units);
}
void testParseDEMode_InelasticDirect()
{
std::vector<std::string> ws_dim_units(1,"some");
std::vector<std::string> out_dim_names,out_dim_units;
int ndE_dims;
std::string natural_units;
std::string EID;

TS_ASSERT_THROWS_NOTHING(EID=pAlg->parseDEMode("DoesNotMatter","Direct",ws_dim_units,out_dim_names,out_dim_units,ndE_dims,natural_units));
TS_ASSERT_EQUALS(1,ndE_dims);
TS_ASSERT_EQUALS("Direct",EID);
TS_ASSERT_EQUALS("DeltaE",out_dim_names[0]);
TS_ASSERT_EQUALS("DeltaE",out_dim_units[0]);
TS_ASSERT_EQUALS("DeltaE",natural_units);
}
void testParseDEMode_InelasticInDir()
{
std::vector<std::string> ws_dim_units(1,"some");
std::vector<std::string> out_dim_names,out_dim_units;
int ndE_dims;
std::string natural_units;
std::string EID;

TS_ASSERT_THROWS_NOTHING(EID=pAlg->parseDEMode("DoesNotMatter","Indirect",ws_dim_units,out_dim_names,out_dim_units,ndE_dims,natural_units));
TS_ASSERT_EQUALS(1,ndE_dims);
TS_ASSERT_EQUALS("Indirect",EID);
TS_ASSERT_EQUALS("DeltaE",out_dim_names[0]);
TS_ASSERT_EQUALS("DeltaE",out_dim_units[0]);
TS_ASSERT_EQUALS("DeltaE",natural_units);
}
void testParseDEMode_Elastic()
{
std::vector<std::string> ws_dim_units(1,"some");
std::vector<std::string> out_dim_names,out_dim_units;
int ndE_dims;
std::string natural_units;
std::string EID;

TS_ASSERT_THROWS_NOTHING(EID=pAlg->parseDEMode("DoesNotMatter","Elastic",ws_dim_units,out_dim_names,out_dim_units,ndE_dims,natural_units));
TS_ASSERT_EQUALS(0,ndE_dims);
TS_ASSERT_EQUALS("Elastic",EID);
TS_ASSERT(out_dim_names.empty());
TS_ASSERT(out_dim_units.empty());
TS_ASSERT_EQUALS("MomentumTransfer",natural_units);
}
void testParseDEMode_ElasticPowd()
{
std::vector<std::string> ws_dim_units(1,"some");
std::vector<std::string> out_dim_names,out_dim_units;
int ndE_dims;
std::string natural_units;
std::string EID;

TS_ASSERT_THROWS_NOTHING(EID=pAlg->parseDEMode("|Q|","Elastic",ws_dim_units,out_dim_names,out_dim_units,ndE_dims,natural_units));
TS_ASSERT_EQUALS(0,ndE_dims);
TS_ASSERT_EQUALS("Elastic",EID);
TS_ASSERT(out_dim_names.empty());
TS_ASSERT(out_dim_units.empty());
TS_ASSERT_EQUALS("dSpacing",natural_units);
}
// TEST ConvertMode
void testParseConv_NonConvertUnitThrows()
{
std::vector<std::string> ws_dim_units(1,"wrong");
std::string natural_units;

TS_ASSERT_THROWS(pAlg->parseConvMode("AnyConversionMode",natural_units,ws_dim_units),std::invalid_argument);
}
void testParseConv_NoQ()
{
std::vector<std::string> ws_dim_units(1,"Any");
std::string CONV_ID;

TS_ASSERT_THROWS_NOTHING(CONV_ID=pAlg->parseConvMode("","AnyUnits",ws_dim_units));
TS_ASSERT_EQUALS("CnvNo",CONV_ID);
}
void testParseConv_NaturalNoQ()
{
std::vector<std::string> ws_dim_units(1,"dSpacing");
std::string CONV_ID;

TS_ASSERT_THROWS_NOTHING(CONV_ID=pAlg->parseConvMode("","dSpacing",ws_dim_units));
TS_ASSERT_EQUALS("CnvNo",CONV_ID);
}
void testParseConv_QuickConvertsion()
{
std::vector<std::string> ws_dim_units(1,"dSpacing");
std::string CONV_ID;

TS_ASSERT_THROWS_NOTHING(CONV_ID=pAlg->parseConvMode("AnyMode","MomentumTransfer",ws_dim_units));
TS_ASSERT_EQUALS("CnvFast",CONV_ID);
}
void testParseConv_FromTOF()
{
std::vector<std::string> ws_dim_units(1,"TOF");
std::string CONV_ID;

TS_ASSERT_THROWS_NOTHING(CONV_ID=pAlg->parseConvMode("AnyMode","MomentumTransfer",ws_dim_units));
TS_ASSERT_EQUALS("CnvFromTOF",CONV_ID);
}
void testParseConv_ByTOF()
{
std::vector<std::string> ws_dim_units(1,"DeltaE");
std::string CONV_ID;

TS_ASSERT_THROWS_NOTHING(CONV_ID=pAlg->parseConvMode("AnyMode","Wavelength",ws_dim_units));
TS_ASSERT_EQUALS("CnvByTOF",CONV_ID);
}




// --> GET DIMENSIONS FROM WS MATRIX:
void testNeedsNumericAxis(){
Mantid::API::MatrixWorkspace_sptr ws2D =WorkspaceCreationHelper::Create2DWorkspace(4,10);
Expand Down

0 comments on commit bb2172a

Please sign in to comment.