| [c68409] | 1 | /*
 | 
|---|
 | 2 |  * Project: MoleCuilder
 | 
|---|
 | 3 |  * Description: creates and alters molecular systems
 | 
|---|
 | 4 |  * Copyright (C)  2010-2012 University of Bonn. All rights reserved.
 | 
|---|
| [94d5ac6] | 5 |  * 
 | 
|---|
 | 6 |  *
 | 
|---|
 | 7 |  *   This file is part of MoleCuilder.
 | 
|---|
 | 8 |  *
 | 
|---|
 | 9 |  *    MoleCuilder is free software: you can redistribute it and/or modify
 | 
|---|
 | 10 |  *    it under the terms of the GNU General Public License as published by
 | 
|---|
 | 11 |  *    the Free Software Foundation, either version 2 of the License, or
 | 
|---|
 | 12 |  *    (at your option) any later version.
 | 
|---|
 | 13 |  *
 | 
|---|
 | 14 |  *    MoleCuilder is distributed in the hope that it will be useful,
 | 
|---|
 | 15 |  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
 | 16 |  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
 | 17 |  *    GNU General Public License for more details.
 | 
|---|
 | 18 |  *
 | 
|---|
 | 19 |  *    You should have received a copy of the GNU General Public License
 | 
|---|
 | 20 |  *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>.
 | 
|---|
| [c68409] | 21 |  */
 | 
|---|
 | 22 | 
 | 
|---|
 | 23 | /*
 | 
|---|
| [dbb533] | 24 |  * ContinuousValueTest.cpp
 | 
|---|
| [c68409] | 25 |  *
 | 
|---|
 | 26 |  *  Created on: Sep 29, 2011
 | 
|---|
 | 27 |  *      Author: heber
 | 
|---|
 | 28 |  */
 | 
|---|
 | 29 | 
 | 
|---|
 | 30 | // include config.h
 | 
|---|
 | 31 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 32 | #include <config.h>
 | 
|---|
 | 33 | #endif
 | 
|---|
 | 34 | 
 | 
|---|
| [dbb533] | 35 | #include "ContinuousValueTest.hpp"
 | 
|---|
| [c68409] | 36 | 
 | 
|---|
 | 37 | #include <cppunit/CompilerOutputter.h>
 | 
|---|
 | 38 | #include <cppunit/extensions/TestFactoryRegistry.h>
 | 
|---|
 | 39 | #include <cppunit/ui/text/TestRunner.h>
 | 
|---|
 | 40 | 
 | 
|---|
| [3c5ef5] | 41 | #include "Parameters/Value.hpp"
 | 
|---|
| [c68409] | 42 | 
 | 
|---|
 | 43 | #ifdef HAVE_TESTRUNNER
 | 
|---|
 | 44 | #include "UnitTestMain.hpp"
 | 
|---|
 | 45 | #endif /*HAVE_TESTRUNNER*/
 | 
|---|
 | 46 | 
 | 
|---|
 | 47 | // Registers the fixture into the 'registry'
 | 
|---|
 | 48 | CPPUNIT_TEST_SUITE_REGISTRATION( ContinuousValueTest );
 | 
|---|
 | 49 | 
 | 
|---|
 | 50 | 
 | 
|---|
 | 51 | void ContinuousValueTest::setUp()
 | 
|---|
 | 52 | {
 | 
|---|
 | 53 |   // failing asserts should be thrown
 | 
|---|
 | 54 |   ASSERT_DO(Assert::Throw);
 | 
|---|
 | 55 | 
 | 
|---|
| [7d1b6a] | 56 |   ValidIntRange = new range<int>(1,4);
 | 
|---|
 | 57 |   ValidVectorRange = new range<Vector>(Vector(0,1,2), Vector(10,11,12));
 | 
|---|
| [c68409] | 58 | }
 | 
|---|
 | 59 | 
 | 
|---|
 | 60 | void ContinuousValueTest::tearDown()
 | 
|---|
 | 61 | {
 | 
|---|
| [7d1b6a] | 62 |   delete ValidIntRange;
 | 
|---|
 | 63 |   delete ValidVectorRange;
 | 
|---|
| [c68409] | 64 | }
 | 
