Changes in src/vectorunittest.cpp [89c8b2:d52e70c]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/vectorunittest.cpp
r89c8b2 rd52e70c 13 13 #include <cppunit/ui/text/TestRunner.h> 14 14 15 #include "defs.hpp" 16 #include "vector.hpp" 15 17 #include "vectorunittest.hpp" 16 #include "vector.hpp"17 #include "defs.hpp"18 18 19 19 /********************************************** Test classes **************************************/ … … 55 55 void VectorTest::SimpleAlgebraTest() 56 56 { 57 Vector helper; 57 58 double factor; 58 // copy vector59 fixture.Init(2.,3.,4.);60 CPPUNIT_ASSERT_EQUAL( Vector(2.,3.,4.), fixture );61 59 // summation and scaling 62 fixture.CopyVector(&zero);63 fixture.AddVector(&unit);64 CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() );65 fixture.CopyVector(&zero);66 fixture.SubtractVector(&unit);67 CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() );68 CPPUNIT_ASSERT_EQUAL( false, fixture.IsZero() );69 fixture.CopyVector(&zero);70 fixture.AddVector(&zero);71 CPPUNIT_ASSERT_EQUAL( true, fixture.IsZero() );72 fixture.CopyVector(¬unit);73 fixture.SubtractVector(&otherunit);74 CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() );75 fixture.CopyVector(&unit);76 fixture.AddVector(&otherunit);77 CPPUNIT_ASSERT_EQUAL( false, fixture.IsOne() );78 fixture.CopyVector(¬unit);79 fixture.SubtractVector(&unit);80 fixture.SubtractVector(&otherunit);81 CPPUNIT_ASSERT_EQUAL( false, fixture.IsZero() );82 fixture.CopyVector(&unit);83 fixture.Scale(0.98);84 CPPUNIT_ASSERT_EQUAL( false, fixture.IsOne() );85 fixture.CopyVector(&unit);86 fixture.Scale(1.);87 CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() );88 fixture.CopyVector(&unit);60 helper.CopyVector(&zero); 61 helper.AddVector(&unit); 62 CPPUNIT_ASSERT_EQUAL( true, helper.IsOne() ); 63 helper.CopyVector(&zero); 64 helper.SubtractVector(&unit); 65 CPPUNIT_ASSERT_EQUAL( true, helper.IsOne() ); 66 CPPUNIT_ASSERT_EQUAL( false, helper.IsZero() ); 67 helper.CopyVector(&zero); 68 helper.AddVector(&zero); 69 CPPUNIT_ASSERT_EQUAL( true, helper.IsZero() ); 70 helper.CopyVector(¬unit); 71 helper.SubtractVector(&otherunit); 72 CPPUNIT_ASSERT_EQUAL( true, helper.IsOne() ); 73 helper.CopyVector(&unit); 74 helper.AddVector(&otherunit); 75 CPPUNIT_ASSERT_EQUAL( false, helper.IsOne() ); 76 helper.CopyVector(¬unit); 77 helper.SubtractVector(&unit); 78 helper.SubtractVector(&otherunit); 79 CPPUNIT_ASSERT_EQUAL( false, helper.IsZero() ); 80 helper.CopyVector(&unit); 81 helper.Scale(0.98); 82 CPPUNIT_ASSERT_EQUAL( false, helper.IsOne() ); 83 helper.CopyVector(&unit); 84 helper.Scale(1.); 85 CPPUNIT_ASSERT_EQUAL( true, helper.IsOne() ); 86 helper.CopyVector(&unit); 89 87 factor = 0.98; 90 fixture.Scale(factor);91 CPPUNIT_ASSERT_EQUAL( false, fixture.IsOne() );92 fixture.CopyVector(&unit);88 helper.Scale(factor); 89 CPPUNIT_ASSERT_EQUAL( false, helper.IsOne() ); 90 helper.CopyVector(&unit); 93 91 factor = 1.; 94 fixture.Scale(factor);95 CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() );92 helper.Scale(factor); 93 CPPUNIT_ASSERT_EQUAL( true, helper.IsOne() ); 96 94 }; 97 95 … … 185 183 void VectorTest::LineIntersectionTest() 186 184 { 185 Vector helper; 187 186 // plane at (0,0,0) normal to (1,0,0) cuts line from (0,0,0) to (2,1,0) at ??? 188 CPPUNIT_ASSERT_EQUAL( true, fixture.GetIntersectionWithPlane((ofstream *)&cout, &unit, &zero, &zero, &two) );189 CPPUNIT_ASSERT_EQUAL( zero, fixture);187 CPPUNIT_ASSERT_EQUAL( true, helper.GetIntersectionWithPlane((ofstream *)&cout, &unit, &zero, &zero, &two) ); 188 CPPUNIT_ASSERT_EQUAL( zero, helper ); 190 189 191 190 // plane at (2,1,0) normal to (0,1,0) cuts line from (1,0,0) to (0,1,1) at ??? 192 CPPUNIT_ASSERT_EQUAL( true, fixture.GetIntersectionWithPlane((ofstream *)&cout, &otherunit, &two, &unit, ¬unit) );193 CPPUNIT_ASSERT_EQUAL( Vector(0., 1., 1.), fixture);191 CPPUNIT_ASSERT_EQUAL( true, helper.GetIntersectionWithPlane((ofstream *)&cout, &otherunit, &two, &unit, ¬unit) ); 192 CPPUNIT_ASSERT_EQUAL( Vector(0., 1., 1.), helper ); 194 193 195 194 // four vectors equal to zero 196 CPPUNIT_ASSERT_EQUAL( false, fixture.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &zero, &zero, &zero, &zero, NULL) );197 CPPUNIT_ASSERT_EQUAL( zero, fixture);195 CPPUNIT_ASSERT_EQUAL( false, helper.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &zero, &zero, &zero, &zero, NULL) ); 196 CPPUNIT_ASSERT_EQUAL( zero, helper ); 198 197 199 198 // four vectors equal to unit 200 CPPUNIT_ASSERT_EQUAL( false, fixture.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &unit, &unit, &unit, &unit, NULL) );201 CPPUNIT_ASSERT_EQUAL( zero, fixture);199 CPPUNIT_ASSERT_EQUAL( false, helper.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &unit, &unit, &unit, &unit, NULL) ); 200 CPPUNIT_ASSERT_EQUAL( zero, helper ); 202 201 203 202 // two equal lines 204 CPPUNIT_ASSERT_EQUAL( true, fixture.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &unit, &two, &unit, &two, NULL) );205 CPPUNIT_ASSERT_EQUAL( unit, fixture);203 CPPUNIT_ASSERT_EQUAL( true, helper.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &unit, &two, &unit, &two, NULL) ); 204 CPPUNIT_ASSERT_EQUAL( unit, helper ); 206 205 207 206 // line from (1,0,0) to (2,1,0) cuts line from (1,0,0) to (0,1,0) at ??? 208 CPPUNIT_ASSERT_EQUAL( true, fixture.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &unit, &two, &unit, &otherunit, NULL) );209 CPPUNIT_ASSERT_EQUAL( unit, fixture);207 CPPUNIT_ASSERT_EQUAL( true, helper.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &unit, &two, &unit, &otherunit, NULL) ); 208 CPPUNIT_ASSERT_EQUAL( unit, helper ); 210 209 211 210 // line from (1,0,0) to (0,0,0) cuts line from (0,0,0) to (2,1,0) at ??? 212 CPPUNIT_ASSERT_EQUAL( true, fixture.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &unit, &zero, &zero, &two, NULL) );213 CPPUNIT_ASSERT_EQUAL( zero, fixture);211 CPPUNIT_ASSERT_EQUAL( true, helper.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &unit, &zero, &zero, &two, NULL) ); 212 CPPUNIT_ASSERT_EQUAL( zero, helper ); 214 213 215 214 // line from (1,0,0) to (2,1,0) cuts line from (0,0,0) to (0,1,0) at ??? 216 CPPUNIT_ASSERT_EQUAL( true, fixture.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &unit, &two, &zero, &otherunit, NULL) ); 217 CPPUNIT_ASSERT_EQUAL( Vector(0., -1., 0.), fixture ); 218 }; 219 220 /** UnitTest for vector rotations. 221 */ 222 void VectorTest::VectorRotationTest() 223 { 224 fixture.Init(-1.,0.,0.); 225 226 // zero vector does not change 227 fixture.CopyVector(&zero); 228 fixture.RotateVector(&unit, 1.); 229 CPPUNIT_ASSERT_EQUAL( zero, fixture ); 230 231 fixture.RotateVector(&two, 1.); 232 CPPUNIT_ASSERT_EQUAL( zero, fixture); 233 234 // vector on axis does not change 235 fixture.CopyVector(&unit); 236 fixture.RotateVector(&unit, 1.); 237 CPPUNIT_ASSERT_EQUAL( unit, fixture ); 238 239 fixture.RotateVector(&unit, 1.); 240 CPPUNIT_ASSERT_EQUAL( unit, fixture ); 241 242 // rotations 243 fixture.CopyVector(&otherunit); 244 fixture.RotateVector(&unit, M_PI); 245 CPPUNIT_ASSERT_EQUAL( Vector(0.,-1.,0.), fixture ); 246 247 fixture.CopyVector(&otherunit); 248 fixture.RotateVector(&unit, 2. * M_PI); 249 CPPUNIT_ASSERT_EQUAL( otherunit, fixture ); 250 251 fixture.CopyVector(&otherunit); 252 fixture.RotateVector(&unit, 0); 253 CPPUNIT_ASSERT_EQUAL( otherunit, fixture ); 254 255 fixture.Init(0.,0.,1.); 256 fixture.RotateVector(¬unit, M_PI); 257 CPPUNIT_ASSERT_EQUAL( otherunit, fixture ); 258 } 259 260 /** 261 * UnitTest for Vector::IsInParallelepiped(). 262 */ 263 void VectorTest::IsInParallelepipedTest() 264 { 265 double parallelepiped[NDIM*NDIM]; 266 parallelepiped[0] = 1; 267 parallelepiped[1] = 0; 268 parallelepiped[2] = 0; 269 parallelepiped[3] = 0; 270 parallelepiped[4] = 1; 271 parallelepiped[5] = 0; 272 parallelepiped[6] = 0; 273 parallelepiped[7] = 0; 274 parallelepiped[8] = 1; 275 276 fixture.CopyVector(zero); 277 CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 278 fixture.Init(2.5,2.5,2.5); 279 CPPUNIT_ASSERT_EQUAL( true, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 280 fixture.Init(1.,1.,1.); 281 CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 282 fixture.Init(3.5,3.5,3.5); 283 CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 284 fixture.Init(2.,2.,2.); 285 CPPUNIT_ASSERT_EQUAL( true, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 286 fixture.Init(2.,3.,2.); 287 CPPUNIT_ASSERT_EQUAL( true, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 288 fixture.Init(-2.,2.,-1.); 289 CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 290 } 291 215 CPPUNIT_ASSERT_EQUAL( true, helper.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &unit, &two, &zero, &otherunit, NULL) ); 216 CPPUNIT_ASSERT_EQUAL( Vector(0., -1., 0.), helper ); 217 }; 292 218 293 219 /********************************************** Main routine **************************************/
Note:
See TracChangeset
for help on using the changeset viewer.