107 lines
2.5 KiB
C++
107 lines
2.5 KiB
C++
#include <cxxtest/TestSuite.h>
|
|
|
|
#include "area.hh"
|
|
#include "building.hh"
|
|
|
|
class Area_test: public CxxTest::TestSuite
|
|
{
|
|
public:
|
|
|
|
void test_constructors(void)
|
|
{
|
|
// Default constructor
|
|
Area a1 ;
|
|
Area a2(NULL, "Unnamed area", 0,0,0, 0,0,0) ;
|
|
TS_ASSERT_EQUALS(a1, a2) ;
|
|
|
|
// Copy constructor
|
|
Building b1 ;
|
|
Area a3(&b1, "My Area", 3,2,1, 0,1,2) ;
|
|
Area a4(a3) ;
|
|
TS_ASSERT_EQUALS(a3, a4) ;
|
|
}
|
|
|
|
|
|
void test_accessors(void)
|
|
{
|
|
// Simple read accessors
|
|
Building b1("Numerica") ;
|
|
Area a1(&b1, "My Area", 1,3,5, 8,7,4) ;
|
|
TS_ASSERT_EQUALS(a1.get_building(), &b1) ;
|
|
TS_ASSERT_EQUALS(a1.get_name(), "My Area") ;
|
|
|
|
TS_WARN("TODO: test inversion of points.") ;
|
|
/*
|
|
TS_ASSERT_EQUALS(a1.get_p_min(), Point3D(1,3,5)) ;
|
|
TS_ASSERT_EQUALS(a1.get_p_max(), Point3D(8,7,4)) ;
|
|
*/
|
|
|
|
// Write & read accessors
|
|
Building b2("Numerica 2") ;
|
|
a1.set_building(&b2) ;
|
|
TS_ASSERT_EQUALS(a1.get_building(), &b2) ;
|
|
a1.set_name("My new Area") ;
|
|
TS_ASSERT_EQUALS(a1.get_name(), "My new Area") ;
|
|
|
|
TS_WARN("TODO: test inversion of points.") ;
|
|
a1.set_x_min(56) ;
|
|
a1.set_y_min(32) ;
|
|
a1.set_z_min(49) ;
|
|
TS_ASSERT_EQUALS(a1.get_p_min(), Point3D(56,32,49)) ;
|
|
a1.set_x_max(99) ;
|
|
a1.set_y_max(44) ;
|
|
a1.set_z_max(77) ;
|
|
TS_ASSERT_EQUALS(a1.get_p_max(), Point3D(99,44,77)) ;
|
|
Point3D p1(9,4,2) ;
|
|
a1.set_p_min(p1) ;
|
|
TS_ASSERT_EQUALS(a1.get_p_min(), p1) ;
|
|
Point3D p2(1,7,1) ;
|
|
a1.set_p_max(p2) ;
|
|
TS_ASSERT_EQUALS(a1.get_p_max(), p2) ;
|
|
}
|
|
|
|
|
|
void test_contains_point(void)
|
|
{
|
|
Building b1("Numerica") ;
|
|
Area a1(&b1, "My Area", 0,0,0, 3,3,3) ;
|
|
|
|
Point3D p01(0,0,0) ;
|
|
TS_ASSERT(a1.contains_point(p01)) ;
|
|
Point3D p02(3,3,3) ;
|
|
TS_ASSERT(a1.contains_point(p02)) ;
|
|
Point3D p03(2,2,2) ;
|
|
TS_ASSERT(a1.contains_point(p03)) ;
|
|
Point3D p04(0,2,1) ;
|
|
TS_ASSERT(a1.contains_point(p04)) ;
|
|
|
|
Point3D p11(-1,0,0) ;
|
|
TS_ASSERT(! a1.contains_point(p11)) ;
|
|
Point3D p12(3.1,3.2,3.3) ;
|
|
TS_ASSERT(! a1.contains_point(p12)) ;
|
|
Point3D p13(2,3.3,2) ;
|
|
TS_ASSERT(! a1.contains_point(p13)) ;
|
|
Point3D p14(2,2,3.5) ;
|
|
TS_ASSERT(! a1.contains_point(p14)) ;
|
|
}
|
|
|
|
|
|
void test_operators(void)
|
|
{
|
|
// ==
|
|
Building b1("Numerica") ;
|
|
Area a1(&b1, "My Area", 1,3,5, 8,7,4) ;
|
|
Area a2(&b1, "My Area", 1,3,5, 8,7,4) ;
|
|
TS_ASSERT_EQUALS(a1, a2) ;
|
|
|
|
// !=
|
|
Area a3(&b1, "My Area", 1,0,5, 8,7,4) ;
|
|
TS_ASSERT_DIFFERS(a1, a3) ;
|
|
|
|
// =
|
|
a2 = a3 ;
|
|
TS_ASSERT_EQUALS(a2, a3) ;
|
|
}
|
|
|
|
} ;
|