@ -13,6 +13,7 @@
# include <cxxtest/TestSuite.h>
# include "calibrationrequest.hh"
# include "stock.hh"
# include "posexcept.hh"
@ -122,9 +123,20 @@ public:
// TODO: implement that
}
void test_reference_points ( void )
/*
* This test creates a ReferencePoint , then retrieves it from its
* coordinates ( Point3D ) .
*/
void test_reference_points_1 ( void )
{
ReferencePoint referencepoint1 ( 3 , 5 , 7 ) ;
Point3D point1 ( 3 , 5 , 7 ) ;
ReferencePoint referencepoint1 ( point1 ) ;
CalibrationRequest cr1 ( 42 ) ; // 42 is obviously not a valid request type
referencepoint1 . add_request ( & cr1 ) ;
TS_ASSERT_THROWS ( Stock : : get_reference_point ( point1 ) , element_not_found ) ;
TS_ASSERT_THROWS ( Stock : : get_reference_point ( referencepoint1 ) ,
element_not_found ) ;
const ReferencePoint & referencepoint1_ref1 =
Stock : : find_create_reference_point ( referencepoint1 ) ;
@ -137,6 +149,68 @@ public:
TS_ASSERT_DIFFERS ( & referencepoint1 , & referencepoint1_ref2 ) ;
TS_ASSERT_EQUALS ( & referencepoint1_ref1 , & referencepoint1_ref2 ) ;
const ReferencePoint & referencepoint1_ref3 =
Stock : : get_reference_point ( referencepoint1 ) ;
TS_ASSERT_EQUALS ( referencepoint1 , referencepoint1_ref3 ) ;
TS_ASSERT_DIFFERS ( & referencepoint1 , & referencepoint1_ref3 ) ;
/* Now let's use the Point3D to look up the ReferencePoint */
const ReferencePoint & referencepoint1_ref4 =
Stock : : get_reference_point ( point1 ) ;
TS_ASSERT_EQUALS ( referencepoint1 , referencepoint1_ref4 ) ;
const ReferencePoint & referencepoint1_ref5 =
Stock : : find_create_reference_point ( point1 ) ;
TS_ASSERT_EQUALS ( referencepoint1 , referencepoint1_ref5 ) ;
}
/*
* This test creates a ReferencePoint using a Point3D in the first
* place , and compares to a ReferencePoint created from a
* ReferencePoint .
*/
void test_reference_points_2 ( void )
{
// Create with Point3D, retrieve with ReferencePoint
Point3D p1 ( 1 , 2 , 3 ) ;
const ReferencePoint & rp1_ref1 = Stock : : find_create_reference_point ( p1 ) ;
ReferencePoint rp1 ( 1 , 2 , 3 ) ;
const ReferencePoint & rp1_ref2 = Stock : : get_reference_point ( rp1 ) ;
const ReferencePoint & rp1_ref3 = Stock : : find_create_reference_point ( rp1 ) ;
TS_ASSERT_EQUALS ( & rp1_ref1 , & rp1_ref2 ) ;
TS_ASSERT_EQUALS ( & rp1_ref1 , & rp1_ref3 ) ;
TS_ASSERT_EQUALS ( rp1 , rp1_ref1 ) ;
// Create with ReferencePoint, retrieve with Point3D
ReferencePoint rp2 ( 4 , 5 , 6 ) ;
const ReferencePoint & rp2_ref1 = Stock : : find_create_reference_point ( rp2 ) ;
Point3D p2 ( 4 , 5 , 6 ) ;
const ReferencePoint & rp2_ref2 = Stock : : get_reference_point ( p2 ) ;
const ReferencePoint & rp2_ref3 = Stock : : find_create_reference_point ( p2 ) ;
TS_ASSERT_EQUALS ( & rp2_ref1 , & rp2_ref2 ) ;
TS_ASSERT_EQUALS ( & rp2_ref1 , & rp2_ref3 ) ;
TS_ASSERT_EQUALS ( rp2 , rp2_ref1 ) ;
/* Now with a request in the reference point */
// Create with Point3D, retrieve with ReferencePoint
Point3D p3 ( 7 , 8 , 9 ) ;
const ReferencePoint & rp3_ref1 = Stock : : find_create_reference_point ( p3 ) ;
ReferencePoint rp3 ( 7 , 8 , 9 ) ;
CalibrationRequest cr3 ( 42 ) ; // 42 is obviously not a valid request type
rp3 . add_request ( & cr3 ) ;
const ReferencePoint & rp3_ref2 = Stock : : get_reference_point ( rp3 ) ;
const ReferencePoint & rp3_ref3 = Stock : : find_create_reference_point ( rp3 ) ;
TS_ASSERT_EQUALS ( & rp3_ref1 , & rp3_ref2 ) ;
TS_ASSERT_EQUALS ( & rp3_ref1 , & rp3_ref3 ) ;
TS_ASSERT_DIFFERS ( rp3 , rp3_ref1 ) ; /* the ReferencePoint in the stock doesn't
* have the CalibrationRequest */
ReferencePoint & rp3_ref_rw =
const_cast < ReferencePoint & > ( Stock : : get_reference_point ( rp3 ) ) ;
rp3_ref_rw . add_request ( & cr3 ) ;
TS_ASSERT_EQUALS ( rp3 , rp3_ref1 ) ;
}
void test_closest_reference_point ( void )