Vector2: Add unit tests
This commit is contained in:
parent
60db1c2eaf
commit
707700e24e
|
@ -15,7 +15,8 @@ set(TEST_SOURCES
|
||||||
zm_comms.cpp
|
zm_comms.cpp
|
||||||
zm_crypt.cpp
|
zm_crypt.cpp
|
||||||
zm_font.cpp
|
zm_font.cpp
|
||||||
zm_utils.cpp)
|
zm_utils.cpp
|
||||||
|
zm_vector2.cpp)
|
||||||
|
|
||||||
add_executable(tests main.cpp ${TEST_SOURCES})
|
add_executable(tests main.cpp ${TEST_SOURCES})
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,87 @@
|
||||||
|
/*
|
||||||
|
* This file is part of the ZoneMinder Project. See AUTHORS file for Copyright information
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation; either version 2 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "catch2/catch.hpp"
|
||||||
|
|
||||||
|
#include "zm_vector2.h"
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &os, Vector2 const &value) {
|
||||||
|
os << "{ X: " << value.X() << ", Y: " << value.Y() << " }";
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Vector2: default constructor") {
|
||||||
|
Vector2 c;
|
||||||
|
REQUIRE(c.X() == 0);
|
||||||
|
REQUIRE(c.Y() == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Vector2: x/y constructor") {
|
||||||
|
Vector2 c(1, 2);
|
||||||
|
|
||||||
|
REQUIRE(c.X() == 1);
|
||||||
|
REQUIRE(c.Y() == 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Vector2: assignment/copy") {
|
||||||
|
Vector2 c;
|
||||||
|
Vector2 c2(1, 2);
|
||||||
|
|
||||||
|
REQUIRE(c.X() == 0);
|
||||||
|
REQUIRE(c.Y() == 0);
|
||||||
|
|
||||||
|
SECTION("assignment operator") {
|
||||||
|
c = c2;
|
||||||
|
REQUIRE(c.X() == 1);
|
||||||
|
REQUIRE(c.Y() == 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("copy constructor") {
|
||||||
|
Vector2 c3(c2); // NOLINT(performance-unnecessary-copy-initialization)
|
||||||
|
REQUIRE(c3.X() == 1);
|
||||||
|
REQUIRE(c3.Y() == 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Vector2: comparison operators") {
|
||||||
|
Vector2 c1(1, 2);
|
||||||
|
Vector2 c2(1, 2);
|
||||||
|
Vector2 c3(1, 3);
|
||||||
|
|
||||||
|
REQUIRE((c1 == c2) == true);
|
||||||
|
REQUIRE((c1 != c3) == true);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Vector2: arithmetic operators") {
|
||||||
|
Vector2 c(1, 1);
|
||||||
|
|
||||||
|
SECTION("addition") {
|
||||||
|
Vector2 c1 = c + Vector2(1, 1);
|
||||||
|
REQUIRE(c1 == Vector2(2, 2));
|
||||||
|
|
||||||
|
c += {1, 2};
|
||||||
|
REQUIRE(c == Vector2(2, 3));
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("subtraction") {
|
||||||
|
Vector2 c1 = c - Vector2(1, 1);
|
||||||
|
REQUIRE(c1 == Vector2(0, 0));
|
||||||
|
|
||||||
|
c -= {1, 2};
|
||||||
|
REQUIRE(c == Vector2(0, -1));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue