/*
* Project: MoleCuilder
* Description: creates and alters molecular systems
* Copyright (C) 2010-2012 University of Bonn. All rights reserved.
*
*
* This file is part of MoleCuilder.
*
* MoleCuilder is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* MoleCuilder is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MoleCuilder. If not, see .
*/
/*
* Ops_ValidatorTest.cpp
*
* Created on: May 9, 2012
* Author: ankele
*/
// include config.h
#ifdef HAVE_CONFIG_H
#include
#endif
#include
#include
#include
#include "CodePatterns/Assert.hpp"
#include "Parameters/Validators/DiscreteValidator.hpp"
#include "Parameters/Validators/Ops_Validator.hpp"
#include "Ops_ValidatorTest.hpp"
#ifdef HAVE_TESTRUNNER
#include "UnitTestMain.hpp"
#endif /*HAVE_TESTRUNNER*/
/********************************************** Test classes **************************************/
// Registers the fixture into the 'registry'
CPPUNIT_TEST_SUITE_REGISTRATION( Ops_ValidatorTest );
void Ops_ValidatorTest::setUp()
{
// failing asserts should be thrown
ASSERT_DO(Assert::Throw);
ValidValuesA.push_back(1);
ValidValuesA.push_back(2);
ValidValuesA.push_back(3);
ValidValuesA.push_back(4);
ValidValuesB.push_back(1);
ValidValuesB.push_back(3);
ValidValuesB.push_back(10);
}
void Ops_ValidatorTest::tearDown()
{
ValidValuesA.clear();
ValidValuesB.clear();
}
/** Test whether operator() returns as desired
*
*/
void Ops_ValidatorTest::AndTest()
{
And_Validator AndVal = (DiscreteValidator(ValidValuesA) && DiscreteValidator(ValidValuesB));
CPPUNIT_ASSERT( (AndVal)(1) );
CPPUNIT_ASSERT( (AndVal)(3) );
CPPUNIT_ASSERT( !(AndVal)(2) );
CPPUNIT_ASSERT( !(AndVal)(0) );
}
/** Test whether operator() returns as desired
*
*/
void Ops_ValidatorTest::OrTest()
{
Or_Validator OrVal = (DiscreteValidator(ValidValuesA) || DiscreteValidator(ValidValuesB));
CPPUNIT_ASSERT( (OrVal)(1) );
CPPUNIT_ASSERT( (OrVal)(2) );
CPPUNIT_ASSERT( (OrVal)(3) );
CPPUNIT_ASSERT( (OrVal)(4) );
CPPUNIT_ASSERT( (OrVal)(10) );
CPPUNIT_ASSERT( !(OrVal)(0) );
CPPUNIT_ASSERT( !(OrVal)(5) );
}
/** Test whether operator!() returns as desired
*
*/
void Ops_ValidatorTest::NotTest()
{
Not_Validator NotVal = (!DiscreteValidator(ValidValuesA));
CPPUNIT_ASSERT( !(NotVal)(1) );
CPPUNIT_ASSERT( !(NotVal)(3) );
CPPUNIT_ASSERT( (NotVal)(5) );
CPPUNIT_ASSERT( (NotVal)(0) );
}