31 #include <cxxtest/TestSuite.h>
33 #include "../../exceptions/WOutOfBounds.h"
34 #include "../../WLimits.h"
36 #include "WLineTraits.h"
37 #include "WPositionTraits.h"
57 TS_ASSERT_EQUALS( equalsDelta( line, other, 0.0 ), 1 );
103 std::string expected(
"[1.0000000000000000e+00;1.0000000000000000e+00;3.1415000000000002e+00;, "
104 "0.0000000000000000e+00;0.0000000000000000e+00;4.4000000000000000e-01;, "
105 "1.0000000000000000e+00;1.0000000000000000e+00;1.0000000000000000e+00;]" );
106 std::stringstream ss;
108 TS_ASSERT_EQUALS( expected, ss.str() );
124 TS_ASSERT_EQUALS( line1, line2 );
125 line2.
back()[1] += 0.0000000001;
126 TS_ASSERT_DIFFERS( line1, line2 );
140 TS_ASSERT_EQUALS( expected, line[2] );
158 TS_ASSERT_EQUALS( line, expected );
173 TS_ASSERT_DELTA( expected, pathLength( line ), 1e-6 );
204 for(
size_t i = 0; i < 10; ++i )
208 TS_ASSERT( line.
size() == 10 );
209 WLine expected( line );
221 for(
int i = 0; i < 3; ++i )
240 for(
int i = 0; i < 100; ++i )
246 expected.
push_back(
WPosition( i + 0.75, std::pow( -1.0, ( i + 1 ) % 2 ) * 0.5, 0 ) );
266 for(
size_t i = 1; i < 1001; ++i )
286 TS_ASSERT_EQUALS( expected,
WPosition( midPoint( line ) ) );
299 TS_ASSERT_EQUALS( expected,
WPosition( midPoint( line ) ) );
310 TS_ASSERT_THROWS_EQUALS( midPoint( line ),
WOutOfBounds &e, std::string( e.
what() ),
"There is no midpoint for an empty line." );
323 TS_ASSERT_DELTA( maxSegmentLength( line ), std::sqrt( 2.0 ),
wlimits::DBL_EPS );
334 TS_ASSERT_EQUALS( maxSegmentLength( line ), 0.0 );
336 TS_ASSERT_EQUALS( maxSegmentLength( line ), 0.0 );
378 WLine expected( line );
431 if( ( diffPos = equalsDelta( first, second, delta ) ) != -1 )
433 using string_utils::operator<<;
434 std::stringstream msg;
435 msg <<
"Lines are different in at least point: " << diffPos;
436 TS_FAIL( msg.str() );
437 if(
static_cast< int >( first.
size() ) > diffPos &&
static_cast< int >( second.
size() ) > diffPos )
439 std::cout <<
"first line at: " << diffPos << std::endl << first[diffPos] << std::endl;
440 std::cout <<
"second line at: " << diffPos << std::endl << second[diffPos] << std::endl;
444 std::cout <<
"lines does not have the same number of points: first=" << first.
size() <<
" second=" << second.
size() << std::endl;
446 std::cout <<
"first line: " << std::endl << first << std::endl;
447 std::cout <<
"second line: " << std::endl << second << std::endl;
virtual const char * what() const
Returns the message string set on throw.
Unit tests the WLine class.
void testEqualsDeltaOnRealDifferentLines(void)
If both lines are of same size, but there is a point differing on more than the given delta the first...
void testDownSampleLine(void)
When resampling a line a new line is generated having the given number of sampling points.
void testSamplingPointsAreExactlyInTheOldSegmentCenterAndCorners(void)
If the points are exactly in between of a segement nothing should fail.
void testReverseOrdering(void)
If for example the start and end points of two lines are in opposite direction we may want to change ...
void testMidPointOnEmptyLine(void)
When calling midPoint on empty lines => there is no point to return hence an exception is generated.
void testResamplingByNewSegmentLengthWithZeroLine(void)
No sample points should remain no sample points.
void testManySampelsInBetweenOfTwoOldPoints(void)
If there are many new sample points between two old sample points nothing should fail either.
void testMidPointOnEvenSize(void)
The mid point of a WLine is just the point in the middle of the line.
void testResamplingByNewSegementLengthOldSegmentLengthBiggerAsNewSegmentLength(void)
If there is a segement bigger than the newSegmentLength, then the new segment should be inserted and ...
void testPathLength(void)
The path length of the line is the accumulated path lengths of all segements (point to point) in that...
void testEqualsDeltaDifferentLength(void)
If two lines have different lengths they are considered diffrent regardless on the given delta and th...
void testEmptyLineOnMaxSegementLength(void)
If there no points at all, 0.0 shall be returned.
void testEqualsDeltaOnDifferentLinesButWithinDelta(void)
If both lines are of same size and every point pair don't differ in terms of the given delta,...
void testMaxSegementLength(void)
The max segemnent length is the maximum length over all segments (p_i<->p_j).
void testEqualityOperator(void)
Two Lines are equal if they have the same points in the same order.
void testMidPointOnUnevenSize(void)
When a line has uneven numbered size, the mid point is unique.
void testRemoveAdjacentDuplicates(void)
If there are duplicates next to each other => collapse them.
void testSamplingWithSameNumberOfPoints(void)
If the resampling rate of a line has as many points as the original line, no sampling should be appli...
void testOutputOperator(void)
When printing a line to stdout it the output should be as follows: [first_pos, ......
void testResamplingByNewSegementLengthTravelingOutOfTheCircle(void)
Only if a sample point comes out of the circle with radius newSegmentLength then append the point of ...
void testResamplingByNewSegementLengthWithLineHavingJustOnePoint(void)
Lines with size() == 1, should also remain untouched.
void testAccessOperatorWithinValidBounds(void)
When accessing an item within 0..length-1 a const reference to the WPosition object should be returne...
void assert_equals_delta(const WLine &first, const WLine &second, double delta=wlimits::DBL_EPS) const
TS_ASSERT_DELTA needs the operator+, operator- and operator< to be implemented especially for WPositi...
void testNumericalStabilityOfResampling(void)
When resampling with many sample points the numerical errors may sum up.
A line is an ordered sequence of WPositions.
void resampleByNumberOfPoints(size_t numPoints)
Resample this line so it has a number of given points afterwards.
void reverseOrder()
Reverses the order of the points.
void removeAdjacentDuplicates()
Collapse samplepoints which are equal and neighboured.
void resampleBySegmentLength(double newSegementLength)
Resample this line so there are only segements of the given length.
void pop_back()
Wrapper around std::vector member function.
size_type size() const
Wrapper around std::vector member function.
void push_back(const value_type &value)
Wrapper around std::vector member function.
const_reference back() const
Wrapper around std::vector member function.
Indicates invalid element access of a container.
This only is a 3d double vector.
const double DBL_EPS
Smallest double such: 1.0 + DBL_EPS == 1.0 is still true.