[e09d67] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
| 4 | * Copyright (C) 2010 University of Bonn. All rights reserved.
|
---|
| 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | /*
|
---|
| 9 | * DiscreteValueUnitTest.cpp
|
---|
| 10 | *
|
---|
| 11 | * Created on: Sep 28, 2011
|
---|
| 12 | * Author: heber
|
---|
| 13 | */
|
---|
| 14 |
|
---|
| 15 | // include config.h
|
---|
| 16 | #ifdef HAVE_CONFIG_H
|
---|
| 17 | #include <config.h>
|
---|
| 18 | #endif
|
---|
| 19 |
|
---|
| 20 | #include "DiscreteValueUnitTest.hpp"
|
---|
| 21 |
|
---|
| 22 | #include <cppunit/CompilerOutputter.h>
|
---|
| 23 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
| 24 | #include <cppunit/ui/text/TestRunner.h>
|
---|
| 25 |
|
---|
| 26 | #include "Parser/DiscreteValue.hpp"
|
---|
| 27 |
|
---|
| 28 | #ifdef HAVE_TESTRUNNER
|
---|
| 29 | #include "UnitTestMain.hpp"
|
---|
| 30 | #endif /*HAVE_TESTRUNNER*/
|
---|
| 31 |
|
---|
| 32 | using namespace std;
|
---|
| 33 |
|
---|
| 34 | // Registers the fixture into the 'registry'
|
---|
| 35 | CPPUNIT_TEST_SUITE_REGISTRATION( DiscreteValueTest );
|
---|
| 36 |
|
---|
| 37 |
|
---|
| 38 | void DiscreteValueTest::setUp()
|
---|
| 39 | {
|
---|
| 40 | // failing asserts should be thrown
|
---|
| 41 | ASSERT_DO(Assert::Throw);
|
---|
| 42 |
|
---|
| 43 | for (int i=1; i<=3;++i) {
|
---|
| 44 | ValidValues.push_back(i);
|
---|
| 45 | }
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | void DiscreteValueTest::tearDown()
|
---|
| 49 | {
|
---|
| 50 | ValidValues.clear();
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | /************************************ tests ***********************************/
|
---|
| 54 |
|
---|
| 55 | /** Unit test for findIndexOfValue.
|
---|
| 56 | *
|
---|
| 57 | */
|
---|
| 58 | void DiscreteValueTest::findIndexOfValueTest()
|
---|
| 59 | {
|
---|
| 60 | // create instance
|
---|
| 61 | DiscreteValue<int> test(ValidValues);
|
---|
| 62 |
|
---|
| 63 | // check valid values indices
|
---|
| 64 | CPPUNIT_ASSERT_EQUAL((size_t)0, test.findIndexOfValue(1));
|
---|
| 65 | CPPUNIT_ASSERT_EQUAL((size_t)1, test.findIndexOfValue(2));
|
---|
| 66 | CPPUNIT_ASSERT_EQUAL((size_t)2, test.findIndexOfValue(3));
|
---|
| 67 |
|
---|
| 68 | // check invalid ones
|
---|
| 69 | for (int i=-10; i<=0;++i)
|
---|
| 70 | CPPUNIT_ASSERT_EQUAL((size_t)-1, test.findIndexOfValue(i));
|
---|
| 71 | for (int i=4; i<=0;++i)
|
---|
| 72 | CPPUNIT_ASSERT_EQUAL((size_t)-1, test.findIndexOfValue(i));
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | /** Unit test for isValid.
|
---|
| 76 | *
|
---|
| 77 | */
|
---|
| 78 | void DiscreteValueTest::isValidTest()
|
---|
| 79 | {
|
---|
| 80 | // create instance
|
---|
| 81 | DiscreteValue<int> test(ValidValues);
|
---|
| 82 |
|
---|
| 83 | // checking valid values
|
---|
| 84 | for (int i=1; i<=3;++i)
|
---|
| 85 | CPPUNIT_ASSERT_EQUAL(true, test.isValid(i));
|
---|
| 86 |
|
---|
| 87 | // checking invalid values
|
---|
| 88 | for (int i=-10; i<=0;++i)
|
---|
| 89 | CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
|
---|
| 90 | for (int i=4; i<=0;++i)
|
---|
| 91 | CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | /** Unit test for appendValidValue.
|
---|
| 95 | *
|
---|
| 96 | */
|
---|
| 97 | void DiscreteValueTest::appendValidValueTest()
|
---|
| 98 | {
|
---|
| 99 | // create instance
|
---|
| 100 | DiscreteValue<int> test(ValidValues);
|
---|
| 101 |
|
---|
| 102 | // adding values 4,5,6
|
---|
| 103 | for (int i=4; i<=6;++i) {
|
---|
| 104 | CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
|
---|
| 105 | test.appendValidValue(i);
|
---|
| 106 | CPPUNIT_ASSERT_EQUAL(true, test.isValid(i));
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | // adding same value, throws assertion
|
---|
| 110 | #ifndef NDEBUG
|
---|
| 111 | std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
|
---|
| 112 | for (int i=1; i<=6;++i)
|
---|
| 113 | CPPUNIT_ASSERT_THROW(test.appendValidValue(i), Assert::AssertionFailure);
|
---|
| 114 | #endif
|
---|
| 115 |
|
---|
| 116 | // checking valid values
|
---|
| 117 | for (int i=1; i<=6;++i)
|
---|
| 118 | CPPUNIT_ASSERT_EQUAL(true, test.isValid(i));
|
---|
| 119 |
|
---|
| 120 | // checking invalid values
|
---|
| 121 | for (int i=-10; i<=0;++i)
|
---|
| 122 | CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
|
---|
| 123 |
|
---|
| 124 | // checking invalid values
|
---|
| 125 | for (int i=7; i<=10;++i)
|
---|
| 126 | CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | /** Unit test for setters and getters.
|
---|
| 130 | *
|
---|
| 131 | */
|
---|
| 132 | void DiscreteValueTest::settergetterTest()
|
---|
| 133 | {
|
---|
| 134 | // create instance
|
---|
| 135 | DiscreteValue<int> test(ValidValues);
|
---|
| 136 |
|
---|
| 137 | // unset calling of get, throws
|
---|
| 138 | #ifndef NDEBUG
|
---|
| 139 | std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
|
---|
| 140 | CPPUNIT_ASSERT_THROW(test.get(), Assert::AssertionFailure);
|
---|
| 141 | #endif
|
---|
| 142 |
|
---|
| 143 | // setting invalid, throws
|
---|
| 144 | #ifndef NDEBUG
|
---|
| 145 | std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
|
---|
| 146 | CPPUNIT_ASSERT_THROW(test.set(4), Assert::AssertionFailure);
|
---|
| 147 | #endif
|
---|
| 148 | #ifndef NDEBUG
|
---|
| 149 | std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
|
---|
| 150 | CPPUNIT_ASSERT_THROW(test.set(0), Assert::AssertionFailure);
|
---|
| 151 | #endif
|
---|
| 152 |
|
---|
| 153 | // checking all valid ones
|
---|
| 154 | for (int i=1; i<=3;++i) {
|
---|
| 155 | test.set(i);
|
---|
| 156 | CPPUNIT_ASSERT_EQUAL(i, test.get());
|
---|
| 157 | }
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 |
|
---|
| 161 |
|
---|