diff --git a/tempest/vector/C2Vector.cpp b/tempest/vector/C2Vector.cpp new file mode 100644 index 0000000..9819fde --- /dev/null +++ b/tempest/vector/C2Vector.cpp @@ -0,0 +1,5 @@ +#include "tempest/vector/C2Vector.hpp" + +bool C2Vector::operator==(const C2Vector& v) { + return this->x == v.x && this->y == v.y; +} diff --git a/tempest/vector/C2Vector.hpp b/tempest/vector/C2Vector.hpp index 47a85f4..c445c8d 100644 --- a/tempest/vector/C2Vector.hpp +++ b/tempest/vector/C2Vector.hpp @@ -12,6 +12,7 @@ class C2Vector { C2Vector(float x, float y) : x(x) , y(y) {}; + bool operator==(const C2Vector& v); }; #endif diff --git a/test/Vector.cpp b/test/Vector.cpp index 6019f02..93f0c42 100644 --- a/test/Vector.cpp +++ b/test/Vector.cpp @@ -15,6 +15,22 @@ TEST_CASE("C2Vector", "[vector]") { } } +TEST_CASE("C2Vector::operator==", "[vector]") { + SECTION("returns true when compared to identical vector") { + auto vector1 = C2Vector(1.0f, 2.0f); + auto vector2 = C2Vector(1.0f, 2.0f); + auto identical = vector1 == vector2; + REQUIRE(identical); + } + + SECTION("returns false when compared to different vector") { + auto vector1 = C2Vector(2.0f, 1.0f); + auto vector2 = C2Vector(1.0f, 2.0f); + auto identical = vector1 == vector2; + REQUIRE(!identical); + } +} + TEST_CASE("C3Vector", "[vector]") { SECTION("constructs with default constructor") { C3Vector vector;