| [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 | 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 | } | 
|---|
| [c68409] | 163 |  | 
|---|
|  | 164 | // checking all valid ones | 
|---|
| [0d4168] | 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 | } | 
|---|
| [6c05d8] | 173 | } | 
|---|
| [c68409] | 174 | } | 
|---|
|  | 175 |  | 
|---|
|  | 176 | /** Unit test for setters and getters. | 
|---|
|  | 177 | * | 
|---|
|  | 178 | */ | 
|---|
| [7d1b6a] | 179 | void ContinuousValueTest::settergetterIntTest() | 
|---|
| [c68409] | 180 | { | 
|---|
|  | 181 | // create instance | 
|---|
| [3c5ef5] | 182 | Value<int> test(*ValidIntRange); | 
|---|
| [c68409] | 183 |  | 
|---|
| [e45c1d] | 184 | // unset calling of get, throws ParameterValueException | 
|---|
| [c68409] | 185 | std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; | 
|---|
| [e45c1d] | 186 | CPPUNIT_ASSERT_THROW(test.get(), ParameterValueException); | 
|---|
| [c68409] | 187 |  | 
|---|
| [0d4168] | 188 | // setting invalid and getting it, throws ParameterValueException | 
|---|
|  | 189 | test.set(5); | 
|---|
| [c68409] | 190 | std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; | 
|---|
| [0d4168] | 191 | CPPUNIT_ASSERT_THROW(test.get(), ParameterValueException); | 
|---|
|  | 192 | test.set(0); | 
|---|
| [c68409] | 193 | std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; | 
|---|
| [0d4168] | 194 | CPPUNIT_ASSERT_THROW(test.get(), ParameterValueException); | 
|---|
| [c68409] | 195 |  | 
|---|
|  | 196 | // checking all valid ones | 
|---|
|  | 197 | for (int i=1; i<=4;++i) { | 
|---|
| [dbb533] | 198 | test.set(i); | 
|---|
|  | 199 | CPPUNIT_ASSERT_EQUAL(i, test.get()); | 
|---|
| [c68409] | 200 | } | 
|---|
|  | 201 | } | 
|---|
|  | 202 |  | 
|---|
|  | 203 | /** Unit test for comparator. | 
|---|
|  | 204 | * | 
|---|
|  | 205 | */ | 
|---|
| [7d1b6a] | 206 | void ContinuousValueTest::comparatorIntTest() | 
|---|
| [c68409] | 207 | { | 
|---|
|  | 208 | { | 
|---|
|  | 209 | // create instance | 
|---|
| [3c5ef5] | 210 | Value<int> test(*ValidIntRange); | 
|---|
|  | 211 | Value<int> instance(*ValidIntRange); | 
|---|
| [047cad] | 212 | test.set(1); | 
|---|
|  | 213 | instance.set(1); | 
|---|
| [c68409] | 214 |  | 
|---|
|  | 215 | // same value, same range | 
|---|
|  | 216 | { | 
|---|
|  | 217 | CPPUNIT_ASSERT(test == instance); | 
|---|
|  | 218 | } | 
|---|
|  | 219 |  | 
|---|
|  | 220 | // different value, same range | 
|---|
|  | 221 | { | 
|---|
| [047cad] | 222 | const int oldvalue = instance.get(); | 
|---|
|  | 223 | instance.set(2); | 
|---|
| [c68409] | 224 | CPPUNIT_ASSERT(test != instance); | 
|---|
| [047cad] | 225 | instance.set(oldvalue); | 
|---|
| [c68409] | 226 | } | 
|---|
|  | 227 | } | 
|---|
|  | 228 | { | 
|---|
| [3c5ef5] | 229 | Value<int> test(*ValidIntRange); | 
|---|
| [7d1b6a] | 230 | range<int> OtherValidIntRange(1,5); | 
|---|
| [3c5ef5] | 231 | Value<int> instance(OtherValidIntRange); | 
|---|
| [c68409] | 232 |  | 
|---|
| [047cad] | 233 | test.set(1); | 
|---|
|  | 234 | instance.set(1); | 
|---|
| [c68409] | 235 |  | 
|---|
|  | 236 | // same value, same range | 
|---|
|  | 237 | { | 
|---|
|  | 238 | CPPUNIT_ASSERT(test != instance); | 
|---|
|  | 239 | } | 
|---|
|  | 240 |  | 
|---|
|  | 241 | // different value, same range | 
|---|
|  | 242 | { | 
|---|
| [047cad] | 243 | const int oldvalue = instance.get(); | 
|---|
|  | 244 | instance.set(2); | 
|---|
| [c68409] | 245 | CPPUNIT_ASSERT(test != instance); | 
|---|
| [047cad] | 246 | instance.set(oldvalue); | 
|---|
| [c68409] | 247 | } | 
|---|
|  | 248 | } | 
|---|
|  | 249 | } | 
|---|
| [7d1b6a] | 250 |  | 
|---|
|  | 251 |  | 
|---|
|  | 252 |  | 
|---|
|  | 253 | /***************************** vector tests ***********************************/ | 
|---|
|  | 254 |  | 
|---|
|  | 255 | /** Unit test for isValid. | 
|---|
|  | 256 | * | 
|---|
|  | 257 | */ | 
|---|
| [047cad] | 258 | void ContinuousValueTest::isValidVectorAsStringTest() | 
|---|
| [7d1b6a] | 259 | { | 
|---|
|  | 260 | // create instance | 
|---|
| [047cad] | 261 | /*ContinuousValue<Vector> test(*ValidVectorRange); | 
|---|
| [7d1b6a] | 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))); | 
|---|
| [047cad] | 283 | CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(20,20,5)));*/ | 
|---|
| [7d1b6a] | 284 | } | 
|---|
|  | 285 |  | 
|---|
|  | 286 | /** Unit test for isValid. | 
|---|
|  | 287 | * | 
|---|
|  | 288 | */ | 
|---|
|  | 289 | void ContinuousValueTest::isValidVectorTest() | 
|---|
|  | 290 | { | 
|---|
|  | 291 | // create instance | 
|---|
| [3c5ef5] | 292 | Value<Vector> test(*ValidVectorRange); | 
|---|
| [7d1b6a] | 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 | 
|---|
| [3c5ef5] | 324 | Value<Vector> test(*ValidVectorRange); | 
|---|
| [7d1b6a] | 325 |  | 
|---|
|  | 326 | // extending range and checking | 
|---|
|  | 327 | for (int i=15; i<=16;++i) | 
|---|
| [047cad] | 328 | CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(i,5,5))); | 
|---|
| [7d1b6a] | 329 | test.setValidRange(range<Vector>(Vector(0,1,2),Vector(20,11,12))); | 
|---|
|  | 330 | for (int i=15; i<=16;++i) | 
|---|
| [047cad] | 331 | CPPUNIT_ASSERT_EQUAL(true, test.isValid(Vector(i,5,5))); | 
|---|
| [7d1b6a] | 332 | } | 
|---|
|  | 333 |  | 
|---|
|  | 334 | { | 
|---|
|  | 335 | // create instance | 
|---|
| [3c5ef5] | 336 | Value<Vector> test(*ValidVectorRange); | 
|---|
| [7d1b6a] | 337 |  | 
|---|
|  | 338 | // lowering range with set value | 
|---|
| [047cad] | 339 | test.set(Vector(4,4,4)); | 
|---|
| [7d1b6a] | 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; | 
|---|
| [e45c1d] | 342 | CPPUNIT_ASSERT_THROW(test.setValidRange(range<Vector>(Vector(1,1,1),Vector(3,3,3))), ParameterValueException); | 
|---|
|  | 343 |  | 
|---|
| [7d1b6a] | 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; | 
|---|
| [e45c1d] | 346 | CPPUNIT_ASSERT_THROW(test.get(), ParameterException); | 
|---|
|  | 347 |  | 
|---|
| [7d1b6a] | 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 | */ | 
|---|
| [047cad] | 356 | void ContinuousValueTest::settergetterVectorAsStringTest() | 
|---|
| [7d1b6a] | 357 | { | 
|---|
|  | 358 | // create instance | 
|---|
| [3c5ef5] | 359 | /*Value<Vector> test(*ValidVectorRange); | 
|---|
| [7d1b6a] | 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()); | 
|---|
| [047cad] | 384 | }*/ | 
|---|
| [7d1b6a] | 385 | } | 
|---|
|  | 386 |  | 
|---|
|  | 387 | /** Unit test for setters and getters. | 
|---|
|  | 388 | * | 
|---|
|  | 389 | */ | 
|---|
|  | 390 | void ContinuousValueTest::settergetterVectorTest() | 
|---|
|  | 391 | { | 
|---|
|  | 392 | // unset calling of get, throws | 
|---|
| [0d4168] | 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 | } | 
|---|
| [7d1b6a] | 398 |  | 
|---|
| [0d4168] | 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 | } | 
|---|
| [7d1b6a] | 409 |  | 
|---|
|  | 410 | // checking some valid ones | 
|---|
| [0d4168] | 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 | } | 
|---|
| [7d1b6a] | 420 | } | 
|---|
|  | 421 | } | 
|---|
|  | 422 |  | 
|---|
|  | 423 | /** Unit test for comparator. | 
|---|
|  | 424 | * | 
|---|
|  | 425 | */ | 
|---|
|  | 426 | void ContinuousValueTest::comparatorVectorTest() | 
|---|
|  | 427 | { | 
|---|
|  | 428 | { | 
|---|
|  | 429 | // create instance | 
|---|
| [3c5ef5] | 430 | Value<Vector> test(*ValidVectorRange); | 
|---|
|  | 431 | Value<Vector> instance(*ValidVectorRange); | 
|---|
| [047cad] | 432 | test.set(Vector(5,6,7)); | 
|---|
|  | 433 | instance.set(Vector(5,6,7)); | 
|---|
| [7d1b6a] | 434 |  | 
|---|
|  | 435 | // same value, same range | 
|---|
|  | 436 | { | 
|---|
|  | 437 | CPPUNIT_ASSERT(test == instance); | 
|---|
|  | 438 | } | 
|---|
|  | 439 |  | 
|---|
|  | 440 | // different value, same range | 
|---|
|  | 441 | { | 
|---|
| [047cad] | 442 | const Vector oldvalue = instance.get(); | 
|---|
|  | 443 | instance.set(Vector(2,3,4)); | 
|---|
| [7d1b6a] | 444 | CPPUNIT_ASSERT(test != instance); | 
|---|
| [047cad] | 445 | instance.set(oldvalue); | 
|---|
| [7d1b6a] | 446 | } | 
|---|
|  | 447 | } | 
|---|
|  | 448 | { | 
|---|
| [3c5ef5] | 449 | Value<Vector> test(*ValidVectorRange); | 
|---|
| [7d1b6a] | 450 | range<Vector> OtherValidVectorRange(Vector(0,1,2), Vector(20,21,22)); | 
|---|
| [3c5ef5] | 451 | Value<Vector> instance(OtherValidVectorRange); | 
|---|
| [7d1b6a] | 452 |  | 
|---|
| [047cad] | 453 | test.set(Vector(1,2,3)); | 
|---|
|  | 454 | instance.set(Vector(1,2,3)); | 
|---|
| [7d1b6a] | 455 |  | 
|---|
|  | 456 | // same value, same range | 
|---|
|  | 457 | { | 
|---|
|  | 458 | CPPUNIT_ASSERT(test != instance); | 
|---|
|  | 459 | } | 
|---|
|  | 460 |  | 
|---|
|  | 461 | // different value, same range | 
|---|
|  | 462 | { | 
|---|
| [047cad] | 463 | const Vector oldvalue = instance.get(); | 
|---|
|  | 464 | instance.set(Vector(2,3,4)); | 
|---|
| [7d1b6a] | 465 | CPPUNIT_ASSERT(test != instance); | 
|---|
| [047cad] | 466 | instance.set(oldvalue); | 
|---|
| [7d1b6a] | 467 | } | 
|---|
|  | 468 | } | 
|---|
|  | 469 | } | 
|---|