| 1 | /*
 | 
|---|
| 2 |  * Project: MoleCuilder
 | 
|---|
| 3 |  * Description: creates and alters molecular systems
 | 
|---|
| 4 |  * Copyright (C)  2010-2012 University of Bonn. All rights reserved.
 | 
|---|
| 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/>.
 | 
|---|
| 21 |  */
 | 
|---|
| 22 | 
 | 
|---|
| 23 | /*
 | 
|---|
| 24 |  * ContinuousValueTest.cpp
 | 
|---|
| 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 | 
 | 
|---|
| 35 | #include "ContinuousValueTest.hpp"
 | 
|---|
| 36 | 
 | 
|---|
| 37 | #include <cppunit/CompilerOutputter.h>
 | 
|---|
| 38 | #include <cppunit/extensions/TestFactoryRegistry.h>
 | 
|---|
| 39 | #include <cppunit/ui/text/TestRunner.h>
 | 
|---|
| 40 | 
 | 
|---|
| 41 | #include "Parameters/Value.hpp"
 | 
|---|
| 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 | 
 | 
|---|
| 56 |   ValidIntRange = new range<int>(1,4);
 | 
|---|
| 57 |   ValidVectorRange = new range<Vector>(Vector(0,1,2), Vector(10,11,12));
 | 
|---|
| 58 | }
 | 
|---|
| 59 | 
 | 
|---|
| 60 | void ContinuousValueTest::tearDown()
 | 
|---|
| 61 | {
 | 
|---|
| 62 |   delete ValidIntRange;
 | 
|---|
| 63 |   delete ValidVectorRange;
 | 
|---|
| 64 | }
 | 
|---|
| 65 | 
 | 
|---|
| 66 | /************************************ tests ***********************************/
 | 
|---|
| 67 | 
 | 
|---|
| 68 | /** Unit test for isValid.
 | 
|---|
| 69 |  *
 | 
|---|
| 70 |  */
 | 
|---|
| 71 | void ContinuousValueTest::isValidIntAsStringTest()
 | 
|---|
| 72 | {
 | 
|---|
| 73 |   // create instance
 | 
|---|
| 74 |   Value<int> test(*ValidIntRange);
 | 
|---|
| 75 | 
 | 
|---|
| 76 |   // checking valid values
 | 
|---|
| 77 |   for (int i=1; i<=4;++i)
 | 
|---|
| 78 |     CPPUNIT_ASSERT_EQUAL(true, test.isValidAsString(toString(i)));
 | 
|---|
| 79 | 
 | 
|---|
| 80 |   // checking invalid values
 | 
|---|
| 81 |   for (int i=-10; i<=0;++i)
 | 
|---|
| 82 |     CPPUNIT_ASSERT_EQUAL(false, test.isValidAsString(toString(i)));
 | 
|---|
| 83 |   for (int i=5; i<=0;++i)
 | 
|---|
| 84 |     CPPUNIT_ASSERT_EQUAL(false, test.isValidAsString(toString(i)));
 | 
|---|
| 85 | }
 | 
|---|
| 86 | 
 | 
|---|
| 87 | /** Unit test for isValid.
 | 
|---|
| 88 |  *
 | 
|---|
| 89 |  */
 | 
|---|
| 90 | void ContinuousValueTest::isValidIntTest()
 | 
|---|
| 91 | {
 | 
|---|
| 92 |   // create instance
 | 
|---|
| 93 |   Value<int> test(*ValidIntRange);
 | 
|---|
| 94 | 
 | 
|---|
| 95 |   // checking valid values
 | 
|---|
| 96 |   for (int i=1; i<=4;++i)
 | 
|---|
| 97 |     CPPUNIT_ASSERT_EQUAL(true, test.isValid(i));
 | 
|---|
| 98 | 
 | 
|---|
| 99 |   // checking invalid values
 | 
|---|
| 100 |   for (int i=-10; i<=0;++i)
 | 
|---|
| 101 |     CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
 | 
|---|
| 102 |   for (int i=5; i<=0;++i)
 | 
|---|
| 103 |     CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
 | 
|---|
| 104 | }
 | 
|---|
| 105 | 
 | 
|---|
| 106 | /** Unit test for setting/getting valid range.
 | 
|---|
| 107 |  *
 | 
|---|
| 108 |  */
 | 
|---|
| 109 | void ContinuousValueTest::setgetValidIntRangeTest()
 | 
