Skip to content

Commit

Permalink
Add some tests for Position
Browse files Browse the repository at this point in the history
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
redstrate committed Nov 8, 2023
1 parent 83ba0f9 commit 03f7602
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/auto/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ project(KDGui-Tests)

include_directories(../KDFoundation/common)

add_subdirectory(position)
add_subdirectory(window)

if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
Expand Down
27 changes: 27 additions & 0 deletions tests/auto/gui/position/CMakeLists.txt
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")
47 changes: 47 additions & 0 deletions tests/auto/gui/position/tst_position.cpp
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));
}
}

0 comments on commit 03f7602

Please sign in to comment.