92 lines
1.9 KiB
C++
92 lines
1.9 KiB
C++
#include <cxxtest/TestSuite.h>
|
|
|
|
#include "waypoint.hh"
|
|
#include "building.hh"
|
|
|
|
class Waypoint_test: public CxxTest::TestSuite
|
|
{
|
|
public:
|
|
|
|
void test_constructors(void)
|
|
{
|
|
// Default constructor
|
|
Waypoint wp00 ;
|
|
Waypoint wp01(NULL, 0, 0, 0) ;
|
|
TS_ASSERT_EQUALS(wp00, wp01) ;
|
|
|
|
// Copy constructor
|
|
Building b1("My Building") ;
|
|
Waypoint wp1(&b1, 1, 2, 3) ;
|
|
Waypoint wp2(wp1) ;
|
|
TS_ASSERT_EQUALS(wp1, wp2) ;
|
|
|
|
// Point3D copy constructor
|
|
Point3D p0(5, 3, 8) ;
|
|
Waypoint wp4(p0) ;
|
|
TS_ASSERT_EQUALS(p0, wp4) ;
|
|
Waypoint wp5(NULL, p0) ;
|
|
TS_ASSERT_EQUALS(wp4, wp5) ;
|
|
|
|
// 3-float array constructor
|
|
float coord[3] = {5, 3, 8} ;
|
|
Waypoint wp3(coord) ;
|
|
TS_ASSERT_EQUALS(wp3, wp4) ;
|
|
}
|
|
|
|
|
|
void test_accessors(void)
|
|
{
|
|
// Simple read accessors
|
|
Building b1("My Building") ;
|
|
Waypoint wp1(&b1, 1, 3, 5) ;
|
|
TS_ASSERT_EQUALS(wp1.get_1st_building(), &b1) ;
|
|
TS_ASSERT_EQUALS(wp1.get_x(), 1) ;
|
|
TS_ASSERT_EQUALS(wp1.get_y(), 3) ;
|
|
TS_ASSERT_EQUALS(wp1.get_z(), 5) ;
|
|
|
|
// Write & read accessors
|
|
Building b2("My Second Building") ;
|
|
wp1.add_building(&b2) ;
|
|
std::tr1::unordered_set<Building*> buildings ;
|
|
buildings.insert(&b1) ;
|
|
buildings.insert(&b2) ;
|
|
TS_ASSERT_EQUALS(wp1.get_buildings(), buildings) ;
|
|
wp1.set_x(42) ;
|
|
TS_ASSERT_EQUALS(wp1.get_x(), 42) ;
|
|
wp1.set_y(321) ;
|
|
TS_ASSERT_EQUALS(wp1.get_y(), 321) ;
|
|
wp1.set_z(98) ;
|
|
TS_ASSERT_EQUALS(wp1.get_z(), 98) ;
|
|
}
|
|
|
|
|
|
void test_operators(void)
|
|
{
|
|
// ==
|
|
Waypoint wp1(NULL, 42, 21, 19) ;
|
|
Waypoint wp2(NULL, 42, 21, 19) ;
|
|
TS_ASSERT_EQUALS(wp1, wp2) ;
|
|
|
|
// !=
|
|
Waypoint wp3(NULL, 1, 4, 7) ;
|
|
TS_ASSERT(wp1 != wp3) ;
|
|
|
|
// =
|
|
wp2 = wp3 ;
|
|
TS_ASSERT_EQUALS(wp2, wp3) ;
|
|
|
|
// <
|
|
TS_ASSERT_LESS_THAN(wp2, wp1) ;
|
|
|
|
// <=
|
|
TS_ASSERT_LESS_THAN_EQUALS(wp2, wp1) ;
|
|
|
|
// >
|
|
TS_ASSERT(wp1 > wp2) ;
|
|
|
|
// >=
|
|
TS_ASSERT(wp1 >= wp2) ;
|
|
}
|
|
|
|
} ;
|