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