/* * 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 . */ /* * DiscreteParameterTest.cpp * * Created on: Sep 30, 2011 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "DiscreteParameterTest.hpp" #include #include #include #include "Parameters/Parameter.hpp" #ifdef HAVE_TESTRUNNER #include "UnitTestMain.hpp" #endif /*HAVE_TESTRUNNER*/ using namespace std; // Registers the fixture into the 'registry' CPPUNIT_TEST_SUITE_REGISTRATION( DiscreteParameterTest ); void DiscreteParameterTest::setUp() { // failing asserts should be thrown ASSERT_DO(Assert::Throw); for (int i=1; i<=3;++i) { ValidValues.push_back(i); } } void DiscreteParameterTest::tearDown() { ValidValues.clear(); } /************************************ tests ***********************************/ /** Unit test for comparator. * */ void DiscreteParameterTest::comparatorTest() { // create instance Parameter test("intParam", ValidValues); Parameter samenamedsamevalued("intParam", ValidValues); Parameter samenamedelsevalued("intParam", ValidValues); Parameter elsenamedsamevalued("int2Param", ValidValues); Parameter elsenamedelsevalued("int2Param", ValidValues); test.set(1); samenamedsamevalued.set(1); samenamedelsevalued.set(2); elsenamedsamevalued.set(1); elsenamedelsevalued.set(2); CPPUNIT_ASSERT( test == samenamedsamevalued ); CPPUNIT_ASSERT( test != samenamedelsevalued ); CPPUNIT_ASSERT( test != elsenamedsamevalued ); CPPUNIT_ASSERT( test != elsenamedelsevalued ); } /** Unit test for clone. * */ void DiscreteParameterTest::cloneTest() { // create instance Parameter test("intParam", ValidValues); // set parameter test.set(2); // is returned as Parameter but we can compare only in true class as // Parameter may also be a ContinuousParameter where comparison is nonsense Parameter *instance = dynamic_cast< Parameter *> (test.clone()); // different places in memory CPPUNIT_ASSERT( &test != instance); // but same contents CPPUNIT_ASSERT( test == *instance); }