owlps/owlps-positioning/tests/point3d_test.hh

90 lines
1.6 KiB
C++

#include <cxxtest/TestSuite.h>
#include "point3d.hh"
class Point3D_test: public CxxTest::TestSuite
{
public:
void test_constructors(void)
{
// Default constructor
Point3D p00 ;
Point3D p01(0, 0, 0) ;
TS_ASSERT_EQUALS(p00, p01) ;
// Copy constructor
Point3D p1(1, 2, 3) ;
Point3D p2(p1) ;
TS_ASSERT_EQUALS(p1, p2) ;
// 3-float array constructor
float coord[3] = {1, 2, 3} ;
Point3D p3(coord) ;
TS_ASSERT_EQUALS(p1, p3) ;
}
void test_accessors(void)
{
// Simple read accessors
Point3D p1(1, 3, 5) ;
TS_ASSERT_EQUALS(p1.get_x(), 1) ;
TS_ASSERT_EQUALS(p1.get_y(), 3) ;
TS_ASSERT_EQUALS(p1.get_z(), 5) ;
// Write & read accessors
p1.set_x(42) ;
TS_ASSERT_EQUALS(p1.get_x(), 42) ;
p1.set_y(321) ;
TS_ASSERT_EQUALS(p1.get_y(), 321) ;
p1.set_z(98) ;
TS_ASSERT_EQUALS(p1.get_z(), 98) ;
}
void test_distances(void)
{
Point3D p1(0, 0, 0) ;
Point3D p2(1, 0, 0) ;
TS_ASSERT_EQUALS(p1.distance(p2), 1) ;
TS_ASSERT_EQUALS(p1.square_distance(p2), 1) ;
Point3D p3(0, 2, 0) ;
TS_ASSERT_EQUALS(p1.distance(p3), 2) ;
TS_ASSERT_EQUALS(p1.square_distance(p3), 4) ;
TS_WARN("TODO: some more complex tests.") ;
}
void test_operators(void)
{
// ==
Point3D p1(42, 21, 19) ;
Point3D p2(42, 21, 19) ;
TS_ASSERT_EQUALS(p1, p2) ;
// !=
Point3D p3(1, 4, 7) ;
TS_ASSERT_DIFFERS(p1, p3) ;
// =
p2 = p3 ;
TS_ASSERT_EQUALS(p2, p3) ;
// <
TS_ASSERT_LESS_THAN(p2, p1) ;
// <=
TS_ASSERT_LESS_THAN_EQUALS(p2, p1) ;
// >
TS_ASSERT(p1 > p2) ;
// >=
TS_ASSERT(p1 >= p2) ;
}
} ;