Commit 923cfbd1 authored by kkrish's avatar kkrish

CMake modified to test in sub-directory

parent db45e265
......@@ -134,7 +134,7 @@ if(BUILD_TESTING OR BUILD_CPPUNIT_TEST)
IF(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage --coverage")
endif(CMAKE_COMPILER_IS_GNUCXX)
file(GLOB test_files "${CMAKE_TEST_DIR}/*.cpp")
file(GLOB test_files "${CMAKE_TEST_DIR}/test_geometry/*.cpp")
# file(GLOB test_py_files "${CMAKE_TEST_DIR}/*/runtest*.py")
endif(BUILD_TESTING OR BUILD_CPPUNIT_TEST)
......
#define BOOST_TEST_MODULE PointTest
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "../geometry/Point.h"
#include <cmath>
BOOST_AUTO_TEST_SUITE(PointTest)
BOOST_AUTO_TEST_CASE(Point_Constructor_Test)
{
BOOST_TEST_MESSAGE("Starting Point ctor test");
Point p;
BOOST_REQUIRE(p.GetX() == 0 && p.GetY() == 0);
Point p2(1, 1);
BOOST_REQUIRE(p2.GetX() == 1 && p2.GetY() == 1);
Point p3(p2);
BOOST_REQUIRE(p3.GetX() == 1 && p3.GetY() == 1);
BOOST_TEST_MESSAGE("Leaving ctor test");
BOOST_MESSAGE("Starting setter test");
p2.SetX(0.5);
p2.SetY(-232.2);
BOOST_REQUIRE(p2.GetX() == 0.5 && p2.GetY() == -232.2);
BOOST_TEST_MESSAGE("Leaving setter test");
}
BOOST_AUTO_TEST_CASE(Point_Norm_Tests)
{
BOOST_TEST_MESSAGE("Starting norm test");
Point p1(0,0);
BOOST_CHECK(p1.Norm() == 0);
p1.SetX(1);
BOOST_CHECK(p1.Norm() == 1);
p1.SetX(-1);
BOOST_CHECK(p1.Norm() == 1);
p1.SetX(3);
BOOST_CHECK(p1.Norm() == 3);
p1.SetX(0);
p1.SetY(1);
BOOST_CHECK(p1.Norm() == 1);
p1.SetY(-1);
BOOST_CHECK(p1.Norm() == 1);
p1.SetY(3);
BOOST_CHECK(p1.Norm() == 3);
p1.SetX(3);
p1.SetY(4);
BOOST_CHECK(p1.Norm() == 5);
BOOST_TEST_MESSAGE("Leaving norm test");
}
BOOST_AUTO_TEST_CASE(POINT_TO_STRING_Test)
{
BOOST_TEST_MESSAGE("starting string conv test");
std::string xpt[] = {"0.25", "1.25", "2.25", "3.25"};
std::string ypt[] = {"10.25", "11.25", "12.25", "13.25"};
Point p1;
for (double i = 0.25; i < 4; ++i)
{
p1.SetX(i);
p1.SetY(i+10);
BOOST_CHECK( p1.toString() == "( " + xpt[int(i)] +
" : " + ypt[int(i)] + " )" );
}
Point p2(-2,-0.5);
BOOST_CHECK( p2.toString() == "( -2 : -0.5 )" );
BOOST_TEST_MESSAGE("Leaving string conv test");
}
BOOST_AUTO_TEST_CASE(POINT_NORM_MOLIFIED_TEST)
{
BOOST_TEST_MESSAGE("starting NormMolified test");
Point p;
for (double i = 0, j = 0.5; i < 10; ++i, ++j)
{
p.SetX(i);
p.SetY(j);
BOOST_CHECK( p.NormMolified() == sqrt(pow(i,2) + pow(j,2) + 0.1) );
}
BOOST_TEST_MESSAGE("Leaving NormMolified test");
}
BOOST_AUTO_TEST_CASE(POINT_NORM_SQUARE_TEST)
{
BOOST_TEST_MESSAGE("starting NormSquare test");
Point p;
for (double i = -5, j = 0.6; i < 5; ++i, ++j)
{
p.SetX(i);
p.SetY(j);
BOOST_CHECK( p.NormSquare() == pow(i,2) + pow(j,2) );
}
BOOST_TEST_MESSAGE("Leaving NormMSquare test");
}
BOOST_AUTO_TEST_CASE(POINT_NORMALIZE_TEST)
{
BOOST_MESSAGE("starting Normalize test");
Point p1(0.0001,0.0001);
Point p2(10,10);
p2 = p1.Normalized();
BOOST_MESSAGE(" check for norm < J_EPS ");
BOOST_REQUIRE( p2.GetX() == 0.0 && p2.GetY() == 0.0 );
for (double i = 0, j = -10; i < 5; ++i, ++j)
{
p1.SetX(i);
p1.SetY(j);
p2 = p1.Normalized();
BOOST_MESSAGE(" check for norm > J_EPS ");
BOOST_REQUIRE( p2.GetX() == i / p1.Norm() &&
p2.GetY() == j / p1.Norm() );
p2 = p1.NormalizedMolified();
BOOST_MESSAGE(" check for norm > J_EPS_GOAL ");
BOOST_REQUIRE( p2.GetX() == i / p1.NormMolified() &&
p2.GetY() == j / p1.NormMolified() );
}
BOOST_MESSAGE("Leaving normalize test");
}
BOOST_AUTO_TEST_CASE(POINT_DET_TEST)
{
BOOST_MESSAGE("starting determinant test");
const double PI = 3.14159265358979323846;
Point p1(10,5);
Point p2;
for (int i = 1; i < 5; ++i)
{
p2.SetX( cos(PI / -i) );
p2.SetY( sin(PI / i) );
BOOST_CHECK( p1.Det(p2) == 10 * sin(PI/i) - 5 * cos(PI/i));
//BOOST_CHECK( p1.Det(p2) == p1.CrossP(p2));
}
BOOST_MESSAGE("Leaving determinant test");
}
BOOST_AUTO_TEST_CASE(POINT_SCALARPRODUCT_TEST)
{
BOOST_MESSAGE("starting scalar product test");
const double PI = 3.14159265358979323846;
Point p1(10,5);
Point p2;
for (int i = 1; i < 5; ++i)
{
p2.SetX( cos(PI / i) );
p2.SetY( sin(PI / -i) );
BOOST_CHECK( p1.ScalarP(p2) == 10 * p2.GetX() + 5 * p2.GetY() );
}
BOOST_MESSAGE("Leaving scalar product test");
}
BOOST_AUTO_TEST_CASE(POINT_OPEROVERLOADING_TEST)
{
BOOST_MESSAGE("starting operator overload test");
const double PI = 3.14159265358979323846;
for (int i = 1; i < 10; ++i)
{
Point p1(i, -i*10);
Point p2( cos(PI/i), sin(PI/i) );
Point sum = p1 + p2;
BOOST_REQUIRE( sum.GetX() == i + cos(PI/i) &&
sum.GetY() == -i*10 + sin(PI/i) );
Point sub = p1 - p2;
BOOST_REQUIRE( sub.GetX() == i - cos(PI/i) &&
sub.GetY() == -i*10 - sin(PI/i) );
Point mul = p2 * i;
BOOST_REQUIRE( mul.GetX() == i * cos(PI/i) &&
mul.GetY() == i * sin(PI/i) );
Point pluseq(i, i);
pluseq += p1;
BOOST_REQUIRE( pluseq.GetX() == i + i &&
pluseq.GetY() == -i*10 + i );
Point div = p2 / 1E-7;
BOOST_REQUIRE( div.GetX() == p2.GetX() &&
div.GetY() == p2.GetY() );
div = p2 / 2;
BOOST_REQUIRE( div.GetX() == p2.GetX() / 2 &&
div.GetY() == p2.GetY() / 2 );
BOOST_CHECK( p1 != p2 );
p1.SetX( p2.GetX() );
p1.SetY( p2.GetY() );
BOOST_CHECK( p1 == p2 );
}
BOOST_MESSAGE("Leaving operator overload test");
}
BOOST_AUTO_TEST_CASE(POINT_COORDTRANS_TO_ELLIPSE_TEST)
{
BOOST_MESSAGE("starting coord transform to ellipse");
const double PI = 3.14159265358979323846;
for (int i = 1; i < 5; ++i)
{
Point p1(i*10, i/10);
Point center(i, -i);
Point check = (p1 - center).Rotate( cos(PI/i), -sin(PI/i) );
Point transform = p1.CoordTransToEllipse( center, cos(PI/i), sin(PI/i) );
BOOST_CHECK( transform == check );
}
BOOST_MESSAGE("Leaving coord transform to ellipse");
}
BOOST_AUTO_TEST_CASE(POINT_COORDTRANS_TO_CART_TEST)
{
BOOST_MESSAGE("starting coord transform to cartesian");
const double PI = 3.14159265358979323846;
for (int i = 1; i < 5; ++i)
{
Point p1(i*10, i/10);
Point center(-i, i);
Point transform = p1.CoordTransToCart( center, cos(PI/i), sin(PI/i) );
Point check = p1.Rotate( cos(PI/i), sin(PI/i) );
BOOST_REQUIRE( transform.GetX() == check.GetX() - i &&
transform.GetY() == check.GetY() + i );
}
BOOST_MESSAGE("starting coord transform to cartesian");
}
BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
#define BOOST_TEST_MODULE LineTest
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "../geometry/Line.h"
#include <cmath>
BOOST_AUTO_TEST_SUITE(LineTest)
BOOST_AUTO_TEST_CASE(LINE_CONSTRUCTOR_TEST)
{
BOOST_MESSAGE("starting Default constr test");
Line L1;
Point P1 = L1.GetPoint1();
Point P2 = L1.GetPoint2();
BOOST_REQUIRE(P1.GetX() == 0 && P1.GetY() == 0);
BOOST_REQUIRE(P2.GetX() == 0 && P2.GetY() == 0);
Line L2;
BOOST_REQUIRE(L1.GetUniqueID() == 0 && L2.GetUniqueID() == 1);
BOOST_MESSAGE("Leaving Default constr test");
BOOST_MESSAGE("starting constr test");
const double PI = 3.14159265358979323846;
for (int i = -5, j = 2; i < 5; ++i, ++j)
{
i = (i == 0)? 1 : i;
P1.SetX(cos(PI / i));
P1.SetY(sin(PI * i));
P2.SetX(i);
P2.SetY(i * i);
Line L3(P1, P2);
Line L4(L3);
Point P3 = L4.GetPoint1();
Point P4 = L4.GetPoint2();
BOOST_REQUIRE(P1.GetX() == P3.GetX() && P2.GetX() == P4.GetX());
BOOST_REQUIRE(P1.GetY() == P3.GetY() && P2.GetY() == P4.GetY());
BOOST_CHECK(j == L4.GetUniqueID());
}
BOOST_MESSAGE("Leaving constr test");
}
BOOST_AUTO_TEST_CASE(LINE_NORMAL_VEC_TEST)
{
BOOST_MESSAGE("starting normal vector test");
const double PI = 3.14159265358979323846;
for (int i = -5; i < 5; ++i)
{
i = (i == 0)? 1 : i;
Point P1 (PI / i, PI * i);
Point P2 (i, sin(PI / i));
Line L1 (P1, P2);
Point normal = L1.NormalVec();
Point diff = P2 - P1;
BOOST_CHECK_MESSAGE(normal.ScalarP(diff) < 1E-12,
"normal.ScalarP(diff) = " << normal.ScalarP(diff) );
}
BOOST_MESSAGE("Leaving normal vector test");
}
BOOST_AUTO_TEST_CASE(LINE_SHORTEST_POINT_TEST)
{
BOOST_MESSAGE("starting shortest point test");
const double PI = 3.14159265358979323846;
Point PA (-2, 4);
Point PB (14, 9);
Line L1 (PA, PB);
const Point& DPAB = PA - PB;
double lambda;
for (float i = -20; i < 20; ++i)
{
i = (i == 0)? 0.5 : i;
Point P1 (i, sin(PI / i));
Point P2 = L1.ShortestPoint(P1);
lambda = (P1 - PB).ScalarP(DPAB) / DPAB.ScalarP(DPAB);
if (lambda > 1)
BOOST_CHECK_MESSAGE(P2 == PA, " P2 = ( " << P2.GetX() << ", " << P2.GetY() << ")");
else if(lambda < 0)
BOOST_CHECK_MESSAGE(P2 == PB, " P2 = ( " << P2.GetX() << ", " << P2.GetY() << ")");
else
BOOST_CHECK_MESSAGE((P2 - P1).ScalarP(DPAB) < 1E-12,
" P2 = ( " << P2.GetX() << ", " << P2.GetY() << ")");
}
BOOST_MESSAGE("Leaving shortest point test");
}
BOOST_AUTO_TEST_CASE(LINE_ISINLINESEGMENT_TEST)
{
BOOST_MESSAGE("starting is_in_linesegment test");
Line L1(Point(1,0), Point(10,0));
for (int i = 1; i <= 10; ++i)
BOOST_CHECK(L1.IsInLineSegment(Point(i, 0)));
for (int i = 0; i < 20; ++i)
BOOST_CHECK(!L1.IsInLineSegment(Point(i, i)));
BOOST_MESSAGE("Leaving is_in_linesegment test");
}
BOOST_AUTO_TEST_CASE(LINE_DIST_TO_TEST)
{
BOOST_MESSAGE("starting dist to shortestPoint test");
Line L1(Point(-10, 2), Point(10, 2));
for (int i = -10; i < 11; ++i)
{
BOOST_CHECK_MESSAGE(L1.DistTo(Point(i, i)) == abs(i-2), L1.DistTo(Point(i, i)));
BOOST_CHECK_MESSAGE(L1.DistToSquare(Point(i, i)) == abs(i-2)^2, L1.DistToSquare(Point(i, i)));
}
BOOST_MESSAGE("Leaving dist to shortestPoint test");
}
BOOST_AUTO_TEST_CASE(LINE_OPERATOR_TEST)
{
BOOST_MESSAGE("starting operator overload test");
const double PI = 3.14159265358979323846;
for (int i = -5; i < 5; ++i)
{
i = (i == 0)? 1 : i;
Point P1 (PI / i, PI * i);
Point P2 (i, sin(PI / i));
Line L1 (P1, P2);
Line L2 (P1, P2);
BOOST_CHECK(L1 == L2);
Point P3 (i, i);
Line L3 (P2, P3);
BOOST_CHECK(L1 != L3);
}
BOOST_MESSAGE("Leaving operator overload test");
}
BOOST_AUTO_TEST_CASE(LINE_LENGTH_TEST)
{
BOOST_MESSAGE("starting line length test");
Point P1;
const double PI = 3.14159265358979323846;
for (int i = -5; i < 5; ++i)
{
i = (i == 0)? 1 : i;
Point P2 (i, sin(PI / i));
Line L1 (P1, P2);
double norm = P2.Norm();
BOOST_CHECK(L1.Length() == norm);
double normSq = P2.NormSquare();
BOOST_CHECK(L1.LengthSquare() == normSq);
}
}
BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
Utest/test_13/flow.png

38 KB | W: | H:

Utest/test_13/flow.png

38.3 KB | W: | H:

Utest/test_13/flow.png
Utest/test_13/flow.png
Utest/test_13/flow.png
Utest/test_13/flow.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -2,7 +2,7 @@
* \file Wall.cpp
* \date Nov 16, 2010
* \version v0.6
* \copyright <2009-2014> Forschungszentrum Jülich GmbH. All rights reserved.
* \copyright <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved.
*
* \section License
* This file is part of JuPedSim.
......
......@@ -2,7 +2,7 @@
* \file Wall.h
* \date Nov 16, 2010
* \version v0.6
* \copyright <2009-2014> Forschungszentrum Jülich GmbH. All rights reserved.
* \copyright <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved.
*
* \section License
* This file is part of JuPedSim.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment