From 323ac318f8b8401414ba1e1e32542b17abad4f63 Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Sun, 4 Aug 2019 22:21:50 -0700 Subject: [PATCH] Add coverage checks. --- CMakeLists.txt | 2 ++ include/wrmath/geom/vector.h | 10 ++++++++-- test/vector_test.cc | 30 ++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d25302f..ee8d47c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,8 @@ if(DEFINED ENV{CMAKE_GCOV}) add_compile_options(-fprofile-arcs -ftest-coverage) # Need CMake 3.15+. add_link_options(-fprofile-arcs -ftest-coverage) +add_custom_target(coverage COMMAND lcov -d . -t wrmath -o wrmath.info -c + COMMAND genhtml -o coverage-report wrmath.info) endif() diff --git a/include/wrmath/geom/vector.h b/include/wrmath/geom/vector.h index 1c13b55..2af42c7 100644 --- a/include/wrmath/geom/vector.h +++ b/include/wrmath/geom/vector.h @@ -29,12 +29,18 @@ public: * The default constructor creates a zero vector for a given * type and size. */ - Vector() { wr::math::DefaultEpsilon(this->epsilon); } + Vector() + { + wr::math::DefaultEpsilon(this->epsilon); + for (size_t i = 0; i < N; i++) { + this->arr[i] = 0.0; + } + } /** * If given an initializer_list, the vector is created with * those values. There must be exactly N elements in the list. - * @param ilstutil + * @param ilst An intializer list with N elements of type T. */ Vector(std::initializer_list ilst) { diff --git a/test/vector_test.cc b/test/vector_test.cc index 7913434..6f67aad 100644 --- a/test/vector_test.cc +++ b/test/vector_test.cc @@ -1,3 +1,4 @@ +#include #include #include @@ -5,6 +6,25 @@ using namespace std; using namespace wr; +TEST(Vector3Miscellaneous, ExtractionOperator) +{ + geom::Vector3d vec {1.0, 2.0, 3.0}; + stringstream vecBuffer; + + vecBuffer << vec; + EXPECT_EQ(vecBuffer.str(), "<1, 2, 3>"); +} + + +TEST(Vector3Miscellaneous, SetEpsilon) +{ + geom::Vector3f a {1.0, 1.0, 1.0}; + geom::Vector3f b; + + a.setEpsilon(1.1); + EXPECT_EQ(a, b); +} + TEST(Vector3FloatTests, Magnitude) { geom::Vector3f v3f {1.0, -2.0, 3.0}; @@ -105,6 +125,7 @@ TEST(Vector3FloatTests, ParallelOrthogonalVectors) geom::Vector3f d {-1.821, 1.072, -2.94}; geom::Vector3f e {-2.0, 1.0, 3.0}; geom::Vector3f f {-6.0, 3.0, 9.0}; + geom::Vector3f zeroVector; EXPECT_FALSE(a.isParallel(b)); EXPECT_FALSE(a.isOrthogonal(b)); @@ -114,6 +135,10 @@ TEST(Vector3FloatTests, ParallelOrthogonalVectors) EXPECT_TRUE(e.isParallel(f)); EXPECT_FALSE(e.isOrthogonal(f)); + + EXPECT_TRUE(zeroVector.isZero()); + EXPECT_TRUE(c.isParallel(zeroVector)); + EXPECT_TRUE(c.isOrthogonal(zeroVector)); } @@ -230,6 +255,7 @@ TEST(Vector3DoubleTests, ParallelOrthogonalVectors) geom::Vector3d d {-1.821, 1.072, -2.94}; geom::Vector3d e {-2.0, 1.0, 3.0}; geom::Vector3d f {-6.0, 3.0, 9.0}; + geom::Vector3d zeroVector; EXPECT_FALSE(a.isParallel(b)); EXPECT_FALSE(a.isOrthogonal(b)); @@ -239,6 +265,10 @@ TEST(Vector3DoubleTests, ParallelOrthogonalVectors) EXPECT_TRUE(e.isParallel(f)); EXPECT_FALSE(e.isOrthogonal(f)); + + EXPECT_TRUE(zeroVector.isZero()); + EXPECT_TRUE(c.isParallel(zeroVector)); + EXPECT_TRUE(c.isOrthogonal(zeroVector)); }