|---|
| 110 | {
 | 
|---|
| 111 |   {
 | 
|---|
| 112 |     // create instance
 | 
|---|
| 113 |     Value<int> test(*ValidIntRange);
 | 
|---|
| 114 | 
 | 
|---|
| 115 |     // extending range and checking
 | 
|---|
| 116 |     for (int i=5; i<=6;++i)
 | 
|---|
| 117 |       CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
 | 
|---|
| 118 |     test.setValidRange(range<int>(1,6));
 | 
|---|
| 119 |     for (int i=5; i<=6;++i)
 | 
|---|
| 120 |       CPPUNIT_ASSERT_EQUAL(true, test.isValid(i));
 | 
|---|
| 121 |   }
 | 
|---|
| 122 | 
 | 
|---|
| 123 |   {
 | 
|---|
| 124 |     // create instance
 | 
|---|
| 125 |     Value<int> test(*ValidIntRange);
 | 
|---|
| 126 | 
 | 
|---|
| 127 |     // lowering range with set value
 | 
|---|
| 128 |     test.set(4);
 | 
|---|
| 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;
 | 
|---|
| 131 |     CPPUNIT_ASSERT_THROW(test.setValidRange(range<int>(1,3)), ParameterValueException);
 | 
|---|
| 132 | 
 | 
|---|
| 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;
 | 
|---|
| 135 |     CPPUNIT_ASSERT_THROW(test.get(), ParameterValueException);
 | 
|---|
| 136 | 
 | 
|---|
| 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 |  */
 | 
|---|
| 145 | void ContinuousValueTest::settergetterIntAsStringTest()
 | 
|---|
| 146 | {
 | 
|---|
| 147 |   // unset calling of get, throws ParameterValueException
 | 
|---|
| 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 |   }
 | 
|---|
| 153 | 
 | 
|---|
| 154 |   // setting invalid and getting it, throws ParameterValueException
 | 
|---|
| 155 |   {
 | 
|---|
| 156 |     Value<int> test(*ValidIntRange);
 | 
|---|
| 157 |     test.setAsString(toString(5));
 | 
|---|
| 158 |     CPPUNIT_ASSERT_THROW(test.getAsString(), ParameterValueException);
 | 
|---|
| 159 |     test.setAsString(toString(0));
 | 
|---|
| 160 |     std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
 | 
|---|
| 161 |     CPPUNIT_ASSERT_THROW(test.getAsString(), ParameterValueException);
 | 
|---|
| 162 |   }
 | 
|---|
| 163 | 
 | 
|---|
| 164 |   // checking all valid ones
 | 
|---|
| 165 |   {
 | 
|---|
| 166 |     Value<int> test(*ValidIntRange);
 | 
|---|
| 167 |     CPPUNIT_ASSERT_EQUAL(false, test.ValueSet);
 | 
|---|
| 168 |     for (int i=1; i<=4;++i) {
 | 
|---|
| 169 |       test.setAsString(toString(i));
 | 
|---|
| 170 |       CPPUNIT_ASSERT_EQUAL(true, test.ValueSet);
 | 
|---|
| 171 |       CPPUNIT_ASSERT_EQUAL(toString(i), test.getAsString());
 | 
|---|
| 172 |     }
 | 
|---|
| 173 |   }
 | 
|---|
| 174 | }
 | 
|---|
| 175 | 
 | 
|---|
| 176 | /** Unit test for setters and getters.
 | 
|---|
| 177 |  *
 | 
|---|
| 178 |  */
 | 
|---|
| 179 | void ContinuousValueTest::settergetterIntTest()
 | 
|---|
| 180 | {
 | 
|---|
| 181 |   // create instance
 | 
|---|
| 182 |   Value<int> test(*ValidIntRange);
 | 
|---|
| 183 | 
 | 
|---|
| 184 |   // unset calling of get, throws ParameterValueException
 | 
|---|
| 185 |   std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
 | 
|---|
| 186 |   CPPUNIT_ASSERT_THROW(test.get(), ParameterValueException);
 | 
|---|
| 187 | 
 | 
|---|
| 188 |   // setting invalid and getting it, throws ParameterValueException
 | 
|---|
| 189 |   test.set(5);
 | 
|---|
| 190 |   std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
 | 
|---|
| 191 |   CPPUNIT_ASSERT_THROW(test.get(), ParameterValueException);
 | 
|---|
| 192 |   test.set(0);
 | 
|---|
| 193 |   std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
 | 
|---|
| 194 |   CPPUNIT_ASSERT_THROW(test.get(), ParameterValueException);
 | 
|---|
| 195 | 
 | 
|---|
| 196 |   // checking all valid ones
 | 
|---|
| 197 |   for (int i=1; i<=4;++i) {
 | 
|---|
| 198 |     test.set(i);
 | 
|---|
| 199 |     CPPUNIT_ASSERT_EQUAL(i, test.get());
 | 
|---|
| 200 |   }
 | 
|---|
| 201 | }
 | 
|---|
| 202 | 
 | 
|---|
| 203 | /** Unit test for comparator.
 | 
|---|
| 204 |  *
 | 
|---|
| 205 |  */
 | 
|---|
| 206 | void ContinuousValueTest::comparatorIntTest()
 | 
|---|
| 207 | {
 | 
|---|
| 208 |   {
 | 
|---|
| 209 |     // create instance
 | 
|---|
| 210 |     Value<int> test(*ValidIntRange);
 | 
|---|
| 211 |     Value<int> instance(*ValidIntRange);
 | 
|---|
| 212 |     test.set(1);
 | 
|---|
| 213 |     instance.set(1);
 | 
|---|
| 214 | 
 | 
|---|
| 215 |     // same value, same range
 | 
|---|
| 216 |     {
 | 
|---|
| 217 |       CPPUNIT_ASSERT(test == instance);
 | 
|---|
| 218 |     }
 | 
|---|
| 219 | 
 | 
|---|
| 220 |     // different value, same range
 | 
|---|
| 221 |     {
 | 
|---|
| 222 |       const int oldvalue = instance.get();
 | 
|---|
| 223 |       instance.set(2);
 | 
|---|
| 224 |       CPPUNIT_ASSERT(test != instance);
 | 
|---|
| 225 |       instance.set(oldvalue);
 | 
|---|
| 226 |     }
 | 
|---|
| 227 |   }
 | 
|---|
| 228 |   {
 | 
|---|
| 229 |     Value<int> test(*ValidIntRange);
 | 
|---|
| 230 |     range<int> OtherValidIntRange(1,5);
 | 
|---|
| 231 |     Value<int> instance(OtherValidIntRange);
 | 
|---|
| 232 | 
 | 
|---|
| 233 |     test.set(1);
 | 
|---|
| 234 |     instance.set(1);
 | 
|---|
| 235 | 
 | 
|---|
| 236 |     // same value, same range
 | 
|---|
| 237 |     {
 | 
|---|
| 238 |       CPPUNIT_ASSERT(test != instance);
 | 
|---|
| 239 |     }
 | 
|---|
| 240 | 
 | 
|---|
| 241 |     // different value, same range
 | 
|---|
| 242 |     {
 | 
|---|
| 243 |       const int oldvalue = instance.get();
 | 
|---|
| 244 |       instance.set(2);
 | 
|---|
| 245 |       CPPUNIT_ASSERT(test != instance);
 | 
|---|
| 246 |       instance.set(oldvalue);
 | 
|---|
| 247 |     }
 | 
|---|
| 248 |   }
 | 
|---|
| 249 | }
 | 
|---|
| 250 | 
 | 
|---|
| 251 | 
 | 
|---|
| 252 | 
 | 
|---|
| 253 | /***************************** vector tests ***********************************/
 | 
|---|
| 254 | 
 | 
|---|
| 255 | /** Unit test for isValid.
 | 
|---|
| 256 |  *
 | 
|---|
| 257 |  */
 | 
|---|
| 258 | void ContinuousValueTest::isValidVectorAsStringTest()
 | 
|---|
| 259 | {
 | 
|---|
| 260 |   // create instance
 | 
|---|
| 261 |   /*ContinuousValue<Vector> test(*ValidVectorRange);
 | 
|---|
| 262 | 
 | 
|---|
| 263 |   // checking valid values
 | 
|---|
| 264 |   CPPUNIT_ASSERT_EQUAL(true, test.isValidValue(Vector(0,1,2)));
 | 
|---|
| 265 |   CPPUNIT_ASSERT_EQUAL(true, test.isValidValue(Vector(9.9,10.9,11.9)));
 | 
|---|
| 266 |   CPPUNIT_ASSERT_EQUAL(true, test.isValidValue(Vector(5,5,5)));
 | 
|---|
| 267 | 
 | 
|---|
| 268 |   // checking invalid values
 | 
|---|
| 269 |   CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(-0.1,0.9,1.9)));
 | 
|---|
| 270 |   CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(10.1,11.1,12.1)));
 | 
|---|
| 271 |   CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(5,5,-1)));
 | 
|---|
| 272 |   CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(5,-1,5)));
 | 
|---|
| 273 |   CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(-1,5,5)));
 | 
|---|
| 274 |   CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(5,5,20)));
 | 
|---|
| 275 |   CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(5,20,5)));
 | 
|---|
| 276 |   CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(20,5,5)));
 | 
|---|
| 277 |   CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(0,0,0)));
 | 
|---|
| 278 |   CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(5,-1,-1)));
 | 
|---|
| 279 |   CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(-1,5,-1)));
 | 
|---|
| 280 |   CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(-1,-1,5)));
 | 
|---|
| 281 |   CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(5,20,20)));
 | 
|---|
| 282 |   CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(20,5,20)));
 | 
|---|
| 283 |   CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(20,20,5)));*/
 | 
|---|
| 284 | }
 | 
|---|
| 285 | 
 | 
|---|
| 286 | /** Unit test for isValid.
 | 
|---|
| 287 |  *
 | 
|---|
| 288 |  */
 | 
|---|
| 289 | void ContinuousValueTest::isValidVectorTest()
 | 
|---|
| 290 | {
 | 
|---|
| 291 |   // create instance
 | 
|---|
| 292 |   Value<Vector> test(*ValidVectorRange);
 | 
|---|
| 293 | 
 | 
|---|
| 294 |   // checking valid values
 | 
|---|
| 295 |   CPPUNIT_ASSERT_EQUAL(true, test.isValid(Vector(0,1,2)));
 | 
|---|
| 296 |   CPPUNIT_ASSERT_EQUAL(true, test.isValid(Vector(9.9,10.9,11.9)));
 | 
|---|
| 297 |   CPPUNIT_ASSERT_EQUAL(true, test.isValid(Vector(5,5,5)));
 | 
|---|
| 298 | 
 | 
|---|
| 299 |   // checking invalid values
 | 
|---|
| 300 |   CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(-0.1,0.9,1.9)));
 | 
