#define BOOST_TEST_DYN_LINK #include #include // These unit tests assume (for now) that there are at least two // coordinate systems with id 0 and 1. using boost::unit_test::label; using RAT::DU::Point3D; struct GlobalFixture { GlobalFixture() {} ~GlobalFixture() {} void setup() { BOOST_TEST_MESSAGE( "GlobalFixture setup() called" ); Point3D::BeginOfRun(); // default: PSUP z=0, AV z=108 } void teardown() {} }; BOOST_TEST_GLOBAL_FIXTURE( GlobalFixture ); BOOST_AUTO_TEST_SUITE( point3d, *label("du") ) BOOST_AUTO_TEST_CASE( static_init_test ) { BOOST_TEST( Point3D::GetSystemCount() > 0 ); size_t n = Point3D::GetSystemCount(); for (size_t i = 0; i < n; ++i) { BOOST_TEST_INFO_SCOPE("System id = " << i); BOOST_TEST( ((Point3D::HasZOffset(i) && Point3D::GetZOffset(i) != 0.0) || (!Point3D::HasZOffset(i) && Point3D::GetZOffset(i) == 0.0)) ); std::string s = Point3D::GetSystemName(i); BOOST_TEST( Point3D::GetSystemId(s) == i ); } // test default setup BOOST_TEST( Point3D::GetSystemCount() == 2 ); BOOST_TEST( !Point3D::HasZOffset(0) ); BOOST_TEST( Point3D::GetZOffset(0) == 0.0 ); BOOST_TEST( Point3D::HasZOffset(1) ); BOOST_TEST( Point3D::GetZOffset(1) == 108.0 ); BOOST_TEST( Point3D::GetSystemName(0) == "PSUP" ); BOOST_TEST( Point3D::GetSystemName(1) == "AV" ); BOOST_TEST( Point3D::GetSystemId("PSUP") == 0); BOOST_TEST( Point3D::GetSystemId("AV") == 1); } BOOST_AUTO_TEST_CASE( constructors_test ) { Point3D p; BOOST_TEST( p.GetCoordinateSystem() == 0 ); BOOST_TEST( p.X() == 0.0 ); BOOST_TEST( p.Y() == 0.0 ); BOOST_TEST( p.Z() == 0.0 ); Point3D q(0, 3.0, 4.5, 5.25); BOOST_TEST( q.GetCoordinateSystem() == 0 ); BOOST_TEST( q.X() == 3.0 ); BOOST_TEST( q.Y() == 4.5 ); BOOST_TEST( q.Z() == 5.25 ); Point3D q2(q); // copy constructor BOOST_TEST( q2.GetCoordinateSystem() == 0 ); BOOST_TEST( q2.X() == 3.0 ); BOOST_TEST( q2.Y() == 4.5 ); BOOST_TEST( q2.Z() == 5.25 ); Point3D q3(1, q); // copy constructor with coordinate system change BOOST_TEST( q3.GetCoordinateSystem() == 1 ); BOOST_TEST( q3.X() == 3.0 ); BOOST_TEST( q3.Y() == 4.5 ); BOOST_TEST( q3.Z() == 5.25 - 108.0 ); } BOOST_AUTO_TEST_CASE( system_change_test ) { Point3D p(0, 3.0, 4.5, 120.25); Point3D q(1, p); BOOST_TEST( q.GetCoordinateSystem() == 1 ); BOOST_TEST( q.X() == 3.0 ); BOOST_TEST( q.Y() == 4.5 ); BOOST_TEST( q.Z() == 12.25, "new z value = " << q.Z() ); q.SetZ(1, 200.0); BOOST_TEST( q.GetCoordinateSystem() == 1 ); BOOST_TEST( q.Z() == 200.0); q.SetZ(0, 200.0); BOOST_TEST( q.GetCoordinateSystem() == 1 ); BOOST_TEST( q.Z() == 92.0); q.SetCoordinateSystem(0); BOOST_TEST( q.GetCoordinateSystem() == 0 ); BOOST_TEST( q.Z() == 200.0); } BOOST_AUTO_TEST_CASE( get_direction_from ) { Point3D p(0, 3.0, 4.5, 120.25); Point3D q(0, 1.0, 5.0, 200.25); TVector3 d = p - q; BOOST_TEST( d.X() == 2.0 ); BOOST_TEST( d.Y() == -0.5 ); BOOST_TEST( d.Z() == -80.0 ); q.SetCoordinateSystem(1); BOOST_TEST( q.GetCoordinateSystem() == 1 ); BOOST_TEST( q.X() == 1.0 ); BOOST_TEST( q.Y() == 5.0 ); BOOST_TEST( q.Z() == 92.25, "new z value = " << q.Z() ); d = p - q; BOOST_TEST( d.X() == 2.0 ); BOOST_TEST( d.Y() == -0.5 ); BOOST_TEST( d.Z() == -80.0 ); } BOOST_AUTO_TEST_SUITE_END()