Skip to content

Commit

Permalink
Add unit tests for Vector4 construction/equality
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Mott committed Sep 1, 2021
1 parent 4f9552e commit 5024bb0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
10 changes: 4 additions & 6 deletions libs/math/Vector4.h
Expand Up @@ -80,8 +80,8 @@ class BasicVector4
}

/**
* \brief
* Return a readable (pretty-printed) string representation of the vector
* \brief Return a readable (pretty-printed) string representation of the
* vector.
*
* We need a dedicated function for this because the standard operator<< is
* already used for serialisation to the less readable space-separated text
Expand All @@ -94,17 +94,15 @@ class BasicVector4
return ss.str();
}

/** Compare this BasicVector4 against another for equality.
*/
/// Compare this BasicVector4 against another for equality.
bool operator== (const BasicVector4& other) const {
return (other.x() == x()
&& other.y() == y()
&& other.z() == z()
&& other.w() == w());
}

/** Compare this BasicVector4 against another for inequality.
*/
/// Compare this BasicVector4 against another for inequality.
bool operator!= (const BasicVector4& other) const {
return !(*this == other);
}
Expand Down
35 changes: 35 additions & 0 deletions test/math/Vector.cpp
Expand Up @@ -30,6 +30,30 @@ TEST(MathTest, ConstructVector3FromArray)
EXPECT_EQ(vec, Vector3(1.0, 14.0, -96.5));
}

TEST(MathTest, ConstructVector4)
{
Vector4 vec(25.0, -356, 128.25, 14);

EXPECT_EQ(vec.x(), 25.0);
EXPECT_EQ(vec.y(), -356);
EXPECT_EQ(vec.z(), 128.25);
EXPECT_EQ(vec.w(), 14);
}

TEST(MathTest, ConstructVector4DefaultW)
{
Vector4 vec(16, 2, 8);

EXPECT_EQ(vec.w(), 1);
}

TEST(MathTest, DefaultConstructVector4)
{
Vector4 vec;

EXPECT_EQ(vec, Vector4(0, 0, 0, 0));
}

TEST(MathTest, SetVector3Components)
{
Vector3 vec(-16, 256, 0.95);
Expand Down Expand Up @@ -85,6 +109,17 @@ TEST(MathTest, VectorEpsilonComparison)
EXPECT_TRUE(math::isNear(v, v + Vector3(1000, 10000, 20000), 1e6));
}

TEST(MathTest, Vector4EqualityComparison)
{
Vector4 v1(-5, 27, 9562);
Vector4 v1a(-5, 27, 9562);
Vector4 v2(350, 0.025, 16);

EXPECT_EQ(v1, v1);
EXPECT_EQ(v1, v1a);
EXPECT_NE(v1, v2);
}

TEST(MathTest, NegateVector3)
{
Vector3 vec(5, 10, 125);
Expand Down

0 comments on commit 5024bb0

Please sign in to comment.