File: PointTest.cxx

package info (click to toggle)
clam 1.4.0-6
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 17,836 kB
  • ctags: 20,981
  • sloc: cpp: 92,504; python: 9,721; ansic: 1,602; xml: 444; sh: 239; makefile: 153; perl: 54; asm: 15
file content (142 lines) | stat: -rw-r--r-- 3,126 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <cppunit/extensions/HelperMacros.h>
#include "cppUnitHelper.hxx"

#include "Point.hxx" // CLAM

namespace CLAMTest
{



class PointTest;

CPPUNIT_TEST_SUITE_REGISTRATION( PointTest );

class PointTest : public CppUnit::TestFixture
{
	CPPUNIT_TEST_SUITE( PointTest );
	CPPUNIT_TEST( testConstructor_TakesValues );
	CPPUNIT_TEST( testDefaultConstructor_InitAsZero );
	CPPUNIT_TEST( testSetY );
	CPPUNIT_TEST( testSetX );
	CPPUNIT_TEST( testInequality_WithDifferentValues );
	CPPUNIT_TEST( testStreamInsertion );
	CPPUNIT_TEST( testStreamExtraction );
	CPPUNIT_TEST( testStreamExtraction_WithSpacesToBeIgnored );
	CPPUNIT_TEST( testStreamExtraction_WithADifferentStartToken );
	CPPUNIT_TEST( testStreamExtraction_WithADifferentEndToken );
	CPPUNIT_TEST_SUITE_END();

public:
	/// Common initialization, executed before each test method
	void setUp() { }

	/// Common clean up, executed after each test method
	void tearDown() { }

private:

	void testConstructor_TakesValues()
	{
		CLAM::Point aPoint(3.0, 2.0);
		CPPUNIT_ASSERT_EQUAL( CLAM::TData(3.0), aPoint.GetX());
		CPPUNIT_ASSERT_EQUAL( CLAM::TData(2.0), aPoint.GetY());
	}

	void testDefaultConstructor_InitAsZero()
	{
		CLAM::Point zeroPoint(0.0, 0.0);
		CLAM::Point aDefaultConstructedPoint;

		CPPUNIT_ASSERT_EQUAL(aDefaultConstructedPoint, zeroPoint);
	}

	void testInequality_WithDifferentValues()
	{
		CLAM::Point pureXUnitPoint(1.0, 0.0);
		CLAM::Point pureYUnitPoint(0.0, 1.0);

		CPPUNIT_ASSERT(pureYUnitPoint != pureXUnitPoint);
	}

	void testSetY()
	{
		CLAM::Point aPoint(3.0, 2.0);
		aPoint.SetY(4.3);
		CPPUNIT_ASSERT_EQUAL(CLAM::Point(3.0,4.3), aPoint);
	}

	void testSetX()
	{
		CLAM::Point aPoint(3.0, 2.0);
		aPoint.SetX(4.3);
		CPPUNIT_ASSERT_EQUAL(CLAM::Point(4.3,2.0), aPoint);
	}


	void testStreamInsertion()
	{
		std::stringstream s;
		CLAM::Point point(1.453,3.454);
		std::string expectedString("{1.453 3.454}");

		s << point << std::flush;

		CPPUNIT_ASSERT_EQUAL(expectedString, s.str());
	}

	void testStreamExtraction()
	{
		CLAM::Point toBeModified(1,3);
		std::string inputString("{5.3 7.3}");
		CLAM::Point expected(5.3, 7.3);
		std::stringstream s(inputString);

		s >> toBeModified;

		CPPUNIT_ASSERT_EQUAL(expected, toBeModified);
	}

	void testStreamExtraction_WithSpacesToBeIgnored()
	{
		CLAM::Point toBeModified(1,3);
		std::string inputString(" \n  { \n 5.3 \n  7.3 \t } ");
		CLAM::Point expected(5.3, 7.3);
		std::stringstream s(inputString);

		s >> toBeModified;

		CPPUNIT_ASSERT_EQUAL(expected, toBeModified);
	}

	void testStreamExtraction_WithADifferentStartToken()
	{
		CLAM::Point toBeModified(1.3,3.2);
		CLAM::Point expected    (1.3,3.2);
		std::string inputString("a{5.3 7.3}");
		std::stringstream ss(inputString);

		ss >> toBeModified;

		CPPUNIT_ASSERT_EQUAL(expected, toBeModified);
	}

	void testStreamExtraction_WithADifferentEndToken()
	{
		CLAM::Point toBeModified(1.3,3.2);
		CLAM::Point expected    (1.3,3.2);
		std::string inputString("{5.3 7.3a a");
		std::stringstream ss(inputString);

		ss >> toBeModified;

		CPPUNIT_ASSERT_EQUAL(expected, toBeModified);
	}

};




} // namespace CLAMTes