| 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 | // create instance
|
|---|
| 148 | Value<int> test(*ValidIntRange);
|
|---|
| 149 |
|
|---|
| 150 | // unset calling of get, throws ParameterValueException
|
|---|
| 151 | std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
|
|---|
| 152 | CPPUNIT_ASSERT_THROW(test.getAsString(), ParameterValueException);
|
|---|
| 153 |
|
|---|
| 154 | // setting invalid, throws ParameterValueException
|
|---|
| 155 | std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
|
|---|
| 156 | CPPUNIT_ASSERT_THROW(test.setAsString(toString(5)), ParameterValueException);
|
|---|
| 157 | std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
|
|---|
| 158 | CPPUNIT_ASSERT_THROW(test.setAsString(toString(0)), ParameterValueException);
|
|---|
| 159 |
|
|---|
| 160 | CPPUNIT_ASSERT_EQUAL(false, test.ValueSet);
|
|---|
| 161 | // checking all valid ones
|
|---|
| 162 | for (int i=1; i<=4;++i) {
|
|---|
| 163 | test.setAsString(toString(i));
|
|---|
| 164 | CPPUNIT_ASSERT_EQUAL(true, test.ValueSet);
|
|---|
| 165 | CPPUNIT_ASSERT_EQUAL(toString(i), test.getAsString());
|
|---|
| 166 | }
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | /** Unit test for setters and getters.
|
|---|
| 170 | *
|
|---|
| 171 | */
|
|---|
| 172 | void ContinuousValueTest::settergetterIntTest()
|
|---|
| 173 | {
|
|---|
| 174 | // create instance
|
|---|
| 175 | Value<int> test(*ValidIntRange);
|
|---|
| 176 |
|
|---|
| 177 | // unset calling of get, throws ParameterValueException
|
|---|
| 178 | std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
|
|---|
| 179 | CPPUNIT_ASSERT_THROW(test.get(), ParameterValueException);
|
|---|
| 180 |
|
|---|
| 181 | // setting invalid, throws ParameterValueException
|
|---|
| 182 | std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
|
|---|
| 183 | CPPUNIT_ASSERT_THROW(test.set(5), ParameterValueException);
|
|---|
| 184 | std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
|
|---|
| 185 | CPPUNIT_ASSERT_THROW(test.set(0), ParameterValueException);
|
|---|
| 186 |
|
|---|
| 187 | // checking all valid ones
|
|---|
| 188 | for (int i=1; i<=4;++i) {
|
|---|
| 189 | test.set(i);
|
|---|
| 190 | CPPUNIT_ASSERT_EQUAL(i, test.get());
|
|---|
| 191 | }
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | /** Unit test for comparator.
|
|---|
| 195 | *
|
|---|
| 196 | */
|
|---|
| 197 | void ContinuousValueTest::comparatorIntTest()
|
|---|
| 198 | {
|
|---|
| 199 | {
|
|---|
| 200 | // create instance
|
|---|
| 201 | Value<int> test(*ValidIntRange);
|
|---|
| 202 | Value<int> instance(*ValidIntRange);
|
|---|
| 203 | test.set(1);
|
|---|
| 204 | instance.set(1);
|
|---|
| 205 |
|
|---|
| 206 | // same value, same range
|
|---|
| 207 | {
|
|---|
| 208 | CPPUNIT_ASSERT(test == instance);
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | // different value, same range
|
|---|
| 212 | {
|
|---|
| 213 | const int oldvalue = instance.get();
|
|---|
| 214 | instance.set(2);
|
|---|
| 215 | CPPUNIT_ASSERT(test != instance);
|
|---|
| 216 | instance.set(oldvalue);
|
|---|
| 217 | }
|
|---|
| 218 | }
|
|---|
| 219 | {
|
|---|
| 220 | Value<int> test(*ValidIntRange);
|
|---|
| 221 | range<int> OtherValidIntRange(1,5);
|
|---|
| 222 | Value<int> instance(OtherValidIntRange);
|
|---|
| 223 |
|
|---|
| 224 | test.set(1);
|
|---|
| 225 | instance.set(1);
|
|---|
| 226 |
|
|---|
| 227 | // same value, same range
|
|---|
| 228 | {
|
|---|
| 229 | CPPUNIT_ASSERT(test != instance);
|
|---|
| 230 | }
|
|---|
| 231 |
|
|---|
| 232 | // different value, same range
|
|---|
| 233 | {
|
|---|
| 234 | const int oldvalue = instance.get();
|
|---|
| 235 | instance.set(2);
|
|---|
| 236 | CPPUNIT_ASSERT(test != instance);
|
|---|
| 237 | instance.set(oldvalue);
|
|---|
| 238 | }
|
|---|
| 239 | }
|
|---|
| 240 | }
|
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 |
|
|---|
| 244 | /***************************** vector tests ***********************************/
|
|---|
| 245 |
|
|---|
| 246 | /** Unit test for isValid.
|
|---|
| 247 | *
|
|---|
| 248 | */
|
|---|
| 249 | void ContinuousValueTest::isValidVectorAsStringTest()
|
|---|
| 250 | {
|
|---|
| 251 | // create instance
|
|---|
| 252 | /*ContinuousValue<Vector> test(*ValidVectorRange);
|
|---|
| 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)));
|
|---|
| 274 | CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(20,20,5)));*/
|
|---|
| 275 | }
|
|---|
| 276 |
|
|---|
| 277 | /** Unit test for isValid.
|
|---|
| 278 | *
|
|---|
| 279 | */
|
|---|
| 280 | void ContinuousValueTest::isValidVectorTest()
|
|---|
| 281 | {
|
|---|
| 282 | // create instance
|
|---|
| 283 | Value<Vector> test(*ValidVectorRange);
|
|---|
| 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
|
|---|
| 315 | Value<Vector> test(*ValidVectorRange);
|
|---|
| 316 |
|
|---|
| 317 | // extending range and checking
|
|---|
| 318 | for (int i=15; i<=16;++i)
|
|---|
| 319 | CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(i,5,5)));
|
|---|
| 320 | test.setValidRange(range<Vector>(Vector(0,1,2),Vector(20,11,12)));
|
|---|
| 321 | for (int i=15; i<=16;++i)
|
|---|
| 322 | CPPUNIT_ASSERT_EQUAL(true, test.isValid(Vector(i,5,5)));
|
|---|
| 323 | }
|
|---|
| 324 |
|
|---|
| 325 | {
|
|---|
| 326 | // create instance
|
|---|
| 327 | Value<Vector> test(*ValidVectorRange);
|
|---|
| 328 |
|
|---|
| 329 | // lowering range with set value
|
|---|
| 330 | test.set(Vector(4,4,4));
|
|---|
| 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;
|
|---|
| 333 | CPPUNIT_ASSERT_THROW(test.setValidRange(range<Vector>(Vector(1,1,1),Vector(3,3,3))), ParameterValueException);
|
|---|
| 334 |
|
|---|
| 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;
|
|---|
| 337 | CPPUNIT_ASSERT_THROW(test.get(), ParameterException);
|
|---|
| 338 |
|
|---|
| 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 | */
|
|---|
| 347 | void ContinuousValueTest::settergetterVectorAsStringTest()
|
|---|
| 348 | {
|
|---|
| 349 | // create instance
|
|---|
| 350 | /*Value<Vector> test(*ValidVectorRange);
|
|---|
| 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());
|
|---|
| 375 | }*/
|
|---|
| 376 | }
|
|---|
| 377 |
|
|---|
| 378 | /** Unit test for setters and getters.
|
|---|
| 379 | *
|
|---|
| 380 | */
|
|---|
| 381 | void ContinuousValueTest::settergetterVectorTest()
|
|---|
| 382 | {
|
|---|
| 383 | // create instance
|
|---|
| 384 | Value<Vector> test(*ValidVectorRange);
|
|---|
| 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;
|
|---|
| 388 | CPPUNIT_ASSERT_THROW(test.get(), ParameterValueException);
|
|---|
| 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;
|
|---|
| 392 | CPPUNIT_ASSERT_THROW(test.set(Vector(5,0,0)), ParameterValueException);
|
|---|
| 393 | std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
|
|---|
| 394 | CPPUNIT_ASSERT_THROW(test.set(Vector(5,20,5)), ParameterValueException);
|
|---|
| 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
|
|---|
| 413 | Value<Vector> test(*ValidVectorRange);
|
|---|
| 414 | Value<Vector> instance(*ValidVectorRange);
|
|---|
| 415 | test.set(Vector(5,6,7));
|
|---|
| 416 | instance.set(Vector(5,6,7));
|
|---|
| 417 |
|
|---|
| 418 | // same value, same range
|
|---|
| 419 | {
|
|---|
| 420 | CPPUNIT_ASSERT(test == instance);
|
|---|
| 421 | }
|
|---|
| 422 |
|
|---|
| 423 | // different value, same range
|
|---|
| 424 | {
|
|---|
| 425 | const Vector oldvalue = instance.get();
|
|---|
| 426 | instance.set(Vector(2,3,4));
|
|---|
| 427 | CPPUNIT_ASSERT(test != instance);
|
|---|
| 428 | instance.set(oldvalue);
|
|---|
| 429 | }
|
|---|
| 430 | }
|
|---|
| 431 | {
|
|---|
| 432 | Value<Vector> test(*ValidVectorRange);
|
|---|
| 433 | range<Vector> OtherValidVectorRange(Vector(0,1,2), Vector(20,21,22));
|
|---|
| 434 | Value<Vector> instance(OtherValidVectorRange);
|
|---|
| 435 |
|
|---|
| 436 | test.set(Vector(1,2,3));
|
|---|
| 437 | instance.set(Vector(1,2,3));
|
|---|
| 438 |
|
|---|
| 439 | // same value, same range
|
|---|
| 440 | {
|
|---|
| 441 | CPPUNIT_ASSERT(test != instance);
|
|---|
| 442 | }
|
|---|
| 443 |
|
|---|
| 444 | // different value, same range
|
|---|
| 445 | {
|
|---|
| 446 | const Vector oldvalue = instance.get();
|
|---|
| 447 | instance.set(Vector(2,3,4));
|
|---|
| 448 | CPPUNIT_ASSERT(test != instance);
|
|---|
| 449 | instance.set(oldvalue);
|
|---|
| 450 | }
|
|---|
| 451 | }
|
|---|
| 452 | }
|
|---|