105 lines
2.5 KiB
C++
105 lines
2.5 KiB
C++
/*
|
|
* This file is part of the Owl Positioning System (OwlPS) project.
|
|
* It is subject to the copyright notice and license terms in the
|
|
* COPYRIGHT.t2t file found in the top-level directory of this
|
|
* distribution and at
|
|
* http://code.lm7.fr/p/owlps/source/tree/master/COPYRIGHT.t2t
|
|
* No part of the OwlPS Project, including this file, may be copied,
|
|
* modified, propagated, or distributed except according to the terms
|
|
* contained in the COPYRIGHT.t2t file; the COPYRIGHT.t2t file must be
|
|
* distributed along with this file, either separately or by replacing
|
|
* this notice by the COPYRIGHT.t2t file's contents.
|
|
*/
|
|
|
|
#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(nullptr, 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(nullptr, 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::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(nullptr, 42, 21, 19) ;
|
|
Waypoint wp2(nullptr, 42, 21, 19) ;
|
|
TS_ASSERT_EQUALS(wp1, wp2) ;
|
|
|
|
// !=
|
|
Waypoint wp3(nullptr, 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) ;
|
|
}
|
|
|
|
} ;
|