|---|
 | 65 | 
 | 
|---|
 | 66 | /************************************ tests ***********************************/
 | 
|---|
 | 67 | 
 | 
|---|
 | 68 | /** Unit test for isValid.
 | 
|---|
 | 69 |  *
 | 
|---|
 | 70 |  */
 | 
|---|
| [047cad] | 71 | void ContinuousValueTest::isValidIntAsStringTest()
 | 
|---|
| [c68409] | 72 | {
 | 
|---|
 | 73 |   // create instance
 | 
|---|
| [3c5ef5] | 74 |   Value<int> test(*ValidIntRange);
 | 
|---|
| [c68409] | 75 | 
 | 
|---|
 | 76 |   // checking valid values
 | 
|---|
| [6c05d8] | 77 |   for (int i=1; i<=4;++i)
 | 
|---|
| [047cad] | 78 |     CPPUNIT_ASSERT_EQUAL(true, test.isValidAsString(toString(i)));
 | 
|---|
| [c68409] | 79 | 
 | 
|---|
 | 80 |   // checking invalid values
 | 
|---|
 | 81 |   for (int i=-10; i<=0;++i)
 | 
|---|
| [047cad] | 82 |     CPPUNIT_ASSERT_EQUAL(false, test.isValidAsString(toString(i)));
 | 
|---|
| [c68409] | 83 |   for (int i=5; i<=0;++i)
 | 
|---|
| [6c05d8] | 84 |     CPPUNIT_ASSERT_EQUAL(false, test.isValidAsString(toString(i)));
 | 
|---|
| [c68409] | 85 | }
 | 
|---|
 | 86 | 
 | 
|---|
 | 87 | /** Unit test for isValid.
 | 
|---|
 | 88 |  *
 | 
|---|
 | 89 |  */
 | 
|---|
| [7d1b6a] | 90 | void ContinuousValueTest::isValidIntTest()
 | 
|---|
| [c68409] | 91 | {
 | 
|---|
 | 92 |   // create instance
 | 
|---|
| [3c5ef5] | 93 |   Value<int> test(*ValidIntRange);
 | 
|---|
| [c68409] | 94 | 
 | 
|---|
 | 95 |   // checking valid values
 | 
|---|
 | 96 |   for (int i=1; i<=4;++i)
 | 
|---|
| [dbb533] | 97 |     CPPUNIT_ASSERT_EQUAL(true, test.isValid(i));
 | 
|---|
| [c68409] | 98 | 
 | 
|---|
 | 99 |   // checking invalid values
 | 
|---|
 | 100 |   for (int i=-10; i<=0;++i)
 | 
|---|
| [dbb533] | 101 |     CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
 | 
|---|
| [c68409] | 102 |   for (int i=5; i<=0;++i)
 | 
|---|
| [dbb533] | 103 |     CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
 | 
|---|
| [c68409] | 104 | }
 | 
|---|
 | 105 | 
 | 
|---|
 | 106 | /** Unit test for setting/getting valid range.
 | 
|---|
 | 107 |  *
 | 
|---|
 | 108 |  */
 | 
|---|
| [7d1b6a] | 109 | void ContinuousValueTest::setgetValidIntRangeTest()
 | 