|---|
| 301 |   CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(10.1,11.1,12.1)));
 | 
|---|
| 302 |   CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(5,5,-1)));
 | 
|---|
| 303 |   CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(5,-1,5)));
 | 
|---|
| 304 |   CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(-1,5,5)));
 | 
|---|
| 305 |   CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(5,5,20)));
 | 
|---|
| 306 |   CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(5,20,5)));
 | 
|---|
| 307 |   CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(20,5,5)));
 | 
|---|
| 308 |   CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(0,0,0)));
 | 
|---|
| 309 |   CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(5,-1,-1)));
 | 
|---|
| 310 |   CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(-1,5,-1)));
 | 
|---|
| 311 |   CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(-1,-1,5)));
 | 
|---|
| 312 |   CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(5,20,20)));
 | 
|---|
| 313 |   CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(20,5,20)));
 | 
|---|
| 314 |   CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(20,20,5)));
 | 
|---|
| 315 | }
 | 
|---|
| 316 | 
 | 
|---|
| 317 | /** Unit test for setting/getting valid range.
 | 
|---|
| 318 |  *
 | 
|---|
| 319 |  */
 | 
|---|
| 320 | void ContinuousValueTest::setgetValidVectorRangeTest()
 | 
|---|
| 321 | {
 | 
|---|
| 322 |   {
 | 
|---|
| 323 |     // create instance
 | 
|---|
| 324 |     Value<Vector> test(*ValidVectorRange);
 | 
|---|
| 325 | 
 | 
|---|
| 326 |     // extending range and checking
 | 
|---|
| 327 |     for (int i=15; i<=16;++i)
 | 
|---|
| 328 |       CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(i,5,5)));
 | 
