Newer
Older
#ifndef MANDATORYVALIDATORTEST_H_
#define MANDATORYVALIDATORTEST_H_
#include <string>
#include <cxxtest/TestSuite.h>
#include "MantidKernel/MandatoryValidator.h"
using namespace Mantid::Kernel;
class MandatoryValidatorTest : public CxxTest::TestSuite
{
public:
void testConstructor()
{
Russell Taylor
committed
TS_ASSERT_THROWS_NOTHING(MandatoryValidator<std::string> nsv)
TS_ASSERT_THROWS_NOTHING(MandatoryValidator<std::vector<int> > nsv)
TS_ASSERT_THROWS_NOTHING(MandatoryValidator<std::vector<double> > nsv)
TS_ASSERT_THROWS_NOTHING(MandatoryValidator<std::vector<std::string> > nsv)
}
void testClone()
{
IValidator_sptr v = boost::make_shared<MandatoryValidator<std::string> >();
IValidator_sptr vv = v->clone();
TS_ASSERT_DIFFERS( v, vv );
TS_ASSERT( boost::dynamic_pointer_cast<MandatoryValidator<std::string> >(vv) );
Russell Taylor
committed
IValidator_sptr i = boost::make_shared<MandatoryValidator<std::vector<int> > >();
IValidator_sptr ii = i->clone();
Russell Taylor
committed
TS_ASSERT_DIFFERS( i, ii )
TS_ASSERT( boost::dynamic_pointer_cast<MandatoryValidator<std::vector<int> > >(ii) )
Russell Taylor
committed
IValidator_sptr d = boost::make_shared<MandatoryValidator<std::vector<double> > >();
IValidator_sptr dd = d->clone();
TS_ASSERT_DIFFERS( d, dd );
TS_ASSERT( boost::dynamic_pointer_cast<MandatoryValidator<std::vector<double> > >(dd) );
Russell Taylor
committed
IValidator_sptr s = boost::make_shared<MandatoryValidator<std::vector<std::string>>>();
IValidator_sptr ss = s->clone();
TS_ASSERT_DIFFERS( s, ss );
TS_ASSERT( boost::dynamic_pointer_cast<MandatoryValidator<std::vector<std::string>>>(ss) );
}
void testMandatoryValidator()
{
Russell Taylor
committed
MandatoryValidator<std::string> p;
Steve Williams
committed
TS_ASSERT_EQUALS(p.isValid("AZ"), "");
TS_ASSERT_EQUALS(p.isValid("B"), "");
TS_ASSERT_EQUALS(p.isValid(""), "A value must be entered for this parameter");
TS_ASSERT_EQUALS(p.isValid("ta"), "" );
Russell Taylor
committed
MandatoryValidator<std::vector<int> > i;
std::vector<int> ivec;
TS_ASSERT( ivec.empty() )
Steve Williams
committed
TS_ASSERT_EQUALS( i.isValid(ivec), "A value must be entered for this parameter" )
Russell Taylor
committed
ivec.push_back(1);
Steve Williams
committed
TS_ASSERT_EQUALS( i.isValid(ivec), "")
Russell Taylor
committed
MandatoryValidator<std::vector<double> > d;
std::vector<double> dvec;
TS_ASSERT( dvec.empty() )
Steve Williams
committed
TS_ASSERT_EQUALS( d.isValid(dvec), "A value must be entered for this parameter" )
Russell Taylor
committed
dvec.push_back(1.1);
Steve Williams
committed
TS_ASSERT_EQUALS( d.isValid(dvec), "")
Russell Taylor
committed
MandatoryValidator<std::vector<std::string> > s;
std::vector<std::string> svec;
TS_ASSERT( svec.empty() )
Steve Williams
committed
TS_ASSERT_EQUALS( s.isValid(svec), "A value must be entered for this parameter" )
Russell Taylor
committed
svec.push_back("OK");
Steve Williams
committed
TS_ASSERT_EQUALS( s.isValid(svec), "" )
Gigg, Martyn Anthony
committed
MandatoryValidator<int> validate_int;
TS_ASSERT_EQUALS( validate_int.isValid(5), "" );
TS_ASSERT_EQUALS( validate_int.isValid(-10000), "" );
MandatoryValidator<double> validate_dbl;
TS_ASSERT_EQUALS( validate_dbl.isValid(5.0), "" );
TS_ASSERT_EQUALS( validate_dbl.isValid(-250.0), "" );
}