|---|
| [c68409] | 110 | {
 | 
|---|
 | 111 |   {
 | 
|---|
 | 112 |     // create instance
 | 
|---|
| [3c5ef5] | 113 |     Value<int> test(*ValidIntRange);
 | 
|---|
| [c68409] | 114 | 
 | 
|---|
 | 115 |     // extending range and checking
 | 
|---|
 | 116 |     for (int i=5; i<=6;++i)
 | 
|---|
| [047cad] | 117 |       CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
 | 
|---|
| [c68409] | 118 |     test.setValidRange(range<int>(1,6));
 | 
|---|
 | 119 |     for (int i=5; i<=6;++i)
 | 
|---|
| [047cad] | 120 |       CPPUNIT_ASSERT_EQUAL(true, test.isValid(i));
 | 
|---|
| [c68409] | 121 |   }
 | 
|---|
 | 122 | 
 | 
|---|
 | 123 |   {
 | 
|---|
 | 124 |     // create instance
 | 
|---|
| [3c5ef5] | 125 |     Value<int> test(*ValidIntRange);
 | 
|---|
| [c68409] | 126 | 
 | 
|---|
 | 127 |     // lowering range with set value
 | 
|---|
| [047cad] | 128 |     test.set(4);
 | 
|---|
| [c68409] | 129 |     CPPUNIT_ASSERT_EQUAL(true, test.ValueSet);
 | 
|---|
 | 130 |     std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
 | 
|---|
| [e45c1d] | 131 |     CPPUNIT_ASSERT_THROW(test.setValidRange(range<int>(1,3)), ParameterValueException);
 | 
|---|
 | 132 | 
 | 
|---|
| [c68409] | 133 |     // no value is not set
 | 
|---|
 | 134 |     std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
 | 
|---|
| [e45c1d] | 135 |     CPPUNIT_ASSERT_THROW(test.get(), ParameterValueException);
 | 
|---|
 | 136 | 
 | 
|---|
| [c68409] | 137 |     // value gets invalidated in either case
 | 
|---|
 | 138 |     CPPUNIT_ASSERT_EQUAL(false, test.ValueSet);
 | 
|---|
 | 139 |   }
 | 
|---|
 | 140 | }
 | 
|---|
 | 141 | 
 | 
|---|
 | 142 | /** Unit test for setValue and getValue.
 | 
|---|
 | 143 |  *
 | 
|---|
 | 144 |  */
 | 
|---|
| [047cad] | 145 | void ContinuousValueTest::settergetterIntAsStringTest()
 | 
|---|
| [c68409] | 146 | {
 | 
|---|
| [e45c1d] | 147 |   // unset calling of get, throws ParameterValueException
 | 
|---|
| [0d4168] | 148 |   {
 | 
|---|
 | 149 |     Value<int> test(*ValidIntRange);
 | 
|---|
 | 150 |     std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
 | 
|---|
 | 151 |     CPPUNIT_ASSERT_THROW(test.getAsString(), ParameterValueException);
 | 
|---|
 | 152 |   }
 | 
|---|
| [c68409] | 153 | 
 | 
|---|
| [0d4168] | 154 |   // setting invalid and getting it, throws ParameterValueException
 | 
|---|
 | 155 |   {
 | 
|---|
 | 156 |     Value<int> test(*ValidIntRange);
 | 
|---|
 | 157 |     std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
 | 
|---|
| [3e6b93] | 158 |     CPPUNIT_ASSERT_THROW(test.setAsString(toString(5)), ParameterValueException);
 | 
|---|
 | 159 |     std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
 | 
|---|
 | 160 |     CPPUNIT_ASSERT_THROW(test.setAsString(toString(0)), ParameterValueException);
 | 
|---|
| [0d4168] | 161 |   }
 | 
|---|
| [c68409] | 162 | 
 | 
|---|
 | 163 |   // checking all valid ones
 | 
|---|
| [0d4168] | 164 |   {
 | 
|---|
 | 165 |     Value<int> test(*ValidIntRange);
 | 
|---|
 | 166 |     CPPUNIT_ASSERT_EQUAL(false, test.ValueSet);
 | 
|---|
 | 167 |     for (int i=1; i<=4;++i) {
 | 
|---|
 | 168 |       test.setAsString(toString(i));
 | 
|---|
 | 169 |       CPPUNIT_ASSERT_EQUAL(true, test.ValueSet);
 | 
|---|
 | 170 |       CPPUNIT_ASSERT_EQUAL(toString(i), test.getAsString());
 | 
|---|
 | 171 |     }
 | 
|---|
| [6c05d8] | 172 |   }
 | 
|---|
| [c68409] | 173 | }
 | 
|---|
 | 174 | 
 | 
|---|
 | 175 | /** Unit test for setters and getters.
 | 
|---|
 | 176 |  *
 | 
|---|
 | 177 |  */
 | 
