Skip to content

Commit

Permalink
Tests for vector equality, negation and default construction
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Mott committed Apr 3, 2021
1 parent ea94a90 commit 1a74920
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
13 changes: 4 additions & 9 deletions libs/math/Vector3.h
Expand Up @@ -119,15 +119,10 @@ class BasicVector3
return !(*this == other);
}

/* Define the negation operator -
* All the vector's components are negated
*/
BasicVector3<T> operator- () const {
return BasicVector3<T>(
-_v[0],
-_v[1],
-_v[2]
);
/// Return the componentwise negation of this vector
BasicVector3<T> operator- () const
{
return BasicVector3<T>(-_v[0], -_v[1], -_v[2]);
}

/* Define the addition operators + and += with any other BasicVector3 of type OtherElement
Expand Down
33 changes: 33 additions & 0 deletions test/math/Vector3.cpp
Expand Up @@ -15,6 +15,21 @@ TEST(MathTest, ConstructVector3)
EXPECT_EQ(vec.z(), 3.5);
}

TEST(MathTest, DefaultConstructVector3)
{
Vector3 vec;

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

TEST(MathTest, ConstructVector3FromArray)
{
double values[3] = { 1.0, 14.0, -96.5 };
Vector3 vec(values);

EXPECT_EQ(vec, Vector3(1.0, 14.0, -96.5));
}

TEST(MathTest, PromoteVector3To4)
{
Vector3 v3(8, 12, -5);
Expand All @@ -31,6 +46,24 @@ TEST(MathTest, DemoteVector4To3)
EXPECT_EQ(v3, Vector3(1, -96, 0.125));
}

TEST(MathTest, Vector3EqualityComparison)
{
Vector3 v1(1, 2, 8);
Vector3 v1a(1, 2, 8);
Vector3 v2(9, 14, -0.5);

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

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

EXPECT_EQ(-vec, Vector3(-5, -10, -125));
}

TEST(MathTest, VectorLength)
{
Vector3 v3(3, 4, 5);
Expand Down

0 comments on commit 1a74920

Please sign in to comment.