-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a bunch of test cases for Position, including one that was previously a bug in the not equal operator. Change-Id: If49c035843d562fbff30f0da37a37fb67d5b020b Reviewed-on: https://codereview.kdab.com/c/kdab/kdutils/+/133342 Reviewed-by: Paul Lemire <paul.lemire@kdab.com> Tested-by: Continuous Integration <build@kdab.com>
- Loading branch information
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# This file is part of KDUtils. | ||
# | ||
# SPDX-FileCopyrightText: 2021-2023 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com> | ||
# Author: Joshua Goins <josh@redstrate.com> | ||
# | ||
# SPDX-License-Identifier: MIT | ||
# | ||
# Contact KDAB at <info@kdab.com> for commercial licensing options. | ||
# | ||
|
||
project( | ||
test-gui-position | ||
VERSION 0.1 | ||
LANGUAGES CXX | ||
) | ||
|
||
add_executable( | ||
${PROJECT_NAME} | ||
tst_position.cpp | ||
) | ||
|
||
target_link_libraries( | ||
${PROJECT_NAME} KDGui doctest | ||
) | ||
|
||
add_test(NAME ${PROJECT_NAME} COMMAND $<TARGET_FILE:${PROJECT_NAME}>) | ||
set_tests_properties(${PROJECT_NAME} PROPERTIES LABELS "Gui") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
This file is part of KDUtils. | ||
SPDX-FileCopyrightText: 2021-2023 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com> | ||
Author: Joshua Goins <joshua.goins@kdab.com> | ||
SPDX-License-Identifier: MIT | ||
Contact KDAB at <info@kdab.com> for commercial licensing options. | ||
*/ | ||
|
||
#include <KDGui/position.h> | ||
#include <array> | ||
|
||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN | ||
#include <doctest/doctest.h> | ||
|
||
using namespace KDGui; | ||
|
||
TEST_SUITE("Position") | ||
{ | ||
TEST_CASE("Constructor") | ||
{ | ||
const Position pos{ 1, 2 }; | ||
REQUIRE_EQ(pos.x, 1); | ||
REQUIRE_EQ(pos.y, 2); | ||
} | ||
TEST_CASE("Equality") | ||
{ | ||
const Position a{ 0, 2 }; | ||
const Position b{ 3, 4 }; | ||
const Position c{ 0, 0 }; | ||
|
||
REQUIRE(a == a); | ||
REQUIRE(a != b); | ||
REQUIRE(a != c); | ||
} | ||
TEST_CASE("Math Operators") | ||
{ | ||
const Position a{ 1, 2 }; | ||
const Position b{ 3, 4 }; | ||
|
||
REQUIRE_EQ(a + b, Position(4, 6)); | ||
REQUIRE_EQ(a - b, Position(-2, -2)); | ||
REQUIRE_EQ(a / int64_t{ 2 }, Position(0, 1)); | ||
} | ||
} |