|---|
| [7d1b6a] | 178 | void ContinuousValueTest::settergetterIntTest()
 | 
|---|
| [c68409] | 179 | {
 | 
|---|
 | 180 |   // create instance
 | 
|---|
| [3c5ef5] | 181 |   Value<int> test(*ValidIntRange);
 | 
|---|
| [c68409] | 182 | 
 | 
|---|
| [e45c1d] | 183 |   // unset calling of get, throws ParameterValueException
 | 
|---|
| [c68409] | 184 |   std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
 | 
|---|
| [e45c1d] | 185 |   CPPUNIT_ASSERT_THROW(test.get(), ParameterValueException);
 | 
|---|
| [c68409] | 186 | 
 | 
|---|
| [0d4168] | 187 |   // setting invalid and getting it, throws ParameterValueException
 | 
|---|
| [c68409] | 188 |   std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
 | 
|---|
| [3e6b93] | 189 |   CPPUNIT_ASSERT_THROW(test.set(5), ParameterValueException);
 | 
|---|
| [c68409] | 190 |   std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
 | 
|---|
| [3e6b93] | 191 |   CPPUNIT_ASSERT_THROW(test.set(0), ParameterValueException);
 | 
|---|
| [c68409] | 192 | 
 | 
|---|
 | 193 |   // checking all valid ones
 | 
|---|
 | 194 |   for (int i=1; i<=4;++i) {
 | 
|---|
| [dbb533] | 195 |     test.set(i);
 | 
|---|
 | 196 |     CPPUNIT_ASSERT_EQUAL(i, test.get());
 | 
|---|
| [c68409] | 197 |   }
 | 
|---|
 | 198 | }
 | 
|---|
 | 199 | 
 | 
|---|
 | 200 | /** Unit test for comparator.
 | 
|---|
 | 201 |  *
 | 
|---|
 | 202 |  */
 | 
|---|
| [7d1b6a] | 203 | void ContinuousValueTest::comparatorIntTest()
 | 
|---|
| [c68409] | 204 | {
 | 
|---|
 | 205 |   {
 | 
|---|
 | 206 |     // create instance
 | 
|---|
| [3c5ef5] | 207 |     Value<int> test(*ValidIntRange);
 | 
|---|
 | 208 |     Value<int> instance(*ValidIntRange);
 | 
|---|
| [047cad] | 209 |     test.set(1);
 | 
|---|
 | 210 |     instance.set(1);
 | 
|---|
| [c68409] | 211 | 
 | 
|---|
 | 212 |     // same value, same range
 | 
|---|
 | 213 |     {
 | 
|---|
 | 214 |       CPPUNIT_ASSERT(test == instance);
 | 
|---|
 | 215 |     }
 | 
|---|
 | 216 | 
 | 
|---|
 | 217 |     // different value, same range
 | 
|---|
 | 218 |     {
 | 
|---|
| [047cad] | 219 |       const int oldvalue = instance.get();
 | 
|---|
 | 220 |       instance.set(2);
 | 
|---|
| [c68409] | 221 |       CPPUNIT_ASSERT(test != instance);
 | 
|---|
| [047cad] | 222 |       instance.set(oldvalue);
 | 
|---|
| [c68409] | 223 |     }
 | 
|---|
 | 224 |   }
 | 
|---|
 | 225 |   {
 | 
|---|
| [3c5ef5] | 226 |     Value<int> test(*ValidIntRange);
 | 
|---|
| [7d1b6a] | 227 |     range<int> OtherValidIntRange(1,5);
 | 
|---|
| [3c5ef5] | 228 |     Value<int> instance(OtherValidIntRange);
 | 
|---|
| [c68409] | 229 | 
 | 
|---|
| [047cad] | 230 |     test.set(1);
 | 
|---|
 | 231 |     instance.set(1);
 | 
|---|
| [c68409] | 232 | 
 | 
|---|
 | 233 |     // same value, same range
 | 
|---|
 | 234 |     {
 | 
|---|
 | 235 |       CPPUNIT_ASSERT(test != instance);
 | 
|---|
 | 236 |     }
 | 
|---|
 | 237 | 
 | 
|---|
 | 238 |     // different value, same range
 | 
|---|
 | 239 |     {
 | 
|---|
| [047cad] | 240 |       const int oldvalue = instance.get();
 | 
|---|
 | 241 |       instance.set(2);
 | 
|---|
| [c68409] | 242 |       CPPUNIT_ASSERT(test != instance);
 | 
|---|
| [047cad] | 243 |       instance.set(oldvalue);
 | 
|---|
| [c68409] | 244 |     }
 | 
|---|
 | 245 |   }
 | 
|---|
 | 246 | }
 | 