|---|
| 329 |     test.setValidRange(range<Vector>(Vector(0,1,2),Vector(20,11,12)));
 | 
|---|
| 330 |     for (int i=15; i<=16;++i)
 | 
|---|
| 331 |       CPPUNIT_ASSERT_EQUAL(true, test.isValid(Vector(i,5,5)));
 | 
|---|
| 332 |   }
 | 
|---|
| 333 | 
 | 
|---|
| 334 |   {
 | 
|---|
| 335 |     // create instance
 | 
|---|
| 336 |     Value<Vector> test(*ValidVectorRange);
 | 
|---|
| 337 | 
 | 
|---|
| 338 |     // lowering range with set value
 | 
|---|
| 339 |     test.set(Vector(4,4,4));
 | 
|---|
| 340 |     CPPUNIT_ASSERT_EQUAL(true, test.ValueSet);
 | 
|---|
| 341 |     std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
 | 
|---|
| 342 |     CPPUNIT_ASSERT_THROW(test.setValidRange(range<Vector>(Vector(1,1,1),Vector(3,3,3))), ParameterValueException);
 | 
|---|
| 343 | 
 | 
|---|
| 344 |     // no value is not set
 | 
|---|
| 345 |     std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
 | 
|---|
| 346 |     CPPUNIT_ASSERT_THROW(test.get(), ParameterException);
 | 
|---|
| 347 | 
 | 
|---|
| 348 |     // value gets invalidated in either case
 | 
|---|
| 349 |     CPPUNIT_ASSERT_EQUAL(false, test.ValueSet);
 | 
|---|
| 350 |   }
 | 
