Skip to content

Commit

Permalink
Add test code for Vector3.
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsy committed Apr 14, 2015
1 parent d98267d commit 046f173
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ script:
- CTEST_OUTPUT_ON_FAILURE=TRUE make check

after_success:
- lcov --directory . --capture --output-file converage.info
- lcov --directory . --capture --output-file coverage.info
- lcov --remove converage.info 'test/*' '/usr/*' 'CMakeFiles/*' --outputfile coverage.info
- lcov --list coverage.info
- coveralls-lcov --repo-token punfgYjHqV4P4flVjRVMnSk45TFIxeull coverage.info
Expand Down
10 changes: 5 additions & 5 deletions src/Renderer/Vector3.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ namespace rainy {

} // namespace rainy

rainy::Vector3 operator+(const rainy::Vector3& v1, const rainy::Vector3& v2);
rainy::Vector3 operator-(const rainy::Vector3& v1, const rainy::Vector3& v2);
rainy::Vector3 operator*(const rainy::Vector3& v, double s);
rainy::Vector3 operator*(double s, const rainy::Vector3& v);
rainy::Vector3 operator/(const rainy::Vector3& v, double s);
RAINY_VECTOR3_DLL rainy::Vector3 operator+(const rainy::Vector3& v1, const rainy::Vector3& v2);
RAINY_VECTOR3_DLL rainy::Vector3 operator-(const rainy::Vector3& v1, const rainy::Vector3& v2);
RAINY_VECTOR3_DLL rainy::Vector3 operator*(const rainy::Vector3& v, double s);
RAINY_VECTOR3_DLL rainy::Vector3 operator*(double s, const rainy::Vector3& v);
RAINY_VECTOR3_DLL rainy::Vector3 operator/(const rainy::Vector3& v, double s);

#endif // RAINY_VECTOR3_H_
32 changes: 31 additions & 1 deletion test/test_Vector3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "../include/rainy.h"
using namespace rainy;

TEST(InstanceTest, ValidCall) {
TEST(Vector3Test, InstanceTest) {
Vector3 v;
EXPECT_EQ(0.0, v.x());
EXPECT_EQ(0.0, v.y());
Expand All @@ -25,6 +25,36 @@ TEST(InstanceTest, ValidCall) {
EXPECT_EQ(6.0, v.z());
}

TEST(Vector3Test, AlgebraTest) {
Vector3 w;
Vector3 v(1.0, 2.0, 3.0);
Vector3 u(1.0, 2.0, 3.0);

w = u + v;
EXPECT_EQ(2.0, w.x());
EXPECT_EQ(4.0, w.y());
EXPECT_EQ(6.0, w.z());

w = u - v;
EXPECT_EQ(0.0, w.x());
EXPECT_EQ(0.0, w.y());
EXPECT_EQ(0.0, w.z());

w = u * 5.0;
EXPECT_EQ(5.0, w.x());
EXPECT_EQ(10.0, w.y());
EXPECT_EQ(15.0, w.z());

w = u / 2.0;
EXPECT_EQ(0.5, w.x());
EXPECT_EQ(1.0, w.y());
EXPECT_EQ(1.5, w.z());

double dt = u.dot(v);
EXPECT_EQ(14.0, dt);
EXPECT_EQ(dt, v.dot(u));
}

int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
Expand Down

0 comments on commit 046f173

Please sign in to comment.