|---|
| [7d1b6a] | 247 | 
 | 
|---|
 | 248 | 
 | 
|---|
 | 249 | 
 | 
|---|
 | 250 | /***************************** vector tests ***********************************/
 | 
|---|
 | 251 | 
 | 
|---|
 | 252 | /** Unit test for isValid.
 | 
|---|
 | 253 |  *
 | 
|---|
 | 254 |  */
 | 
|---|
| [047cad] | 255 | void ContinuousValueTest::isValidVectorAsStringTest()
 | 
|---|
| [7d1b6a] | 256 | {
 | 
|---|
 | 257 |   // create instance
 | 
|---|
| [047cad] | 258 |   /*ContinuousValue<Vector> test(*ValidVectorRange);
 | 
|---|
| [7d1b6a] | 259 | 
 | 
|---|
 | 260 |   // checking valid values
 | 
|---|
 | 261 |   CPPUNIT_ASSERT_EQUAL(true, test.isValidValue(Vector(0,1,2)));
 | 
|---|
 | 262 |   CPPUNIT_ASSERT_EQUAL(true, test.isValidValue(Vector(9.9,10.9,11.9)));
 | 
|---|
 | 263 |   CPPUNIT_ASSERT_EQUAL(true, test.isValidValue(Vector(5,5,5)));
 | 
|---|
 | 264 | 
 | 
|---|
 | 265 |   // checking invalid values
 | 
|---|
 | 266 |   CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(-0.1,0.9,1.9)));
 | 
|---|
 | 267 |   CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(10.1,11.1,12.1)));
 | 
|---|
 | 268 |   CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(5,5,-1)));
 | 
|---|
 | 269 |   CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(5,-1,5)));
 | 
|---|
 | 270 |   CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(-1,5,5)));
 | 
|---|
 | 271 |   CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(5,5,20)));
 | 
|---|
 | 272 |   CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(5,20,5)));
 | 
|---|
 | 273 |   CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(20,5,5)));
 | 
|---|
 | 274 |   CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(0,0,0)));
 | 
|---|
 | 275 |   CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(5,-1,-1)));
 | 
|---|
 | 276 |   CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(-1,5,-1)));
 | 
|---|
 | 277 |   CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(-1,-1,5)));
 | 
|---|
 | 278 |   CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(5,20,20)));
 | 
|---|
 | 279 |   CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(20,5,20)));
 | 
|---|
| [047cad] | 280 |   CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(20,20,5)));*/
 | 
|---|
| [7d1b6a] | 281 | }
 | 
|---|
 | 282 | 
 | 
|---|
 | 283 | /** Unit test for isValid.
 | 
|---|
 | 284 |  *
 | 
|---|
 | 285 |  */
 | 
|---|
 | 286 | void ContinuousValueTest::isValidVectorTest()
 | 
|---|
 | 287 | {
 | 
|---|
 | 288 |   // create instance
 | 
|---|
| [3c5ef5] | 289 |   Value<Vector> test(*ValidVectorRange);
 | 
|---|
| [7d1b6a] | 290 | 
 | 
|---|
 | 291 |   // checking valid values
 | 
|---|
 | 292 |   CPPUNIT_ASSERT_EQUAL(true, test.isValid(Vector(0,1,2)));
 | 
|---|
 | 293 |   CPPUNIT_ASSERT_EQUAL(true, test.isValid(Vector(9.9,10.9,11.9)));
 | 
|---|
 | 294 |   CPPUNIT_ASSERT_EQUAL(true, test.isValid(Vector(5,5,5)));
 | 
|---|
 | 295 | 
 | 
|---|
 | 296 |   // checking invalid values
 | 
|---|
 | 297 |   CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(-0.1,0.9,1.9)));
 | 
