[084729c] | 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 | * RangeUnitTest.cpp
|
---|
| 10 | *
|
---|
| 11 | * Created on: Nov 25, 2009
|
---|
| 12 | * Author: heber
|
---|
| 13 | */
|
---|
| 14 |
|
---|
| 15 | // include config.h
|
---|
| 16 | #ifdef HAVE_CONFIG_H
|
---|
| 17 | #include <config.h>
|
---|
| 18 | #endif
|
---|
| 19 |
|
---|
| 20 | #include <cppunit/CompilerOutputter.h>
|
---|
| 21 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
| 22 | #include <cppunit/ui/text/TestRunner.h>
|
---|
| 23 |
|
---|
| 24 | #include "RangeUnitTest.hpp"
|
---|
| 25 |
|
---|
| 26 | #ifdef HAVE_TESTRUNNER
|
---|
| 27 | #include "UnitTestMain.hpp"
|
---|
| 28 | #endif /*HAVE_TESTRUNNER*/
|
---|
| 29 |
|
---|
| 30 | /********************************************** Test classes **************************************/
|
---|
| 31 |
|
---|
| 32 | // Registers the fixture into the 'registry'
|
---|
| 33 | CPPUNIT_TEST_SUITE_REGISTRATION( RangeTest );
|
---|
| 34 |
|
---|
| 35 |
|
---|
| 36 | void RangeTest::setUp()
|
---|
| 37 | {
|
---|
| 38 | testrange = new range<int>(5,20);
|
---|
| 39 | };
|
---|
| 40 |
|
---|
| 41 |
|
---|
| 42 | void RangeTest::tearDown()
|
---|
| 43 | {
|
---|
| 44 | delete testrange;
|
---|
| 45 | };
|
---|
| 46 |
|
---|
| 47 | /** UnitTest for inRangeTest().
|
---|
| 48 | */
|
---|
| 49 | void RangeTest::inRangeTest()
|
---|
| 50 | {
|
---|
| 51 | // check valid range
|
---|
| 52 | for (int i=5; i<20; i++)
|
---|
| 53 | CPPUNIT_ASSERT(testrange->isInRange(i));
|
---|
| 54 |
|
---|
| 55 | // check negative range
|
---|
| 56 | for (int i=-5; i>-20; i--)
|
---|
| 57 | CPPUNIT_ASSERT(!testrange->isInRange(i));
|
---|
| 58 |
|
---|
| 59 | // lower limit-1 and upper limit are out of range
|
---|
| 60 | CPPUNIT_ASSERT(!testrange->isInRange(4));
|
---|
| 61 | CPPUNIT_ASSERT(!testrange->isInRange(20));
|
---|
| 62 |
|
---|
| 63 | // isBefore
|
---|
| 64 | for (int i=4; i>=0; i--)
|
---|
| 65 | CPPUNIT_ASSERT(testrange->isBefore(i));
|
---|
| 66 |
|
---|
| 67 | // isBeyond
|
---|
| 68 | for (int i=20; i<30; i++)
|
---|
| 69 | CPPUNIT_ASSERT(testrange->isBeyond(i));
|
---|
| 70 |
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | /** UnitTest for operatorTest().
|
---|
| 74 | */
|
---|
| 75 | void RangeTest::operatorTest()
|
---|
| 76 | {
|
---|
| 77 | // check makeRange
|
---|
| 78 | range<int> true_comparison = makeRange(5,20);
|
---|
| 79 | range<int> false_comparison1 = makeRange(6,20);
|
---|
| 80 | range<int> false_comparison2 = makeRange(5,21);
|
---|
| 81 | range<int> false_comparison3 = makeRange(6,21);
|
---|
| 82 | CPPUNIT_ASSERT_EQUAL(testrange->first, true_comparison.first);
|
---|
| 83 | CPPUNIT_ASSERT_EQUAL(testrange->last, true_comparison.last);
|
---|
| 84 |
|
---|
| 85 | // check operator==
|
---|
| 86 | CPPUNIT_ASSERT(*testrange == true_comparison);
|
---|
| 87 | // check operator!=
|
---|
| 88 | CPPUNIT_ASSERT(*testrange != false_comparison1);
|
---|
| 89 | CPPUNIT_ASSERT(*testrange != false_comparison2);
|
---|
| 90 | CPPUNIT_ASSERT(*testrange != false_comparison3);
|
---|
| 91 |
|
---|
| 92 | // check operator<
|
---|
| 93 | CPPUNIT_ASSERT(!(*testrange < true_comparison));
|
---|
| 94 | CPPUNIT_ASSERT(*testrange < false_comparison1);
|
---|
| 95 | CPPUNIT_ASSERT(*testrange < false_comparison2);
|
---|
| 96 | CPPUNIT_ASSERT(*testrange < false_comparison3);
|
---|
| 97 | // check operator>
|
---|
| 98 | CPPUNIT_ASSERT(!(*testrange > true_comparison));
|
---|
| 99 | CPPUNIT_ASSERT(false_comparison1 > *testrange);
|
---|
| 100 | CPPUNIT_ASSERT(false_comparison2 > *testrange);
|
---|
| 101 | CPPUNIT_ASSERT(false_comparison3 > *testrange);
|
---|
| 102 | // check operator>=,<=
|
---|
| 103 | CPPUNIT_ASSERT(*testrange >= true_comparison);
|
---|
| 104 | CPPUNIT_ASSERT(*testrange <= true_comparison);
|
---|
| 105 | }
|
---|