| [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 | { | 
|---|
|  | 147 | // create instance | 
|---|
| [3c5ef5] | 148 | Value<int> test(*ValidIntRange); | 
|---|
| [c68409] | 149 |  | 
|---|
| [e45c1d] | 150 | // unset calling of get, throws ParameterValueException | 
|---|
| [c68409] | 151 | std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; | 
|---|
| [e45c1d] | 152 | CPPUNIT_ASSERT_THROW(test.getAsString(), ParameterValueException); | 
|---|
| [c68409] | 153 |  | 
|---|
| [e45c1d] | 154 | // setting invalid, throws ParameterValueException | 
|---|
| [c68409] | 155 | std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; | 
|---|
| [e45c1d] | 156 | CPPUNIT_ASSERT_THROW(test.setAsString(toString(5)), ParameterValueException); | 
|---|
| [c68409] | 157 | std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; | 
|---|
| [e45c1d] | 158 | CPPUNIT_ASSERT_THROW(test.setAsString(toString(0)), ParameterValueException); | 
|---|
| [c68409] | 159 |  | 
|---|
|  | 160 | CPPUNIT_ASSERT_EQUAL(false, test.ValueSet); | 
|---|
|  | 161 | // checking all valid ones | 
|---|
|  | 162 | for (int i=1; i<=4;++i) { | 
|---|
| [047cad] | 163 | test.setAsString(toString(i)); | 
|---|
| [c68409] | 164 | CPPUNIT_ASSERT_EQUAL(true, test.ValueSet); | 
|---|
| [047cad] | 165 | CPPUNIT_ASSERT_EQUAL(toString(i), test.getAsString()); | 
|---|
| [6c05d8] | 166 | } | 
|---|
| [c68409] | 167 | } | 
|---|
|  | 168 |  | 
|---|
|  | 169 | /** Unit test for setters and getters. | 
|---|
|  | 170 | * | 
|---|
|  | 171 | */ | 
|---|
| [7d1b6a] | 172 | void ContinuousValueTest::settergetterIntTest() | 
|---|
| [c68409] | 173 | { | 
|---|
|  | 174 | // create instance | 
|---|
| [3c5ef5] | 175 | Value<int> test(*ValidIntRange); | 
|---|
| [c68409] | 176 |  | 
|---|
| [e45c1d] | 177 | // unset calling of get, throws ParameterValueException | 
|---|
| [c68409] | 178 | std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; | 
|---|
| [e45c1d] | 179 | CPPUNIT_ASSERT_THROW(test.get(), ParameterValueException); | 
|---|
| [c68409] | 180 |  | 
|---|
| [e45c1d] | 181 | // setting invalid, throws ParameterValueException | 
|---|
| [c68409] | 182 | std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; | 
|---|
| [e45c1d] | 183 | CPPUNIT_ASSERT_THROW(test.set(5), 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.set(0), ParameterValueException); | 
|---|
| [c68409] | 186 |  | 
|---|
|  | 187 | // checking all valid ones | 
|---|
|  | 188 | for (int i=1; i<=4;++i) { | 
|---|
| [dbb533] | 189 | test.set(i); | 
|---|
|  | 190 | CPPUNIT_ASSERT_EQUAL(i, test.get()); | 
|---|
| [c68409] | 191 | } | 
|---|
|  | 192 | } | 
|---|
|  | 193 |  | 
|---|
|  | 194 | /** Unit test for comparator. | 
|---|
|  | 195 | * | 
|---|
|  | 196 | */ | 
|---|
| [7d1b6a] | 197 | void ContinuousValueTest::comparatorIntTest() | 
|---|
| [c68409] | 198 | { | 
|---|
|  | 199 | { | 
|---|
|  | 200 | // create instance | 
|---|
| [3c5ef5] | 201 | Value<int> test(*ValidIntRange); | 
|---|
|  | 202 | Value<int> instance(*ValidIntRange); | 
|---|
| [047cad] | 203 | test.set(1); | 
|---|
|  | 204 | instance.set(1); | 
|---|
| [c68409] | 205 |  | 
|---|
|  | 206 | // same value, same range | 
|---|
|  | 207 | { | 
|---|
|  | 208 | CPPUNIT_ASSERT(test == instance); | 
|---|
|  | 209 | } | 
|---|
|  | 210 |  | 
|---|
|  | 211 | // different value, same range | 
|---|
|  | 212 | { | 
|---|
| [047cad] | 213 | const int oldvalue = instance.get(); | 
|---|
|  | 214 | instance.set(2); | 
|---|
| [c68409] | 215 | CPPUNIT_ASSERT(test != instance); | 
|---|
| [047cad] | 216 | instance.set(oldvalue); | 
|---|
| [c68409] | 217 | } | 
|---|
|  | 218 | } | 
|---|
|  | 219 | { | 
|---|
| [3c5ef5] | 220 | Value<int> test(*ValidIntRange); | 
|---|
| [7d1b6a] | 221 | range<int> OtherValidIntRange(1,5); | 
|---|
| [3c5ef5] | 222 | Value<int> instance(OtherValidIntRange); | 
|---|
| [c68409] | 223 |  | 
|---|
| [047cad] | 224 | test.set(1); | 
|---|
|  | 225 | instance.set(1); | 
|---|
| [c68409] | 226 |  | 
|---|
|  | 227 | // same value, same range | 
|---|
|  | 228 | { | 
|---|
|  | 229 | CPPUNIT_ASSERT(test != instance); | 
|---|
|  | 230 | } | 
|---|
|  | 231 |  | 
|---|
|  | 232 | // different value, same range | 
|---|
|  | 233 | { | 
|---|
| [047cad] | 234 | const int oldvalue = instance.get(); | 
|---|
|  | 235 | instance.set(2); | 
|---|
| [c68409] | 236 | CPPUNIT_ASSERT(test != instance); | 
|---|
| [047cad] | 237 | instance.set(oldvalue); | 
|---|
| [c68409] | 238 | } | 
|---|
|  | 239 | } | 
|---|
|  | 240 | } | 
|---|
| [7d1b6a] | 241 |  | 
|---|
|  | 242 |  | 
|---|
|  | 243 |  | 
|---|
|  | 244 | /***************************** vector tests ***********************************/ | 
|---|
|  | 245 |  | 
|---|
|  | 246 | /** Unit test for isValid. | 
|---|
|  | 247 | * | 
|---|
|  | 248 | */ | 
|---|
| [047cad] | 249 | void ContinuousValueTest::isValidVectorAsStringTest() | 
|---|
| [7d1b6a] | 250 | { | 
|---|
|  | 251 | // create instance | 
|---|
| [047cad] | 252 | /*ContinuousValue<Vector> test(*ValidVectorRange); | 
|---|
| [7d1b6a] | 253 |  | 
|---|
|  | 254 | // checking valid values | 
|---|
|  | 255 | CPPUNIT_ASSERT_EQUAL(true, test.isValidValue(Vector(0,1,2))); | 
|---|
|  | 256 | CPPUNIT_ASSERT_EQUAL(true, test.isValidValue(Vector(9.9,10.9,11.9))); | 
|---|
|  | 257 | CPPUNIT_ASSERT_EQUAL(true, test.isValidValue(Vector(5,5,5))); | 
|---|
|  | 258 |  | 
|---|
|  | 259 | // checking invalid values | 
|---|
|  | 260 | CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(-0.1,0.9,1.9))); | 
|---|
|  | 261 | CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(10.1,11.1,12.1))); | 
|---|
|  | 262 | CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(5,5,-1))); | 
|---|
|  | 263 | CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(5,-1,5))); | 
|---|
|  | 264 | CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(-1,5,5))); | 
|---|
|  | 265 | CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(5,5,20))); | 
|---|
|  | 266 | CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(5,20,5))); | 
|---|
|  | 267 | CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(20,5,5))); | 
|---|
|  | 268 | CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(0,0,0))); | 
|---|
|  | 269 | CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(5,-1,-1))); | 
|---|
|  | 270 | CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(-1,5,-1))); | 
|---|
|  | 271 | CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(-1,-1,5))); | 
|---|
|  | 272 | CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(5,20,20))); | 
|---|
|  | 273 | CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(20,5,20))); | 
|---|
| [047cad] | 274 | CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(20,20,5)));*/ | 
|---|
| [7d1b6a] | 275 | } | 
|---|
|  | 276 |  | 
|---|
|  | 277 | /** Unit test for isValid. | 
|---|
|  | 278 | * | 
|---|
|  | 279 | */ | 
|---|
|  | 280 | void ContinuousValueTest::isValidVectorTest() | 
|---|
|  | 281 | { | 
|---|
|  | 282 | // create instance | 
|---|
| [3c5ef5] | 283 | Value<Vector> test(*ValidVectorRange); | 
|---|
| [7d1b6a] | 284 |  | 
|---|
|  | 285 | // checking valid values | 
|---|
|  | 286 | CPPUNIT_ASSERT_EQUAL(true, test.isValid(Vector(0,1,2))); | 
|---|
|  | 287 | CPPUNIT_ASSERT_EQUAL(true, test.isValid(Vector(9.9,10.9,11.9))); | 
|---|
|  | 288 | CPPUNIT_ASSERT_EQUAL(true, test.isValid(Vector(5,5,5))); | 
|---|
|  | 289 |  | 
|---|
|  | 290 | // checking invalid values | 
|---|
|  | 291 | CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(-0.1,0.9,1.9))); | 
|---|
|  | 292 | CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(10.1,11.1,12.1))); | 
|---|
|  | 293 | CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(5,5,-1))); | 
|---|
|  | 294 | CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(5,-1,5))); | 
|---|
|  | 295 | CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(-1,5,5))); | 
|---|
|  | 296 | CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(5,5,20))); | 
|---|
|  | 297 | CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(5,20,5))); | 
|---|
|  | 298 | CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(20,5,5))); | 
|---|
|  | 299 | CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(0,0,0))); | 
|---|
|  | 300 | CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(5,-1,-1))); | 
|---|
|  | 301 | CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(-1,5,-1))); | 
|---|
|  | 302 | CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(-1,-1,5))); | 
|---|
|  | 303 | CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(5,20,20))); | 
|---|
|  | 304 | CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(20,5,20))); | 
|---|
|  | 305 | CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(20,20,5))); | 
|---|
|  | 306 | } | 
|---|
|  | 307 |  | 
|---|
|  | 308 | /** Unit test for setting/getting valid range. | 
|---|
|  | 309 | * | 
|---|
|  | 310 | */ | 
|---|
|  | 311 | void ContinuousValueTest::setgetValidVectorRangeTest() | 
|---|
|  | 312 | { | 
|---|
|  | 313 | { | 
|---|
|  | 314 | // create instance | 
|---|
| [3c5ef5] | 315 | Value<Vector> test(*ValidVectorRange); | 
|---|
| [7d1b6a] | 316 |  | 
|---|
|  | 317 | // extending range and checking | 
|---|
|  | 318 | for (int i=15; i<=16;++i) | 
|---|
| [047cad] | 319 | CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(i,5,5))); | 
|---|
| [7d1b6a] | 320 | test.setValidRange(range<Vector>(Vector(0,1,2),Vector(20,11,12))); | 
|---|
|  | 321 | for (int i=15; i<=16;++i) | 
|---|
| [047cad] | 322 | CPPUNIT_ASSERT_EQUAL(true, test.isValid(Vector(i,5,5))); | 
|---|
| [7d1b6a] | 323 | } | 
|---|
|  | 324 |  | 
|---|
|  | 325 | { | 
|---|
|  | 326 | // create instance | 
|---|
| [3c5ef5] | 327 | Value<Vector> test(*ValidVectorRange); | 
|---|
| [7d1b6a] | 328 |  | 
|---|
|  | 329 | // lowering range with set value | 
|---|
| [047cad] | 330 | test.set(Vector(4,4,4)); | 
|---|
| [7d1b6a] | 331 | CPPUNIT_ASSERT_EQUAL(true, test.ValueSet); | 
|---|
|  | 332 | std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; | 
|---|
| [e45c1d] | 333 | CPPUNIT_ASSERT_THROW(test.setValidRange(range<Vector>(Vector(1,1,1),Vector(3,3,3))), ParameterValueException); | 
|---|
|  | 334 |  | 
|---|
| [7d1b6a] | 335 | // no value is not set | 
|---|
|  | 336 | std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; | 
|---|
| [e45c1d] | 337 | CPPUNIT_ASSERT_THROW(test.get(), ParameterException); | 
|---|
|  | 338 |  | 
|---|
| [7d1b6a] | 339 | // value gets invalidated in either case | 
|---|
|  | 340 | CPPUNIT_ASSERT_EQUAL(false, test.ValueSet); | 
|---|
|  | 341 | } | 
|---|
|  | 342 | } | 
|---|
|  | 343 |  | 
|---|
|  | 344 | /** Unit test for setValue and getValue. | 
|---|
|  | 345 | * | 
|---|
|  | 346 | */ | 
|---|
| [047cad] | 347 | void ContinuousValueTest::settergetterVectorAsStringTest() | 
|---|
| [7d1b6a] | 348 | { | 
|---|
|  | 349 | // create instance | 
|---|
| [3c5ef5] | 350 | /*Value<Vector> test(*ValidVectorRange); | 
|---|
| [7d1b6a] | 351 |  | 
|---|
|  | 352 | // unset calling of get, throws | 
|---|
|  | 353 | #ifndef NDEBUG | 
|---|
|  | 354 | std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; | 
|---|
|  | 355 | CPPUNIT_ASSERT_THROW(test.getValue(), Assert::AssertionFailure); | 
|---|
|  | 356 | #endif | 
|---|
|  | 357 |  | 
|---|
|  | 358 | // setting invalid, 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.setValue(Vector(5,0,0)), Assert::AssertionFailure); | 
|---|
|  | 362 | #endif | 
|---|
|  | 363 | #ifndef NDEBUG | 
|---|
|  | 364 | std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; | 
|---|
|  | 365 | CPPUNIT_ASSERT_THROW(test.setValue(Vector(5,20,5)), Assert::AssertionFailure); | 
|---|
|  | 366 | #endif | 
|---|
|  | 367 |  | 
|---|
|  | 368 | CPPUNIT_ASSERT_EQUAL(false, test.ValueSet); | 
|---|
|  | 369 | // checking some valid ones | 
|---|
|  | 370 | for (int i=1; i<=4;++i) { | 
|---|
|  | 371 | Vector v(i,5,5); | 
|---|
|  | 372 | test.setValue(v); | 
|---|
|  | 373 | CPPUNIT_ASSERT_EQUAL(true, test.ValueSet); | 
|---|
|  | 374 | CPPUNIT_ASSERT_EQUAL(v, test.getValue()); | 
|---|
| [047cad] | 375 | }*/ | 
|---|
| [7d1b6a] | 376 | } | 
|---|
|  | 377 |  | 
|---|
|  | 378 | /** Unit test for setters and getters. | 
|---|
|  | 379 | * | 
|---|
|  | 380 | */ | 
|---|
|  | 381 | void ContinuousValueTest::settergetterVectorTest() | 
|---|
|  | 382 | { | 
|---|
|  | 383 | // create instance | 
|---|
| [3c5ef5] | 384 | Value<Vector> test(*ValidVectorRange); | 
|---|
| [7d1b6a] | 385 |  | 
|---|
|  | 386 | // unset calling of get, throws | 
|---|
|  | 387 | std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; | 
|---|
| [e45c1d] | 388 | CPPUNIT_ASSERT_THROW(test.get(), ParameterValueException); | 
|---|
| [7d1b6a] | 389 |  | 
|---|
|  | 390 | // setting invalid, throws | 
|---|
|  | 391 | std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; | 
|---|
| [e45c1d] | 392 | CPPUNIT_ASSERT_THROW(test.set(Vector(5,0,0)), ParameterValueException); | 
|---|
| [7d1b6a] | 393 | std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; | 
|---|
| [e45c1d] | 394 | CPPUNIT_ASSERT_THROW(test.set(Vector(5,20,5)), ParameterValueException); | 
|---|
| [7d1b6a] | 395 |  | 
|---|
|  | 396 | CPPUNIT_ASSERT_EQUAL(false, test.ValueSet); | 
|---|
|  | 397 | // checking some valid ones | 
|---|
|  | 398 | for (int i=1; i<=4;++i) { | 
|---|
|  | 399 | Vector v(i,5,5); | 
|---|
|  | 400 | test.set(v); | 
|---|
|  | 401 | CPPUNIT_ASSERT_EQUAL(true, test.ValueSet); | 
|---|
|  | 402 | CPPUNIT_ASSERT_EQUAL(v, test.get()); | 
|---|
|  | 403 | } | 
|---|
|  | 404 | } | 
|---|
|  | 405 |  | 
|---|
|  | 406 | /** Unit test for comparator. | 
|---|
|  | 407 | * | 
|---|
|  | 408 | */ | 
|---|
|  | 409 | void ContinuousValueTest::comparatorVectorTest() | 
|---|
|  | 410 | { | 
|---|
|  | 411 | { | 
|---|
|  | 412 | // create instance | 
|---|
| [3c5ef5] | 413 | Value<Vector> test(*ValidVectorRange); | 
|---|
|  | 414 | Value<Vector> instance(*ValidVectorRange); | 
|---|
| [047cad] | 415 | test.set(Vector(5,6,7)); | 
|---|
|  | 416 | instance.set(Vector(5,6,7)); | 
|---|
| [7d1b6a] | 417 |  | 
|---|
|  | 418 | // same value, same range | 
|---|
|  | 419 | { | 
|---|
|  | 420 | CPPUNIT_ASSERT(test == instance); | 
|---|
|  | 421 | } | 
|---|
|  | 422 |  | 
|---|
|  | 423 | // different value, same range | 
|---|
|  | 424 | { | 
|---|
| [047cad] | 425 | const Vector oldvalue = instance.get(); | 
|---|
|  | 426 | instance.set(Vector(2,3,4)); | 
|---|
| [7d1b6a] | 427 | CPPUNIT_ASSERT(test != instance); | 
|---|
| [047cad] | 428 | instance.set(oldvalue); | 
|---|
| [7d1b6a] | 429 | } | 
|---|
|  | 430 | } | 
|---|
|  | 431 | { | 
|---|
| [3c5ef5] | 432 | Value<Vector> test(*ValidVectorRange); | 
|---|
| [7d1b6a] | 433 | range<Vector> OtherValidVectorRange(Vector(0,1,2), Vector(20,21,22)); | 
|---|
| [3c5ef5] | 434 | Value<Vector> instance(OtherValidVectorRange); | 
|---|
| [7d1b6a] | 435 |  | 
|---|
| [047cad] | 436 | test.set(Vector(1,2,3)); | 
|---|
|  | 437 | instance.set(Vector(1,2,3)); | 
|---|
| [7d1b6a] | 438 |  | 
|---|
|  | 439 | // same value, same range | 
|---|
|  | 440 | { | 
|---|
|  | 441 | CPPUNIT_ASSERT(test != instance); | 
|---|
|  | 442 | } | 
|---|
|  | 443 |  | 
|---|
|  | 444 | // different value, same range | 
|---|
|  | 445 | { | 
|---|
| [047cad] | 446 | const Vector oldvalue = instance.get(); | 
|---|
|  | 447 | instance.set(Vector(2,3,4)); | 
|---|
| [7d1b6a] | 448 | CPPUNIT_ASSERT(test != instance); | 
|---|
| [047cad] | 449 | instance.set(oldvalue); | 
|---|
| [7d1b6a] | 450 | } | 
|---|
|  | 451 | } | 
|---|
|  | 452 | } | 
|---|