|---|
 | 298 |   CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(10.1,11.1,12.1)));
 | 
|---|
 | 299 |   CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(5,5,-1)));
 | 
|---|
 | 300 |   CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(5,-1,5)));
 | 
|---|
 | 301 |   CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(-1,5,5)));
 | 
|---|
 | 302 |   CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(5,5,20)));
 | 
|---|
 | 303 |   CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(5,20,5)));
 | 
|---|
 | 304 |   CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(20,5,5)));
 | 
|---|
 | 305 |   CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(0,0,0)));
 | 
|---|
 | 306 |   CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(5,-1,-1)));
 | 
|---|
 | 307 |   CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(-1,5,-1)));
 | 
|---|
 | 308 |   CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(-1,-1,5)));
 | 
|---|
 | 309 |   CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(5,20,20)));
 | 
|---|
 | 310 |   CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(20,5,20)));
 | 
|---|
 | 311 |   CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(20,20,5)));
 | 
|---|
 | 312 | }
 | 
|---|
 | 313 | 
 | 
|---|
 | 314 | /** Unit test for setting/getting valid range.
 | 
|---|
 | 315 |  *
 | 
|---|
 | 316 |  */
 | 
|---|
 | 317 | void ContinuousValueTest::setgetValidVectorRangeTest()
 | 
|---|
 | 318 | {
 | 
|---|
 | 319 |   {
 | 
|---|
 | 320 |     // create instance
 | 
|---|
| [3c5ef5] | 321 |     Value<Vector> test(*ValidVectorRange);
 | 
|---|
| [7d1b6a] | 322 | 
 | 
|---|
 | 323 |     // extending range and checking
 | 
|---|
 | 324 |     for (int i=15; i<=16;++i)
 | 
|---|
| [047cad] | 325 |       CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(i,5,5)));
 | 
|---|
| [7d1b6a] | 326 |     test.setValidRange(range<Vector>(Vector(0,1,2),Vector(20,11,12)));
 | 
|---|
 | 327 |     for (int i=15; i<=16;++i)
 | 
|---|
| [047cad] | 328 |       CPPUNIT_ASSERT_EQUAL(true, test.isValid(Vector(i,5,5)));
 | 
|---|
| [7d1b6a] | 329 |   }
 | 
|---|
 | 330 | 
 | 
|---|
 | 331 |   {
 | 
|---|
 | 332 |     // create instance
 | 
|---|
| [3c5ef5] | 333 |     Value<Vector> test(*ValidVectorRange);
 | 
|---|
| [7d1b6a] | 334 | 
 | 
|---|
 | 335 |     // lowering range with set value
 | 
|---|
| [047cad] | 336 |     test.set(Vector(4,4,4));
 | 
|---|
| [7d1b6a] | 337 |     CPPUNIT_ASSERT_EQUAL(true, test.ValueSet);
 | 
|---|
 | 338 |     std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
 | 
|---|
| [e45c1d] | 339 |     CPPUNIT_ASSERT_THROW(test.setValidRange(range<Vector>(Vector(1,1,1),Vector(3,3,3))), ParameterValueException);
 | 
|---|
 | 340 | 
 | 
|---|
| [7d1b6a] | 341 |     // no value is not set
 | 
|---|
 | 342 |     std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
 | 
|---|
| [e45c1d] | 343 |     CPPUNIT_ASSERT_THROW(test.get(), ParameterException);
 | 
|---|
 | 344 | 
 | 
|---|
| [7d1b6a] | 345 |     // value gets invalidated in either case
 | 
|---|
 | 346 |     CPPUNIT_ASSERT_EQUAL(false, test.ValueSet);
 | 
|---|
 | 347 |   }
 | 
|---|
 | 348 | }
 | 
|---|
 | 349 | 
 | 