|---|
| 351 | }
 | 
|---|
| 352 | 
 | 
|---|
| 353 | /** Unit test for setValue and getValue.
 | 
|---|
| 354 |  *
 | 
|---|
| 355 |  */
 | 
|---|
| 356 | void ContinuousValueTest::settergetterVectorAsStringTest()
 | 
|---|
| 357 | {
 | 
|---|
| 358 |   // create instance
 | 
|---|
| 359 |   /*Value<Vector> test(*ValidVectorRange);
 | 
|---|
| 360 | 
 | 
|---|
| 361 |   // unset calling of get, throws
 | 
|---|
| 362 | #ifndef NDEBUG
 | 
|---|
| 363 |   std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
 | 
|---|
| 364 |   CPPUNIT_ASSERT_THROW(test.getValue(), Assert::AssertionFailure);
 | 
|---|
| 365 | #endif
 | 
|---|
| 366 | 
 | 
|---|
| 367 |   // setting invalid, throws
 | 
|---|
| 368 | #ifndef NDEBUG
 | 
|---|
| 369 |   std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
 | 
|---|
| 370 |   CPPUNIT_ASSERT_THROW(test.setValue(Vector(5,0,0)), Assert::AssertionFailure);
 | 
|---|
| 371 | #endif
 | 
|---|
| 372 | #ifndef NDEBUG
 | 
|---|
| 373 |   std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
 | 
|---|
| 374 |   CPPUNIT_ASSERT_THROW(test.setValue(Vector(5,20,5)), Assert::AssertionFailure);
 | 
|---|
| 375 | #endif
 | 
|---|
| 376 | 
 | 
|---|
| 377 |   CPPUNIT_ASSERT_EQUAL(false, test.ValueSet);
 | 
|---|
| 378 |   // checking some valid ones
 | 
|---|
| 379 |   for (int i=1; i<=4;++i) {
 | 
|---|
| 380 |     Vector v(i,5,5);
 | 
|---|
| 381 |     test.setValue(v);
 | 
|---|
| 382 |     CPPUNIT_ASSERT_EQUAL(true, test.ValueSet);
 | 
|---|
| 383 |     CPPUNIT_ASSERT_EQUAL(v, test.getValue());
 | 
|---|
| 384 |   }*/
 | 
|---|
| 385 | }
 | 
|---|
| 386 | 
 | 
|---|
| 387 | /** Unit test for setters and getters.
 | 
|---|
| 388 |  *
 | 
|---|
| 389 |  */
 | 
|---|
| 390 | void ContinuousValueTest::settergetterVectorTest()
 | 
