Files
OpenVulkano/tests/Math/Range.cpp
Vladyslav Baranovskyi a2c5b1f284 tests file for Range.hpp
2024-10-08 12:37:55 +03:00

57 lines
1.2 KiB
C++

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <catch2/catch_all.hpp>
#include "Math/Range.hpp"
using namespace OpenVulkano::Math;
using RangeType = Range<int>;
// The class does not have a default constructor... So rely on warnings about unitialized members
TEST_CASE("Parameterized constructor", "[Range]")
{
int min = 10;
int max = 20;
RangeType range(min, max);
REQUIRE(range.GetMin() == min);
REQUIRE(range.GetMax() == max);
}
TEST_CASE("GetMin and GetMax", "[Range]")
{
int min = 10;
int max = 20;
RangeType range(min, max);
// Test const-qualified access
const RangeType& constRange = range;
REQUIRE(constRange.GetMin() == min);
REQUIRE(constRange.GetMax() == max);
// Test non-const access
range.GetMin() = 30;
range.GetMax() = 40;
REQUIRE(range.GetMin() == 30);
REQUIRE(range.GetMax() == 40);
}
TEST_CASE("GetSize", "[Range]")
{
int min = 10;
int max = 20;
RangeType range(min, max);
REQUIRE(range.GetSize() == 10);
}
TEST_CASE("GetSize with negative", "[Range]")
{
int min = -10;
int max = 10;
RangeType range(min, max);
REQUIRE(range.GetSize() == 20);
}