|---|
 | 350 | /** Unit test for setValue and getValue.
 | 
|---|
 | 351 |  *
 | 
|---|
 | 352 |  */
 | 
|---|
| [047cad] | 353 | void ContinuousValueTest::settergetterVectorAsStringTest()
 | 
|---|
| [7d1b6a] | 354 | {
 | 
|---|
 | 355 |   // create instance
 | 
|---|
| [3c5ef5] | 356 |   /*Value<Vector> test(*ValidVectorRange);
 | 
|---|
| [7d1b6a] | 357 | 
 | 
|---|
 | 358 |   // unset calling of get, throws
 | 
|---|
 | 359 | #ifndef NDEBUG
 | 
|---|
 | 360 |   std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
 | 
|---|
 | 361 |   CPPUNIT_ASSERT_THROW(test.getValue(), Assert::AssertionFailure);
 | 
|---|
 | 362 | #endif
 | 
|---|
 | 363 | 
 | 
|---|
 | 364 |   // setting invalid, throws
 | 
|---|
 | 365 | #ifndef NDEBUG
 | 
|---|
 | 366 |   std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
 | 
|---|
 | 367 |   CPPUNIT_ASSERT_THROW(test.setValue(Vector(5,0,0)), Assert::AssertionFailure);
 | 
|---|
 | 368 | #endif
 | 
|---|
 | 369 | #ifndef NDEBUG
 | 
|---|
 | 370 |   std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
 | 
|---|
 | 371 |   CPPUNIT_ASSERT_THROW(test.setValue(Vector(5,20,5)), Assert::AssertionFailure);
 | 
|---|
 | 372 | #endif
 | 
|---|
 | 373 | 
 | 
|---|
 | 374 |   CPPUNIT_ASSERT_EQUAL(false, test.ValueSet);
 | 
|---|
 | 375 |   // checking some valid ones
 | 
|---|
 | 376 |   for (int i=1; i<=4;++i) {
 | 
|---|
 | 377 |     Vector v(i,5,5);
 | 
|---|
 | 378 |     test.setValue(v);
 | 
|---|
 | 379 |     CPPUNIT_ASSERT_EQUAL(true, test.ValueSet);
 | 
|---|
 | 380 |     CPPUNIT_ASSERT_EQUAL(v, test.getValue());
 | 
|---|
| [047cad] | 381 |   }*/
 | 
|---|
| [7d1b6a] | 382 | }
 | 
|---|
 | 383 | 
 | 
|---|
 | 384 | /** Unit test for setters and getters.
 | 
|---|
 | 385 |  *
 | 
|---|
 | 386 |  */
 | 
|---|
 | 387 | void ContinuousValueTest::settergetterVectorTest()
 | 
|---|
 | 388 | {
 | 
|---|
 | 389 |   // unset calling of get, throws
 | 
|---|
| [0d4168] | 390 |   {
 | 
|---|
 | 391 |     Value<Vector> test(*ValidVectorRange);
 | 
|---|
 | 392 |     std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
 | 
|---|
 | 393 |     CPPUNIT_ASSERT_THROW(test.get(), ParameterValueException);
 | 
|---|
 | 394 |   }
 | 
|---|
| [7d1b6a] | 395 | 
 | 
|---|
| [0d4168] | 396 |   // setting invalid and getting it, throws
 | 
|---|
 | 397 |   {
 | 
|---|
 | 398 |     Value<Vector> test(*ValidVectorRange);
 | 
|---|
 | 399 |     std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
 | 
|---|
| [3e6b93] | 400 |     CPPUNIT_ASSERT_THROW(test.set(Vector(5,0,0)), ParameterValueException);
 | 
|---|
| [0d4168] | 401 |     std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
 | 
|---|
| [3e6b93] | 402 |     CPPUNIT_ASSERT_THROW(test.set(Vector(5,20,5)), ParameterValueException);
 | 
|---|
| [0d4168] | 403 |   }
 | 
|---|
| [7d1b6a] | 404 | 
 | 
|---|
 | 405 |   // checking some valid ones
 | 
|---|
| [0d4168] | 406 |   {
 | 
|---|
 | 407 |     Value<Vector> test(*ValidVectorRange);
 | 
|---|
 | 408 |     CPPUNIT_ASSERT_EQUAL(false, test.ValueSet);
 | 
|---|
 | 409 |     for (int i=1; i<=4;++i) {
 | 
|---|
 | 410 |       Vector v(i,5,5);
 | 
|---|
 | 411 |       test.set(v);
 | 
|---|
 | 412 |       CPPUNIT_ASSERT_EQUAL(true, test.ValueSet);
 | 
|---|
 | 413 |       CPPUNIT_ASSERT_EQUAL(v, test.get());
 | 
|---|
 | 414 |     }
 | 
|---|
| [7d1b6a] | 415 |   }
 | 
|---|
 | 416 | }
 | 