|---|
| 391 | {
 | 
|---|
| 392 |   // unset calling of get, throws
 | 
|---|
| 393 |   {
 | 
|---|
| 394 |     Value<Vector> test(*ValidVectorRange);
 | 
|---|
| 395 |     std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
 | 
|---|
| 396 |     CPPUNIT_ASSERT_THROW(test.get(), ParameterValueException);
 | 
|---|
| 397 |   }
 | 
|---|
| 398 | 
 | 
|---|
| 399 |   // setting invalid and getting it, throws
 | 
|---|
| 400 |   {
 | 
|---|
| 401 |     Value<Vector> test(*ValidVectorRange);
 | 
|---|
| 402 |     test.set(Vector(5,0,0));
 | 
|---|
| 403 |     std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
 | 
|---|
| 404 |     CPPUNIT_ASSERT_THROW(test.get(), ParameterValueException);
 | 
|---|
| 405 |     test.set(Vector(5,20,5));
 | 
|---|
| 406 |     std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
 | 
|---|
| 407 |     CPPUNIT_ASSERT_THROW(test.get(), ParameterValueException);
 | 
|---|
| 408 |   }
 | 
|---|
| 409 | 
 | 
|---|
| 410 |   // checking some valid ones
 | 
|---|
| 411 |   {
 | 
|---|
| 412 |     Value<Vector> test(*ValidVectorRange);
 | 
|---|
| 413 |     CPPUNIT_ASSERT_EQUAL(false, test.ValueSet);
 | 
|---|
| 414 |     for (int i=1; i<=4;++i) {
 | 
|---|
| 415 |       Vector v(i,5,5);
 | 
|---|
| 416 |       test.set(v);
 | 
|---|
| 417 |       CPPUNIT_ASSERT_EQUAL(true, test.ValueSet);
 | 
|---|
| 418 |       CPPUNIT_ASSERT_EQUAL(v, test.get());
 | 
|---|
| 419 |     }
 | 
|---|
| 420 |   }
 | 
|---|
| 421 | }
 | 
|---|
| 422 | 
 | 
|---|
| 423 | /** Unit test for comparator.
 | 
|---|
| 424 |  *
 | 
|---|
| 425 |  */
 | 
|---|
| 426 | void ContinuousValueTest::comparatorVectorTest()
 | 
|---|
| 427 | {
 | 
|---|
| 428 |   {
 | 
|---|
| 429 |     // create instance
 | 
|---|
| 430 |     Value<Vector> test(*ValidVectorRange);
 | 
|---|
| 431 |     Value<Vector> instance(*ValidVectorRange);
 | 
|---|
| 432 |     test.set(Vector(5,6,7));
 | 
|---|
| 433 |     instance.set(Vector(5,6,7));
 | 
|---|
| 434 | 
 | 
|---|
| 435 |     // same value, same range
 | 
|---|
| 436 |     {
 | 
|---|
| 437 |       CPPUNIT_ASSERT(test == instance);
 | 
|---|
| 438 |     }
 | 
|---|
| 439 | 
 | 
|---|
| 440 |     // different value, same range
 | 
|---|
| 441 |     {
 | 
|---|
| 442 |       const Vector oldvalue = instance.get();
 | 
|---|
| 443 |       instance.set(Vector(2,3,4));
 | 
|---|
| 444 |       CPPUNIT_ASSERT(test != instance);
 | 
|---|
| 445 |       instance.set(oldvalue);
 | 
|---|
| 446 |     }
 | 
|---|
| 447 |   }
 | 
|---|
| 448 |   {
 | 
|---|
| 449 |     Value<Vector> test(*ValidVectorRange);
 | 
|---|
| 450 |     range<Vector> OtherValidVectorRange(Vector(0,1,2), Vector(20,21,22));
 | 
|---|
| 451 |     Value<Vector> instance(OtherValidVectorRange);
 | 
|---|
| 452 | 
 | 
|---|
| 453 |     test.set(Vector(1,2,3));
 | 
|---|
| 454 |     instance.set(Vector(1,2,3));
 | 
|---|
| 455 | 
 | 
|---|
| 456 |     // same value, same range
 | 
|---|
| 457 |     {
 | 
|---|
| 458 |       CPPUNIT_ASSERT(test != instance);
 | 
|---|
| 459 |     }
 | 
|---|
| 460 | 
 | 
|---|
| 461 |     // different value, same range
 | 
|---|
| 462 |     {
 | 
|---|
| 463 |       const Vector oldvalue = instance.get();
 | 
|---|
| 464 |       instance.set(Vector(2,3,4));
 | 
|---|
| 465 |       CPPUNIT_ASSERT(test != instance);
 | 
|---|
| 466 |       instance.set(oldvalue);
 | 
|---|
| 467 |     }
 | 
|---|
| 468 |   }
 | 
|---|
| 469 | }
 | 
|---|