Skip to content

Commit

Permalink
Tests: unit tests for Point class
Browse files Browse the repository at this point in the history
  • Loading branch information
ddejean committed Dec 26, 2011
1 parent 2be2386 commit 5aa4c0c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Maths/Point.cpp
Expand Up @@ -23,3 +23,9 @@ Point Point::operator+(Vector v)
return p;
}

bool Point::operator ==(const Point &p)
{
return ((this->x == p.x)
&& (this->y == p.y)
&& (this->z == p.z));
}
2 changes: 1 addition & 1 deletion Maths/Point.h
Expand Up @@ -17,7 +17,7 @@ class Point {
Point(double x, double y, double z);
Point operator+(Vector v);
friend Vector operator-(const Point &p1, const Point &p2);
friend std::istream &operator>>(std::istream &inputFile, Point &p);
bool operator ==(const Point &p);
};


Expand Down
30 changes: 30 additions & 0 deletions tests/TestPoint.cpp
@@ -0,0 +1,30 @@
#include "TestPoint.h"
#include "Maths/Vector.h"

void TestPoint::setUp(void)
{
a = Point();
b = Point();
c = Point();
}

void TestPoint::testEquals(void)
{
a = Point(1.0, 2.0, 3.0);

TS_ASSERT_EQUALS(a, a);
TS_ASSERT_EQUALS(b, b);
TS_ASSERT_DIFFERS(a, b);
}

void TestPoint::testPlus(void)
{
Vector v = Vector(1.0, 1.0, 1.0);
Point a = Point(0.0, 0.0, 0.0);
Point b = Point(2.0, 2.0, 2.0);

c = a + v;
TS_ASSERT_EQUALS(c, c);
c = c + v;
TS_ASSERT_EQUALS(c, b);
}
18 changes: 18 additions & 0 deletions tests/TestPoint.h
@@ -0,0 +1,18 @@
#ifndef TESTPOINT_H_
#define TESTPOINT_H_

#include "cxxtest/TestSuite.h"
#include "Maths/Point.h"

class TestPoint: public CxxTest::TestSuite {
private:
Point a, b, c;

public:
void setUp(void);

void testEquals(void);
void testPlus(void);
};

#endif /* TESTPOINT_H_ */

0 comments on commit 5aa4c0c

Please sign in to comment.