|---|
 | 417 | 
 | 
|---|
 | 418 | /** Unit test for comparator.
 | 
|---|
 | 419 |  *
 | 
|---|
 | 420 |  */
 | 
|---|
 | 421 | void ContinuousValueTest::comparatorVectorTest()
 | 
|---|
 | 422 | {
 | 
|---|
 | 423 |   {
 | 
|---|
 | 424 |     // create instance
 | 
|---|
| [3c5ef5] | 425 |     Value<Vector> test(*ValidVectorRange);
 | 
|---|
 | 426 |     Value<Vector> instance(*ValidVectorRange);
 | 
|---|
| [047cad] | 427 |     test.set(Vector(5,6,7));
 | 
|---|
 | 428 |     instance.set(Vector(5,6,7));
 | 
|---|
| [7d1b6a] | 429 | 
 | 
|---|
 | 430 |     // same value, same range
 | 
|---|
 | 431 |     {
 | 
|---|
 | 432 |       CPPUNIT_ASSERT(test == instance);
 | 
|---|
 | 433 |     }
 | 
|---|
 | 434 | 
 | 
|---|
 | 435 |     // different value, same range
 | 
|---|
 | 436 |     {
 | 
|---|
| [047cad] | 437 |       const Vector oldvalue = instance.get();
 | 
|---|
 | 438 |       instance.set(Vector(2,3,4));
 | 
|---|
| [7d1b6a] | 439 |       CPPUNIT_ASSERT(test != instance);
 | 
|---|
| [047cad] | 440 |       instance.set(oldvalue);
 | 
|---|
| [7d1b6a] | 441 |     }
 | 
|---|
 | 442 |   }
 | 
|---|
 | 443 |   {
 | 
|---|
| [3c5ef5] | 444 |     Value<Vector> test(*ValidVectorRange);
 | 
|---|
| [7d1b6a] | 445 |     range<Vector> OtherValidVectorRange(Vector(0,1,2), Vector(20,21,22));
 | 
|---|
| [3c5ef5] | 446 |     Value<Vector> instance(OtherValidVectorRange);
 | 
|---|
| [7d1b6a] | 447 | 
 | 
|---|
| [047cad] | 448 |     test.set(Vector(1,2,3));
 | 
|---|
 | 449 |     instance.set(Vector(1,2,3));
 | 
|---|
| [7d1b6a] | 450 | 
 | 
|---|
 | 451 |     // same value, same range
 | 
|---|
 | 452 |     {
 | 
|---|
 | 453 |       CPPUNIT_ASSERT(test != instance);
 | 
|---|
 | 454 |     }
 | 
|---|
 | 455 | 
 | 
|---|
 | 456 |     // different value, same range
 | 
|---|
 | 457 |     {
 | 
|---|
| [047cad] | 458 |       const Vector oldvalue = instance.get();
 | 
|---|
 | 459 |       instance.set(Vector(2,3,4));
 | 
|---|
| [7d1b6a] | 460 |       CPPUNIT_ASSERT(test != instance);
 | 
|---|
| [047cad] | 461 |       instance.set(oldvalue);
 | 
|---|
| [7d1b6a] | 462 |     }
 | 
|---|
 | 463 |   }
 | 
|---|
 | 464 | }
 | 
|---|