Thanks git for duping SOME tests
This commit is contained in:
@@ -1,68 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 "Base/UnitFormatter.hpp"
|
|
||||||
|
|
||||||
using namespace units::literals;
|
|
||||||
|
|
||||||
TEST_CASE("testUnitFormatterWithTrailingZeros", "[UnitFormatter]")
|
|
||||||
{
|
|
||||||
OpenVulkano::UnitFormatter metricFormatter(true, 2, false);
|
|
||||||
OpenVulkano::UnitFormatter imperialFormatter(false, 2, false);
|
|
||||||
|
|
||||||
units::length::meter_t positiveDistance = 1500.0_m;
|
|
||||||
units::length::meter_t smallDistance = 0.5_m;
|
|
||||||
units::length::meter_t negativeDistance = -100.0_m;
|
|
||||||
units::length::meter_t smallDistanceMetric = 0.05_m;
|
|
||||||
units::length::meter_t smallDistanceImperial = 0.03_m;
|
|
||||||
units::area::square_meter_t smallArea(0.005);
|
|
||||||
units::area::square_meter_t negativeArea(-50.0);
|
|
||||||
|
|
||||||
REQUIRE(metricFormatter.Format(positiveDistance) == "1.50 km");
|
|
||||||
REQUIRE(metricFormatter.Format(smallDistance) == "0.50 m");
|
|
||||||
REQUIRE(metricFormatter.Format(negativeDistance) == "-100.00 m");
|
|
||||||
REQUIRE(metricFormatter.Format(smallArea) == "0.01 m²");
|
|
||||||
REQUIRE(metricFormatter.Format(negativeArea) == "-50.00 m²");
|
|
||||||
REQUIRE(imperialFormatter.Format(smallDistance) == "1.64 ft");
|
|
||||||
REQUIRE(imperialFormatter.Format(negativeDistance) == "-328.08 ft");
|
|
||||||
REQUIRE(imperialFormatter.Format(smallArea) == "0.05 ft²");
|
|
||||||
REQUIRE(imperialFormatter.Format(negativeArea) == "-538.20 ft²");
|
|
||||||
REQUIRE(metricFormatter.Format(smallDistanceMetric) == "50.00 mm");
|
|
||||||
REQUIRE(imperialFormatter.Format(smallDistanceImperial) == "1.18 in");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("testUnitFormatterWithoutTrailingZeros", "[UnitFormatter]")
|
|
||||||
{
|
|
||||||
OpenVulkano::UnitFormatter metricFormatter(true, 2);
|
|
||||||
OpenVulkano::UnitFormatter imperialFormatter(false, 2);
|
|
||||||
|
|
||||||
units::length::meter_t positiveDistance = 1500.0_m;
|
|
||||||
units::length::meter_t smallDistance = 0.5_m;
|
|
||||||
units::length::meter_t negativeDistance = -100.0_m;
|
|
||||||
units::length::meter_t smallDistanceMetric = 0.05_m;
|
|
||||||
units::length::meter_t smallDistanceImperial = 0.03_m;
|
|
||||||
units::length::meter_t mediumDistanceMetric = 0.5_m;
|
|
||||||
units::length::meter_t largeDistanceMetric = 100.0_m;
|
|
||||||
units::area::square_meter_t smallArea(0.005);
|
|
||||||
units::area::square_meter_t negativeArea(-50.0);
|
|
||||||
|
|
||||||
REQUIRE(metricFormatter.Format(positiveDistance) == "1.5 km");
|
|
||||||
REQUIRE(metricFormatter.Format(smallDistance) == "0.5 m");
|
|
||||||
REQUIRE(metricFormatter.Format(negativeDistance) == "-100 m");
|
|
||||||
REQUIRE(metricFormatter.Format(smallArea) == "0.01 m²");
|
|
||||||
REQUIRE(metricFormatter.Format(negativeArea) == "-50 m²");
|
|
||||||
REQUIRE(imperialFormatter.Format(smallDistance) == "1.64 ft");
|
|
||||||
REQUIRE(imperialFormatter.Format(negativeDistance) == "-328.08 ft");
|
|
||||||
REQUIRE(imperialFormatter.Format(smallArea) == "0.05 ft²");
|
|
||||||
REQUIRE(imperialFormatter.Format(negativeArea) == "-538.2 ft²");
|
|
||||||
REQUIRE(metricFormatter.Format(smallDistanceMetric) == "50 mm");
|
|
||||||
REQUIRE(imperialFormatter.Format(smallDistanceImperial) == "1.18 in");
|
|
||||||
REQUIRE(metricFormatter.Format(smallDistanceMetric) == "50 mm");
|
|
||||||
REQUIRE(metricFormatter.Format(mediumDistanceMetric) == "0.5 m");
|
|
||||||
REQUIRE(metricFormatter.Format(largeDistanceMetric) == "100 m");
|
|
||||||
}
|
|
||||||
@@ -1,262 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 "Base/Utils.hpp"
|
|
||||||
|
|
||||||
enum class AnEnum
|
|
||||||
{
|
|
||||||
Zero = 0,
|
|
||||||
One = 1,
|
|
||||||
Max = 100
|
|
||||||
};
|
|
||||||
|
|
||||||
using namespace OpenVulkano;
|
|
||||||
|
|
||||||
TEST_CASE("EnumAsInt", "[Utils]")
|
|
||||||
{
|
|
||||||
REQUIRE(Utils::EnumAsInt(AnEnum::Zero) == 0);
|
|
||||||
REQUIRE(Utils::EnumAsInt(AnEnum::One) == 1);
|
|
||||||
REQUIRE(Utils::EnumAsInt(AnEnum::Max) == 100);
|
|
||||||
|
|
||||||
enum class EdgeEnum : int64_t
|
|
||||||
{
|
|
||||||
Min = INT64_MIN,
|
|
||||||
Max = INT64_MAX
|
|
||||||
};
|
|
||||||
REQUIRE(Utils::EnumAsInt(EdgeEnum::Min) == INT64_MIN);
|
|
||||||
REQUIRE(Utils::EnumAsInt(EdgeEnum::Max) == INT64_MAX);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("Align", "[Utils]")
|
|
||||||
{
|
|
||||||
REQUIRE(Utils::Align(1, 4) == 4);
|
|
||||||
REQUIRE(Utils::Align(2, 4) == 4);
|
|
||||||
REQUIRE(Utils::Align(3, 4) == 4);
|
|
||||||
REQUIRE(Utils::Align(4, 4) == 4);
|
|
||||||
REQUIRE(Utils::Align(5, 4) == 8);
|
|
||||||
REQUIRE(Utils::Align(6, 4) == 8);
|
|
||||||
REQUIRE(Utils::Align(7, 4) == 8);
|
|
||||||
REQUIRE(Utils::Align(8, 4) == 8);
|
|
||||||
|
|
||||||
REQUIRE(Utils::Align(0, 8) == 0);
|
|
||||||
REQUIRE(Utils::Align(SIZE_MAX, 8) == 0); // it is natural for this condition due to overflow
|
|
||||||
|
|
||||||
REQUIRE(Utils::Align(5, 1) == 5);
|
|
||||||
REQUIRE(Utils::Align(123456789, 1) == 123456789);
|
|
||||||
|
|
||||||
REQUIRE(Utils::Align(10, 16) == 16);
|
|
||||||
REQUIRE(Utils::Align(15, 16) == 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("AlignPage", "[Utils]")
|
|
||||||
{
|
|
||||||
REQUIRE(Utils::AlignPage(1000) == 4096);
|
|
||||||
REQUIRE(Utils::AlignPage(5000) == 8192);
|
|
||||||
|
|
||||||
REQUIRE(Utils::AlignPage(0) == 0);
|
|
||||||
REQUIRE(Utils::AlignPage(SIZE_MAX) == Utils::Align(SIZE_MAX, 4096));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("IsPow2", "[Utils]")
|
|
||||||
{
|
|
||||||
REQUIRE(Utils::IsPow2<uint32_t>(1));
|
|
||||||
REQUIRE(Utils::IsPow2<uint32_t>(2));
|
|
||||||
REQUIRE(Utils::IsPow2<uint32_t>(16));
|
|
||||||
REQUIRE_FALSE(Utils::IsPow2<uint32_t>(6));
|
|
||||||
|
|
||||||
REQUIRE(Utils::IsPow2<uint32_t>(0));
|
|
||||||
REQUIRE(Utils::IsPow2<uint64_t>(1ULL << 63));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("Log2OfPow2", "[Utils]")
|
|
||||||
{
|
|
||||||
REQUIRE(Utils::Log2OfPow2<uint32_t>(1) == 0);
|
|
||||||
REQUIRE(Utils::Log2OfPow2<uint32_t>(2) == 1);
|
|
||||||
REQUIRE(Utils::Log2OfPow2<uint32_t>(16) == 4);
|
|
||||||
|
|
||||||
REQUIRE(Utils::Log2OfPow2<uint64_t>(1ULL << 63) == 63);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("OctToInt", "[Utils]")
|
|
||||||
{
|
|
||||||
REQUIRE(Utils::OctToInt("7") == 7);
|
|
||||||
REQUIRE(Utils::OctToInt("10") == 8);
|
|
||||||
REQUIRE(Utils::OctToInt("1234") == 668);
|
|
||||||
REQUIRE(Utils::OctToInt("777") == 511);
|
|
||||||
REQUIRE(Utils::OctToInt("1000") == 512);
|
|
||||||
|
|
||||||
REQUIRE(Utils::OctToInt("000") == 0);
|
|
||||||
REQUIRE(Utils::OctToInt("07777") == 4095);
|
|
||||||
|
|
||||||
REQUIRE(Utils::OctToInt("9") == -1);
|
|
||||||
REQUIRE(Utils::OctToInt("A") == -1);
|
|
||||||
REQUIRE(Utils::OctToInt("") == 0);
|
|
||||||
|
|
||||||
REQUIRE(Utils::OctToInt(" 1234 ") == 668);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("StartsWith", "[Utils]")
|
|
||||||
{
|
|
||||||
REQUIRE(Utils::StartsWith("abcdef", "abc"));
|
|
||||||
REQUIRE(Utils::StartsWith("abcdef", "a"));
|
|
||||||
REQUIRE(Utils::StartsWith("abcdef", ""));
|
|
||||||
|
|
||||||
REQUIRE_FALSE(Utils::StartsWith("abcdef", "abcdz"));
|
|
||||||
REQUIRE_FALSE(Utils::StartsWith("a", "aa"));
|
|
||||||
REQUIRE_FALSE(Utils::StartsWith("", "a"));
|
|
||||||
REQUIRE(Utils::StartsWith("abcdef", "abcdef"));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("EndsWith", "[Utils]")
|
|
||||||
{
|
|
||||||
REQUIRE(Utils::EndsWith("abcdef", "def"));
|
|
||||||
REQUIRE(Utils::EndsWith("abcdef", "f"));
|
|
||||||
REQUIRE(Utils::EndsWith("abcdef", ""));
|
|
||||||
|
|
||||||
REQUIRE_FALSE(Utils::EndsWith("abcdef", "abcdeh"));
|
|
||||||
REQUIRE_FALSE(Utils::EndsWith("a", "aa"));
|
|
||||||
REQUIRE(Utils::EndsWith("abcdef", "abcdef"));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("SplitAtLastOccurrence Extended", "[Utils]")
|
|
||||||
{
|
|
||||||
auto result = Utils::SplitAtLastOccurrence("folder/file.txt", '/');
|
|
||||||
REQUIRE(result.first == "folder");
|
|
||||||
REQUIRE(result.second == "file.txt");
|
|
||||||
|
|
||||||
result = Utils::SplitAtLastOccurrence("test.ext", '.');
|
|
||||||
REQUIRE(result.first == "test");
|
|
||||||
REQUIRE(result.second == "ext");
|
|
||||||
|
|
||||||
result = Utils::SplitAtLastOccurrence("nochar", '/');
|
|
||||||
REQUIRE(result.first == "nochar");
|
|
||||||
REQUIRE(result.second == "");
|
|
||||||
|
|
||||||
result = Utils::SplitAtLastOccurrence("/leading/slash", '/');
|
|
||||||
REQUIRE(result.first == "/leading");
|
|
||||||
REQUIRE(result.second == "slash");
|
|
||||||
|
|
||||||
result = Utils::SplitAtLastOccurrence("/leadingonly/", '/');
|
|
||||||
REQUIRE(result.first == "/leadingonly");
|
|
||||||
REQUIRE(result.second == "");
|
|
||||||
|
|
||||||
result = Utils::SplitAtLastOccurrence("onlyslash/", '/');
|
|
||||||
REQUIRE(result.first == "onlyslash");
|
|
||||||
REQUIRE(result.second == "");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("Split", "[Utils]")
|
|
||||||
{
|
|
||||||
std::vector<std::string> result;
|
|
||||||
|
|
||||||
result = Utils::Split("a,b,c", ',');
|
|
||||||
REQUIRE(result.size() == 3);
|
|
||||||
REQUIRE(result[0] == "a");
|
|
||||||
REQUIRE(result[1] == "b");
|
|
||||||
REQUIRE(result[2] == "c");
|
|
||||||
|
|
||||||
result = Utils::Split("one|two|three", '|');
|
|
||||||
REQUIRE(result.size() == 3);
|
|
||||||
REQUIRE(result[0] == "one");
|
|
||||||
REQUIRE(result[1] == "two");
|
|
||||||
REQUIRE(result[2] == "three");
|
|
||||||
|
|
||||||
result = Utils::Split("", ',');
|
|
||||||
REQUIRE(result.empty());
|
|
||||||
|
|
||||||
result = Utils::Split("no separator here", ',');
|
|
||||||
REQUIRE(result.size() == 1);
|
|
||||||
REQUIRE(result[0] == "no separator here");
|
|
||||||
|
|
||||||
result = Utils::Split("a,,b,,c", ',');
|
|
||||||
REQUIRE(result.size() == 3);
|
|
||||||
REQUIRE(result[0] == "a");
|
|
||||||
REQUIRE(result[1] == "b");
|
|
||||||
REQUIRE(result[2] == "c");
|
|
||||||
|
|
||||||
result = Utils::Split(",a,b,c,", ',');
|
|
||||||
REQUIRE(result.size() == 3);
|
|
||||||
REQUIRE(result[0] == "a");
|
|
||||||
REQUIRE(result[1] == "b");
|
|
||||||
REQUIRE(result[2] == "c");
|
|
||||||
|
|
||||||
result = Utils::Split(",,,,,", ',');
|
|
||||||
REQUIRE(result.empty());
|
|
||||||
|
|
||||||
result = Utils::Split("a", ',');
|
|
||||||
REQUIRE(result.size() == 1);
|
|
||||||
REQUIRE(result[0] == "a");
|
|
||||||
|
|
||||||
result = Utils::Split(",,", ',');
|
|
||||||
REQUIRE(result.empty());
|
|
||||||
|
|
||||||
result = Utils::Split(",", ',');
|
|
||||||
REQUIRE(result.empty());
|
|
||||||
|
|
||||||
result = Utils::Split("a,", ',');
|
|
||||||
REQUIRE(result.size() == 1);
|
|
||||||
REQUIRE(result[0] == "a");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("Split with non-null-terminated strings", "[Utils]")
|
|
||||||
{
|
|
||||||
std::string_view input;
|
|
||||||
std::vector<std::string> result;
|
|
||||||
|
|
||||||
input = { "a,b,c|", 5 };
|
|
||||||
result = Utils::Split(input, ',');
|
|
||||||
|
|
||||||
REQUIRE(result.size() == 3);
|
|
||||||
REQUIRE(result[0] == "a");
|
|
||||||
REQUIRE(result[1] == "b");
|
|
||||||
REQUIRE(result[2] == "c");
|
|
||||||
|
|
||||||
input = { "one|two|three>", 13 };
|
|
||||||
result = Utils::Split(input, '|');
|
|
||||||
REQUIRE(result.size() == 3);
|
|
||||||
REQUIRE(result[0] == "one");
|
|
||||||
REQUIRE(result[1] == "two");
|
|
||||||
REQUIRE(result[2] == "three");
|
|
||||||
|
|
||||||
input = { "no separator here|", 17 };
|
|
||||||
result = Utils::Split(input, ',');
|
|
||||||
REQUIRE(result.size() == 1);
|
|
||||||
REQUIRE(result[0] == "no separator here");
|
|
||||||
|
|
||||||
input = { "a,,b,,c|", 7 };
|
|
||||||
result = Utils::Split(input, ',');
|
|
||||||
REQUIRE(result.size() == 3);
|
|
||||||
REQUIRE(result[0] == "a");
|
|
||||||
REQUIRE(result[1] == "b");
|
|
||||||
REQUIRE(result[2] == "c");
|
|
||||||
|
|
||||||
input = { ",a,b,c,|", 7 };
|
|
||||||
result = Utils::Split(input, ',');
|
|
||||||
REQUIRE(result.size() == 3);
|
|
||||||
REQUIRE(result[0] == "a");
|
|
||||||
REQUIRE(result[1] == "b");
|
|
||||||
REQUIRE(result[2] == "c");
|
|
||||||
|
|
||||||
input = { ",,,,|", 4 };
|
|
||||||
result = Utils::Split(input, ',');
|
|
||||||
REQUIRE(result.empty());
|
|
||||||
|
|
||||||
input = { "a|", 1 };
|
|
||||||
result = Utils::Split(input, ',');
|
|
||||||
REQUIRE(result.size() == 1);
|
|
||||||
REQUIRE(result[0] == "a");
|
|
||||||
|
|
||||||
input = { "a,|", 2 };
|
|
||||||
result = Utils::Split(input, ',');
|
|
||||||
REQUIRE(result.size() == 1);
|
|
||||||
REQUIRE(result[0] == "a");
|
|
||||||
|
|
||||||
input = { ",,,|", 3 };
|
|
||||||
result = Utils::Split(input, ',');
|
|
||||||
REQUIRE(result.empty());
|
|
||||||
}
|
|
||||||
@@ -1,562 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 "Base/Version.hpp"
|
|
||||||
|
|
||||||
using namespace OpenVulkano;
|
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
const std::string VERSION_1 = "1", VERSION_1_0 = "1.0", VERSION_V1_0 = "v1.0", VERSION_V2_0 = "v2.0", VERSION_2_0_SNAPSHOT = "2.0-SNAPSHOT";
|
|
||||||
const std::string VERSION_1_2_SNAPSHOT = "1.2-SNAPSHOT", VERSION_1_2 = "1.2", VERSION_1_2_BETA = "1.2-Beta", VERSION_1_2_BETA2 = "1.2-BETA2";
|
|
||||||
const std::string VERSION_1_2_SNAPSHOT_BUILD_5 = "1.2-SNAPSHOT-Build5", VERSION_1_2_SNAPSHOT_BUILD_8 = "1.2-SNAPSHOT-Build=8";
|
|
||||||
const std::string VERSION_1_2_SNAPSHOT_TIME_201703081212 = "1.2-SNAPSHOT-T201703081212", VERSION_1_2_SNAPSHOT_TIME_201603081212 = "1.2-SNAPSHOT-Timestamp=201603081212";
|
|
||||||
const Version version_1 = Version(VERSION_1), version_1_0 = Version(VERSION_1_0), version_v1_0 = Version(VERSION_V1_0), version_1_2_it = Version(VERSION_1_2, true);
|
|
||||||
const Version version_1_2_snapshot = Version(VERSION_1_2_SNAPSHOT), version_1_2 = Version(VERSION_1_2), version_1_2_snapshot_it = Version(VERSION_1_2_SNAPSHOT, true);
|
|
||||||
const Version version_1_2_beta = Version(VERSION_1_2_BETA), version_1_2_beta2 = Version(VERSION_1_2_BETA2), version_v2_0 = Version(VERSION_V2_0);
|
|
||||||
const Version version_2_0_snapshot = Version(VERSION_2_0_SNAPSHOT);
|
|
||||||
const Version version_1_2_snapshot_b_5 = Version(VERSION_1_2_SNAPSHOT_BUILD_5), version_1_2_snapshot_b_8 = Version(VERSION_1_2_SNAPSHOT_BUILD_8);
|
|
||||||
const Version version_1_2_snapshot_t_201703081212 = Version(VERSION_1_2_SNAPSHOT_TIME_201703081212), version_1_2_snapshot_t_201603081212 = Version(VERSION_1_2_SNAPSHOT_TIME_201603081212);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("testSpecialVersion", "[Version]")
|
|
||||||
{
|
|
||||||
REQUIRE("1.8.0" == static_cast<const std::string&>(Version("1.8.0")));
|
|
||||||
REQUIRE("1.8-alpha-snapshot" == static_cast<const std::string&>(Version("1.8-alpha-snapshot")));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("testNewerThan", "[Version]")
|
|
||||||
{
|
|
||||||
REQUIRE(version_1_2 > version_1);
|
|
||||||
REQUIRE(version_1_2 > version_1_0);
|
|
||||||
REQUIRE(version_1_2 > version_v1_0);
|
|
||||||
/*REQUIRE(version_1_2 > version_1_2_snapshot);
|
|
||||||
REQUIRE(version_1_2 > version_1_2_beta);
|
|
||||||
REQUIRE(version_1_2 > version_1_2_beta2);*/
|
|
||||||
REQUIRE(version_1_2_it > version_1);
|
|
||||||
REQUIRE(version_1_2_it > version_1_0);
|
|
||||||
REQUIRE(version_1_2_it > version_v1_0);
|
|
||||||
/*REQUIRE(version_1_2_it > version_1_2_snapshot);
|
|
||||||
REQUIRE(version_1_2_it > version_1_2_beta);
|
|
||||||
REQUIRE(version_1_2_it > version_1_2_beta2);
|
|
||||||
REQUIRE(version_1_2_snapshot > version_1);
|
|
||||||
REQUIRE(version_1_2_snapshot > version_1_0);
|
|
||||||
REQUIRE(version_1_2_snapshot > version_v1_0);
|
|
||||||
REQUIRE(version_1_2_snapshot > version_1_2_beta);
|
|
||||||
REQUIRE(version_1_2_snapshot > version_1_2_beta2);
|
|
||||||
REQUIRE(version_1_2_snapshot_it > version_1);
|
|
||||||
REQUIRE(version_1_2_snapshot_it > version_1_0);
|
|
||||||
REQUIRE(version_1_2_snapshot_it > version_v1_0);
|
|
||||||
REQUIRE(version_1_2_snapshot_it > version_1_2_snapshot);
|
|
||||||
REQUIRE(version_1_2_snapshot_it > version_1_2_beta);
|
|
||||||
REQUIRE(version_1_2_snapshot_it > version_1_2_beta2);
|
|
||||||
REQUIRE(version_1_2_beta > version_1);
|
|
||||||
REQUIRE(version_1_2_beta > version_1_0);
|
|
||||||
REQUIRE(version_1_2_beta > version_v1_0);
|
|
||||||
REQUIRE(version_1_2_beta2 > version_1);
|
|
||||||
REQUIRE(version_1_2_beta2 > version_1_0);
|
|
||||||
REQUIRE(version_1_2_beta2 > version_v1_0);
|
|
||||||
REQUIRE(version_1_2_beta2 > version_1_2_beta);
|
|
||||||
REQUIRE(version_2_0_snapshot > version_1_2);
|
|
||||||
REQUIRE(version_v2_0 > version_2_0_snapshot);
|
|
||||||
REQUIRE(version_1_2_snapshot_b_8 > version_1_2_snapshot_b_5);
|
|
||||||
REQUIRE(version_1_2_snapshot_t_201703081212 > version_1_2_snapshot_t_201603081212);*/
|
|
||||||
REQUIRE_FALSE(version_1 > version_1);
|
|
||||||
REQUIRE_FALSE(version_1 > version_1_0);
|
|
||||||
REQUIRE_FALSE(version_1 > version_v1_0);
|
|
||||||
REQUIRE_FALSE(version_1 > version_1_2);
|
|
||||||
REQUIRE_FALSE(version_1 > version_1_2_it);
|
|
||||||
REQUIRE_FALSE(version_1 > version_1_2_snapshot);
|
|
||||||
REQUIRE_FALSE(version_1 > version_1_2_snapshot_it);
|
|
||||||
REQUIRE_FALSE(version_1 > version_1_2_beta);
|
|
||||||
REQUIRE_FALSE(version_1 > version_1_2_beta2);
|
|
||||||
REQUIRE_FALSE(version_1 > version_v2_0);
|
|
||||||
REQUIRE_FALSE(version_1_0 > version_1);
|
|
||||||
REQUIRE_FALSE(version_1_0 > version_1_0);
|
|
||||||
REQUIRE_FALSE(version_1_0 > version_v1_0);
|
|
||||||
REQUIRE_FALSE(version_1_0 > version_1_2);
|
|
||||||
REQUIRE_FALSE(version_1_0 > version_1_2_it);
|
|
||||||
REQUIRE_FALSE(version_1_0 > version_1_2_snapshot);
|
|
||||||
REQUIRE_FALSE(version_1_0 > version_1_2_snapshot_it);
|
|
||||||
REQUIRE_FALSE(version_1_0 > version_1_2_beta);
|
|
||||||
REQUIRE_FALSE(version_1_0 > version_1_2_beta2);
|
|
||||||
REQUIRE_FALSE(version_1_0 > version_v2_0);
|
|
||||||
REQUIRE_FALSE(version_v1_0 > version_1_2);
|
|
||||||
REQUIRE_FALSE(version_v1_0 > version_1_2_it);
|
|
||||||
REQUIRE_FALSE(version_v1_0 > version_1_2_snapshot);
|
|
||||||
REQUIRE_FALSE(version_v1_0 > version_1_2_snapshot_it);
|
|
||||||
REQUIRE_FALSE(version_v1_0 > version_1);
|
|
||||||
REQUIRE_FALSE(version_v1_0 > version_1_0);
|
|
||||||
REQUIRE_FALSE(version_v1_0 > version_v1_0);
|
|
||||||
REQUIRE_FALSE(version_v1_0 > version_1_2_beta);
|
|
||||||
REQUIRE_FALSE(version_v1_0 > version_1_2_beta2);
|
|
||||||
REQUIRE_FALSE(version_v1_0 > version_v2_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot > version_1_2_snapshot);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot > version_1_2);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot > version_1_2_it);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot > version_1_2_snapshot_it);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot > version_v2_0);
|
|
||||||
REQUIRE_FALSE(version_1_2 > version_1_2);
|
|
||||||
REQUIRE_FALSE(version_1_2 > version_1_2_it);
|
|
||||||
REQUIRE_FALSE(version_1_2 > version_1_2_snapshot_it);
|
|
||||||
REQUIRE_FALSE(version_1_2 > version_v2_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_it > version_1_2);
|
|
||||||
REQUIRE_FALSE(version_1_2_it > version_1_2_it);
|
|
||||||
REQUIRE_FALSE(version_1_2_it > version_1_2_snapshot_it);
|
|
||||||
REQUIRE_FALSE(version_1_2_it > version_v2_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot_it > version_1_2);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot_it > version_1_2_it);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot_it > version_1_2_snapshot_it);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot_it > version_v2_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta > version_1_2_snapshot);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta > version_1_2);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta > version_1_2_it);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta > version_1_2_snapshot_it);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta > version_1_2_beta);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta > version_1_2_beta2);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta > version_v2_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta2 > version_1_2_snapshot);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta2 > version_1_2);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta2 > version_1_2_it);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta2 > version_1_2_snapshot_it);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta2 > version_1_2_beta2);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta2 > version_v2_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot_b_5 > version_1_2_snapshot);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot_t_201703081212 > version_1_2_snapshot);
|
|
||||||
REQUIRE_FALSE(version_2_0_snapshot > version_v2_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot > version_1_2_snapshot_b_5);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot_b_5 > version_1_2_snapshot_b_8);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot > version_1_2_snapshot_t_201703081212);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot_t_201603081212 > version_1_2_snapshot_t_201703081212);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("testNewerOrEqualThan", "[Version]")
|
|
||||||
{
|
|
||||||
REQUIRE(version_1 >= version_1);
|
|
||||||
REQUIRE(version_1 >= version_1_0);
|
|
||||||
REQUIRE(version_1 >= version_v1_0);
|
|
||||||
REQUIRE(version_1_0 >= version_1);
|
|
||||||
REQUIRE(version_1_0 >= version_1_0);
|
|
||||||
REQUIRE(version_1_0 >= version_v1_0);
|
|
||||||
REQUIRE(version_v1_0 >= version_1);
|
|
||||||
REQUIRE(version_v1_0 >= version_1_0);
|
|
||||||
REQUIRE(version_v1_0 >= version_v1_0);
|
|
||||||
REQUIRE(version_1_2 >= version_1);
|
|
||||||
REQUIRE(version_1_2 >= version_1_0);
|
|
||||||
REQUIRE(version_1_2 >= version_v1_0);
|
|
||||||
REQUIRE(version_1_2 >= version_1_2_snapshot);
|
|
||||||
REQUIRE(version_1_2 >= version_1_2);
|
|
||||||
REQUIRE(version_1_2 >= version_1_2_it);
|
|
||||||
REQUIRE(version_1_2 >= version_1_2_snapshot_it);
|
|
||||||
REQUIRE(version_1_2 >= version_1_2_beta);
|
|
||||||
REQUIRE(version_1_2 >= version_1_2_beta2);
|
|
||||||
REQUIRE(version_1_2_it >= version_1);
|
|
||||||
REQUIRE(version_1_2_it >= version_1_0);
|
|
||||||
REQUIRE(version_1_2_it >= version_v1_0);
|
|
||||||
REQUIRE(version_1_2_it >= version_1_2_snapshot);
|
|
||||||
REQUIRE(version_1_2_it >= version_1_2);
|
|
||||||
REQUIRE(version_1_2_it >= version_1_2_it);
|
|
||||||
REQUIRE(version_1_2_it >= version_1_2_snapshot_it);
|
|
||||||
REQUIRE(version_1_2_it >= version_1_2_beta);
|
|
||||||
REQUIRE(version_1_2_it >= version_1_2_beta2);
|
|
||||||
REQUIRE(version_1_2_snapshot >= version_1_2_snapshot);
|
|
||||||
REQUIRE(version_1_2_snapshot >= version_1);
|
|
||||||
REQUIRE(version_1_2_snapshot >= version_1_0);
|
|
||||||
REQUIRE(version_1_2_snapshot >= version_v1_0);
|
|
||||||
REQUIRE(version_1_2_snapshot >= version_1_2_beta);
|
|
||||||
REQUIRE(version_1_2_snapshot >= version_1_2_beta2);
|
|
||||||
REQUIRE(version_1_2_snapshot_it >= version_1_2);
|
|
||||||
REQUIRE(version_1_2_snapshot_it >= version_1_2_it);
|
|
||||||
REQUIRE(version_1_2_snapshot_it >= version_1_2_snapshot_it);
|
|
||||||
REQUIRE(version_1_2_snapshot_it >= version_1);
|
|
||||||
REQUIRE(version_1_2_snapshot_it >= version_1_0);
|
|
||||||
REQUIRE(version_1_2_snapshot_it >= version_v1_0);
|
|
||||||
REQUIRE(version_1_2_snapshot_it >= version_1_2_snapshot);
|
|
||||||
REQUIRE(version_1_2_snapshot_it >= version_1_2_beta);
|
|
||||||
REQUIRE(version_1_2_snapshot_it >= version_1_2_beta2);
|
|
||||||
REQUIRE(version_1_2_beta >= version_1);
|
|
||||||
REQUIRE(version_1_2_beta >= version_1_0);
|
|
||||||
REQUIRE(version_1_2_beta >= version_v1_0);
|
|
||||||
REQUIRE(version_1_2_beta >= version_1_2_beta);
|
|
||||||
REQUIRE(version_1_2_beta2 >= version_1);
|
|
||||||
REQUIRE(version_1_2_beta2 >= version_1_0);
|
|
||||||
REQUIRE(version_1_2_beta2 >= version_v1_0);
|
|
||||||
REQUIRE(version_1_2_beta2 >= version_1_2_beta);
|
|
||||||
REQUIRE(version_1_2_beta2 >= version_1_2_beta2);
|
|
||||||
REQUIRE(version_2_0_snapshot >= version_1_2);
|
|
||||||
REQUIRE(version_v2_0 >= version_1);
|
|
||||||
REQUIRE(version_v2_0 >= version_1_0);
|
|
||||||
REQUIRE(version_v2_0 >= version_v1_0);
|
|
||||||
REQUIRE(version_v2_0 >= version_1_2_snapshot);
|
|
||||||
REQUIRE(version_v2_0 >= version_1_2);
|
|
||||||
REQUIRE(version_v2_0 >= version_1_2_it);
|
|
||||||
REQUIRE(version_v2_0 >= version_1_2_snapshot_it);
|
|
||||||
REQUIRE(version_v2_0 >= version_1_2_beta);
|
|
||||||
REQUIRE(version_v2_0 >= version_1_2_beta2);
|
|
||||||
REQUIRE(version_v2_0 >= version_2_0_snapshot);
|
|
||||||
REQUIRE(version_v2_0 >= version_v2_0);
|
|
||||||
REQUIRE_FALSE(version_1 >= version_1_2);
|
|
||||||
REQUIRE_FALSE(version_1 >= version_1_2_it);
|
|
||||||
REQUIRE_FALSE(version_1 >= version_1_2_snapshot);
|
|
||||||
REQUIRE_FALSE(version_1 >= version_1_2_snapshot_it);
|
|
||||||
REQUIRE_FALSE(version_1 >= version_1_2_beta);
|
|
||||||
REQUIRE_FALSE(version_1 >= version_1_2_beta2);
|
|
||||||
REQUIRE_FALSE(version_1 >= version_v2_0);
|
|
||||||
REQUIRE_FALSE(version_1_0 >= version_1_2);
|
|
||||||
REQUIRE_FALSE(version_1_0 >= version_1_2_it);
|
|
||||||
REQUIRE_FALSE(version_1_0 >= version_1_2_snapshot);
|
|
||||||
REQUIRE_FALSE(version_1_0 >= version_1_2_snapshot_it);
|
|
||||||
REQUIRE_FALSE(version_1_0 >= version_1_2_beta);
|
|
||||||
REQUIRE_FALSE(version_1_0 >= version_1_2_beta2);
|
|
||||||
REQUIRE_FALSE(version_1_0 >= version_v2_0);
|
|
||||||
REQUIRE_FALSE(version_v1_0 >= version_1_2);
|
|
||||||
REQUIRE_FALSE(version_v1_0 >= version_1_2_it);
|
|
||||||
REQUIRE_FALSE(version_v1_0 >= version_1_2_snapshot);
|
|
||||||
REQUIRE_FALSE(version_v1_0 >= version_1_2_snapshot_it);
|
|
||||||
REQUIRE_FALSE(version_v1_0 >= version_1_2_beta);
|
|
||||||
REQUIRE_FALSE(version_v1_0 >= version_1_2_beta2);
|
|
||||||
REQUIRE_FALSE(version_v1_0 >= version_v2_0);
|
|
||||||
/*REQUIRE_FALSE(version_1_2_snapshot >= version_1_2);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot >= version_1_2_it);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot >= version_1_2_snapshot_it);*/
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot >= version_v2_0);
|
|
||||||
REQUIRE_FALSE(version_1_2 >= version_v2_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot_it >= version_v2_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_it >= version_v2_0);
|
|
||||||
/*REQUIRE_FALSE(version_1_2_beta >= version_1_2);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta >= version_1_2_beta2);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta >= version_1_2_it);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta >= version_1_2_snapshot);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta >= version_1_2_snapshot_it);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta >= version_v2_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta2 >= version_1_2);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta2 >= version_1_2_it);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta2 >= version_1_2_snapshot);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta2 >= version_1_2_snapshot_it);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta2 >= version_v2_0);
|
|
||||||
REQUIRE_FALSE(version_2_0_snapshot >= version_v2_0);*/
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("testOlderThan", "[Version]")
|
|
||||||
{
|
|
||||||
REQUIRE(version_1 < version_1_2);
|
|
||||||
REQUIRE(version_1 < version_1_2_it);
|
|
||||||
REQUIRE(version_1 < version_1_2_snapshot);
|
|
||||||
REQUIRE(version_1 < version_1_2_snapshot_it);
|
|
||||||
REQUIRE(version_1 < version_1_2_beta);
|
|
||||||
REQUIRE(version_1 < version_1_2_beta2);
|
|
||||||
REQUIRE(version_1 < version_v2_0);
|
|
||||||
REQUIRE(version_1_0 < version_1_2);
|
|
||||||
REQUIRE(version_1_0 < version_1_2_it);
|
|
||||||
REQUIRE(version_1_0 < version_1_2_snapshot);
|
|
||||||
REQUIRE(version_1_0 < version_1_2_snapshot_it);
|
|
||||||
REQUIRE(version_1_0 < version_1_2_beta);
|
|
||||||
REQUIRE(version_1_0 < version_1_2_beta2);
|
|
||||||
REQUIRE(version_1_0 < version_v2_0);
|
|
||||||
REQUIRE(version_v1_0 < version_1_2);
|
|
||||||
REQUIRE(version_v1_0 < version_1_2_it);
|
|
||||||
REQUIRE(version_v1_0 < version_1_2_snapshot);
|
|
||||||
REQUIRE(version_v1_0 < version_1_2_snapshot_it);
|
|
||||||
REQUIRE(version_v1_0 < version_1_2_beta);
|
|
||||||
REQUIRE(version_v1_0 < version_1_2_beta2);
|
|
||||||
REQUIRE(version_v1_0 < version_v2_0);
|
|
||||||
/*REQUIRE(version_1_2_snapshot < version_1_2);
|
|
||||||
REQUIRE(version_1_2_snapshot < version_1_2_it);
|
|
||||||
REQUIRE(version_1_2_snapshot < version_1_2_snapshot_it);*/
|
|
||||||
REQUIRE(version_1_2_snapshot < version_v2_0);
|
|
||||||
REQUIRE(version_1_2 < version_v2_0);
|
|
||||||
REQUIRE(version_1_2_snapshot_it < version_v2_0);
|
|
||||||
REQUIRE(version_1_2_it < version_v2_0);
|
|
||||||
/*REQUIRE(version_1_2_beta < version_1_2);
|
|
||||||
REQUIRE(version_1_2_beta < version_1_2_beta2);
|
|
||||||
REQUIRE(version_1_2_beta < version_1_2_it);
|
|
||||||
REQUIRE(version_1_2_beta < version_1_2_snapshot);
|
|
||||||
REQUIRE(version_1_2_beta < version_1_2_snapshot_it);
|
|
||||||
REQUIRE(version_1_2_beta < version_v2_0);
|
|
||||||
REQUIRE(version_1_2_beta2 < version_1_2);
|
|
||||||
REQUIRE(version_1_2_beta2 < version_1_2_it);
|
|
||||||
REQUIRE(version_1_2_beta2 < version_1_2_snapshot);
|
|
||||||
REQUIRE(version_1_2_beta2 < version_1_2_snapshot_it);*/
|
|
||||||
REQUIRE(version_1_2_beta2 < version_v2_0);
|
|
||||||
//REQUIRE(version_2_0_snapshot < version_v2_0);
|
|
||||||
REQUIRE_FALSE(version_1 < version_1);
|
|
||||||
REQUIRE_FALSE(version_1 < version_1_0);
|
|
||||||
REQUIRE_FALSE(version_1 < version_v1_0);
|
|
||||||
REQUIRE_FALSE(version_1_0 < version_1);
|
|
||||||
REQUIRE_FALSE(version_1_0 < version_1_0);
|
|
||||||
REQUIRE_FALSE(version_1_0 < version_v1_0);
|
|
||||||
REQUIRE_FALSE(version_v1_0 < version_1);
|
|
||||||
REQUIRE_FALSE(version_v1_0 < version_1_0);
|
|
||||||
REQUIRE_FALSE(version_v1_0 < version_v1_0);
|
|
||||||
REQUIRE_FALSE(version_1_2 < version_1);
|
|
||||||
REQUIRE_FALSE(version_1_2 < version_1_0);
|
|
||||||
REQUIRE_FALSE(version_1_2 < version_v1_0);
|
|
||||||
REQUIRE_FALSE(version_1_2 < version_1_2_snapshot);
|
|
||||||
REQUIRE_FALSE(version_1_2 < version_1_2);
|
|
||||||
REQUIRE_FALSE(version_1_2 < version_1_2_it);
|
|
||||||
REQUIRE_FALSE(version_1_2 < version_1_2_snapshot_it);
|
|
||||||
REQUIRE_FALSE(version_1_2 < version_1_2_beta);
|
|
||||||
REQUIRE_FALSE(version_1_2 < version_1_2_beta2);
|
|
||||||
REQUIRE_FALSE(version_1_2_it < version_1);
|
|
||||||
REQUIRE_FALSE(version_1_2_it < version_1_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_it < version_v1_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_it < version_1_2_snapshot);
|
|
||||||
REQUIRE_FALSE(version_1_2_it < version_1_2);
|
|
||||||
REQUIRE_FALSE(version_1_2_it < version_1_2_it);
|
|
||||||
REQUIRE_FALSE(version_1_2_it < version_1_2_snapshot_it);
|
|
||||||
REQUIRE_FALSE(version_1_2_it < version_1_2_beta);
|
|
||||||
REQUIRE_FALSE(version_1_2_it < version_1_2_beta2);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot < version_1_2_snapshot);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot < version_1);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot < version_1_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot < version_v1_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot < version_1_2_beta);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot < version_1_2_beta2);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot_it < version_1_2);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot_it < version_1_2_it);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot_it < version_1_2_snapshot_it);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot_it < version_1);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot_it < version_1_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot_it < version_v1_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot_it < version_1_2_snapshot);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot_it < version_1_2_beta);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot_it < version_1_2_beta2);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta < version_1);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta < version_1_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta < version_v1_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta < version_1_2_beta);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta2 < version_1);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta2 < version_1_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta2 < version_v1_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta2 < version_1_2_beta);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta2 < version_1_2_beta2);
|
|
||||||
REQUIRE_FALSE(version_2_0_snapshot < version_1_2);
|
|
||||||
REQUIRE_FALSE(version_v2_0 < version_1);
|
|
||||||
REQUIRE_FALSE(version_v2_0 < version_1_0);
|
|
||||||
REQUIRE_FALSE(version_v2_0 < version_v1_0);
|
|
||||||
REQUIRE_FALSE(version_v2_0 < version_1_2_snapshot);
|
|
||||||
REQUIRE_FALSE(version_v2_0 < version_1_2);
|
|
||||||
REQUIRE_FALSE(version_v2_0 < version_1_2_it);
|
|
||||||
REQUIRE_FALSE(version_v2_0 < version_1_2_snapshot_it);
|
|
||||||
REQUIRE_FALSE(version_v2_0 < version_1_2_beta);
|
|
||||||
REQUIRE_FALSE(version_v2_0 < version_1_2_beta2);
|
|
||||||
REQUIRE_FALSE(version_v2_0 < version_v2_0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("testOlderOrEqualThan", "[Version]")
|
|
||||||
{
|
|
||||||
REQUIRE(version_1 <= version_1);
|
|
||||||
REQUIRE(version_1 <= version_1_0);
|
|
||||||
REQUIRE(version_1 <= version_v1_0);
|
|
||||||
REQUIRE(version_1 <= version_1_2);
|
|
||||||
REQUIRE(version_1 <= version_1_2_it);
|
|
||||||
REQUIRE(version_1 <= version_1_2_snapshot);
|
|
||||||
REQUIRE(version_1 <= version_1_2_snapshot_it);
|
|
||||||
REQUIRE(version_1 <= version_1_2_beta);
|
|
||||||
REQUIRE(version_1 <= version_1_2_beta2);
|
|
||||||
REQUIRE(version_1 <= version_v2_0);
|
|
||||||
REQUIRE(version_1_0 <= version_1);
|
|
||||||
REQUIRE(version_1_0 <= version_1_0);
|
|
||||||
REQUIRE(version_1_0 <= version_v1_0);
|
|
||||||
REQUIRE(version_1_0 <= version_1_2);
|
|
||||||
REQUIRE(version_1_0 <= version_1_2_it);
|
|
||||||
REQUIRE(version_1_0 <= version_1_2_snapshot);
|
|
||||||
REQUIRE(version_1_0 <= version_1_2_snapshot_it);
|
|
||||||
REQUIRE(version_1_0 <= version_1_2_beta);
|
|
||||||
REQUIRE(version_1_0 <= version_1_2_beta2);
|
|
||||||
REQUIRE(version_1_0 <= version_v2_0);
|
|
||||||
REQUIRE(version_v1_0 <= version_1_2);
|
|
||||||
REQUIRE(version_v1_0 <= version_1_2_it);
|
|
||||||
REQUIRE(version_v1_0 <= version_1_2_snapshot);
|
|
||||||
REQUIRE(version_v1_0 <= version_1_2_snapshot_it);
|
|
||||||
REQUIRE(version_v1_0 <= version_1);
|
|
||||||
REQUIRE(version_v1_0 <= version_1_0);
|
|
||||||
REQUIRE(version_v1_0 <= version_v1_0);
|
|
||||||
REQUIRE(version_v1_0 <= version_1_2_beta);
|
|
||||||
REQUIRE(version_v1_0 <= version_1_2_beta2);
|
|
||||||
REQUIRE(version_v1_0 <= version_v2_0);
|
|
||||||
REQUIRE(version_1_2_snapshot <= version_1_2_snapshot);
|
|
||||||
REQUIRE(version_1_2_snapshot <= version_1_2);
|
|
||||||
REQUIRE(version_1_2_snapshot <= version_1_2_it);
|
|
||||||
REQUIRE(version_1_2_snapshot <= version_1_2_snapshot_it);
|
|
||||||
REQUIRE(version_1_2_snapshot <= version_v2_0);
|
|
||||||
REQUIRE(version_1_2 <= version_1_2);
|
|
||||||
REQUIRE(version_1_2 <= version_1_2_it);
|
|
||||||
REQUIRE(version_1_2 <= version_1_2_snapshot_it);
|
|
||||||
REQUIRE(version_1_2 <= version_v2_0);
|
|
||||||
REQUIRE(version_1_2_it <= version_1_2);
|
|
||||||
REQUIRE(version_1_2_it <= version_1_2_it);
|
|
||||||
REQUIRE(version_1_2_it <= version_1_2_snapshot_it);
|
|
||||||
REQUIRE(version_1_2_it <= version_v2_0);
|
|
||||||
REQUIRE(version_1_2_snapshot_it <= version_1_2);
|
|
||||||
REQUIRE(version_1_2_snapshot_it <= version_1_2_it);
|
|
||||||
REQUIRE(version_1_2_snapshot_it <= version_1_2_snapshot_it);
|
|
||||||
REQUIRE(version_1_2_snapshot_it <= version_v2_0);
|
|
||||||
REQUIRE(version_1_2_beta <= version_1_2_snapshot);
|
|
||||||
REQUIRE(version_1_2_beta <= version_1_2);
|
|
||||||
REQUIRE(version_1_2_beta <= version_1_2_it);
|
|
||||||
REQUIRE(version_1_2_beta <= version_1_2_snapshot_it);
|
|
||||||
REQUIRE(version_1_2_beta <= version_1_2_beta);
|
|
||||||
REQUIRE(version_1_2_beta <= version_1_2_beta2);
|
|
||||||
REQUIRE(version_1_2_beta <= version_v2_0);
|
|
||||||
REQUIRE(version_1_2_beta2 <= version_1_2_snapshot);
|
|
||||||
REQUIRE(version_1_2_beta2 <= version_1_2);
|
|
||||||
REQUIRE(version_1_2_beta2 <= version_1_2_it);
|
|
||||||
REQUIRE(version_1_2_beta2 <= version_1_2_snapshot_it);
|
|
||||||
REQUIRE(version_1_2_beta2 <= version_1_2_beta2);
|
|
||||||
REQUIRE(version_1_2_beta2 <= version_v2_0);
|
|
||||||
REQUIRE(version_2_0_snapshot <= version_v2_0);
|
|
||||||
REQUIRE_FALSE(version_1_2 <= version_1);
|
|
||||||
REQUIRE_FALSE(version_1_2 <= version_1_0);
|
|
||||||
REQUIRE_FALSE(version_1_2 <= version_v1_0);
|
|
||||||
/*REQUIRE_FALSE(version_1_2 <= version_1_2_snapshot);
|
|
||||||
REQUIRE_FALSE(version_1_2 <= version_1_2_beta);
|
|
||||||
REQUIRE_FALSE(version_1_2 <= version_1_2_beta2);*/
|
|
||||||
REQUIRE_FALSE(version_1_2_it <= version_1);
|
|
||||||
REQUIRE_FALSE(version_1_2_it <= version_1_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_it <= version_v1_0);
|
|
||||||
/*REQUIRE_FALSE(version_1_2_it <= version_1_2_snapshot);
|
|
||||||
REQUIRE_FALSE(version_1_2_it <= version_1_2_beta);
|
|
||||||
REQUIRE_FALSE(version_1_2_it <= version_1_2_beta2);*/
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot <= version_1);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot <= version_1_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot <= version_v1_0);
|
|
||||||
/*REQUIRE_FALSE(version_1_2_snapshot <= version_1_2_beta);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot <= version_1_2_beta2);*/
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot_it <= version_1);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot_it <= version_1_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot_it <= version_v1_0);
|
|
||||||
/*REQUIRE_FALSE(version_1_2_snapshot_it <= version_1_2_snapshot);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot_it <= version_1_2_beta);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot_it <= version_1_2_beta2);*/
|
|
||||||
REQUIRE_FALSE(version_1_2_beta <= version_1);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta <= version_1_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta <= version_v1_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta2 <= version_1);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta2 <= version_1_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta2 <= version_v1_0);
|
|
||||||
//REQUIRE_FALSE(version_1_2_beta2 <= version_1_2_beta);
|
|
||||||
REQUIRE_FALSE(version_2_0_snapshot <= version_1_2);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("testEquals", "[Version]")
|
|
||||||
{
|
|
||||||
REQUIRE(version_1 == version_1_0);
|
|
||||||
REQUIRE(version_1 == version_v1_0);
|
|
||||||
REQUIRE(version_1_0 == version_1);
|
|
||||||
REQUIRE(version_1_0 == version_v1_0);
|
|
||||||
REQUIRE(version_v1_0 == version_1);
|
|
||||||
REQUIRE(version_v1_0 == version_1_0);
|
|
||||||
REQUIRE(version_1_2 == version_1_2_it);
|
|
||||||
REQUIRE(version_1_2 == version_1_2_snapshot_it);
|
|
||||||
REQUIRE(version_1_2_it == version_1_2);
|
|
||||||
REQUIRE(version_1_2_it == version_1_2_snapshot_it);
|
|
||||||
REQUIRE(version_1_2_snapshot_it == version_1_2);
|
|
||||||
REQUIRE(version_1_2_snapshot_it == version_1_2_it);
|
|
||||||
REQUIRE_FALSE(version_1 == version_1_2);
|
|
||||||
REQUIRE_FALSE(version_1 == version_1_2_it);
|
|
||||||
REQUIRE_FALSE(version_1 == version_1_2_snapshot);
|
|
||||||
REQUIRE_FALSE(version_1 == version_1_2_snapshot_it);
|
|
||||||
REQUIRE_FALSE(version_1 == version_1_2_beta);
|
|
||||||
REQUIRE_FALSE(version_1 == version_1_2_beta2);
|
|
||||||
REQUIRE_FALSE(version_1 == version_v2_0);
|
|
||||||
REQUIRE_FALSE(version_1_0 == version_1_2);
|
|
||||||
REQUIRE_FALSE(version_1_0 == version_1_2_it);
|
|
||||||
REQUIRE_FALSE(version_1_0 == version_1_2_snapshot);
|
|
||||||
REQUIRE_FALSE(version_1_0 == version_1_2_snapshot_it);
|
|
||||||
REQUIRE_FALSE(version_1_0 == version_1_2_beta);
|
|
||||||
REQUIRE_FALSE(version_1_0 == version_1_2_beta2);
|
|
||||||
REQUIRE_FALSE(version_1_0 == version_v2_0);
|
|
||||||
REQUIRE_FALSE(version_v1_0 == version_1_2);
|
|
||||||
REQUIRE_FALSE(version_v1_0 == version_1_2_it);
|
|
||||||
REQUIRE_FALSE(version_v1_0 == version_1_2_snapshot);
|
|
||||||
REQUIRE_FALSE(version_v1_0 == version_1_2_snapshot_it);
|
|
||||||
REQUIRE_FALSE(version_v1_0 == version_1_2_beta);
|
|
||||||
REQUIRE_FALSE(version_v1_0 == version_1_2_beta2);
|
|
||||||
REQUIRE_FALSE(version_v1_0 == version_v2_0);
|
|
||||||
REQUIRE_FALSE(version_1_2 == version_1);
|
|
||||||
REQUIRE_FALSE(version_1_2 == version_1_0);
|
|
||||||
REQUIRE_FALSE(version_1_2 == version_v1_0);
|
|
||||||
/*REQUIRE_FALSE(version_1_2 == version_1_2_snapshot);
|
|
||||||
REQUIRE_FALSE(version_1_2 == version_1_2_beta);
|
|
||||||
REQUIRE_FALSE(version_1_2 == version_1_2_beta2);*/
|
|
||||||
REQUIRE_FALSE(version_1_2 == version_v2_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_it == version_1);
|
|
||||||
REQUIRE_FALSE(version_1_2_it == version_1_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_it == version_v1_0);
|
|
||||||
/*REQUIRE_FALSE(version_1_2_it == version_1_2_snapshot);
|
|
||||||
REQUIRE_FALSE(version_1_2_it == version_1_2_beta);
|
|
||||||
REQUIRE_FALSE(version_1_2_it == version_1_2_beta2);*/
|
|
||||||
REQUIRE_FALSE(version_1_2_it == version_v2_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot == version_1);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot == version_1_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot == version_v1_0);
|
|
||||||
/*REQUIRE_FALSE(version_1_2_snapshot == version_1_2);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot == version_1_2_it);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot == version_1_2_snapshot_it);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot == version_1_2_beta);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot == version_1_2_beta2);*/
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot == version_v2_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot_it == version_1);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot_it == version_1_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot_it == version_v1_0);
|
|
||||||
/*REQUIRE_FALSE(version_1_2_snapshot_it == version_1_2_snapshot);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot_it == version_1_2_beta);
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot_it == version_1_2_beta2);*/
|
|
||||||
REQUIRE_FALSE(version_1_2_snapshot_it == version_v2_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta == version_v2_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta2 == version_v2_0);
|
|
||||||
REQUIRE_FALSE(version_1_2_beta2 == version_2_0_snapshot);
|
|
||||||
//REQUIRE_FALSE(version_v2_0 == version_2_0_snapshot);
|
|
||||||
REQUIRE(version_1 == Version(VERSION_1));
|
|
||||||
REQUIRE(version_1_0 == Version(VERSION_1_0));
|
|
||||||
REQUIRE(version_1 == Version(VERSION_1_0));
|
|
||||||
REQUIRE(version_v1_0 == Version(VERSION_V1_0));
|
|
||||||
REQUIRE(version_1_2 == Version(VERSION_1_2));
|
|
||||||
REQUIRE(version_1_2_snapshot == Version(VERSION_1_2_SNAPSHOT));
|
|
||||||
REQUIRE(version_1_2_beta == Version(VERSION_1_2_BETA));
|
|
||||||
REQUIRE(version_1_2_beta2 == Version(VERSION_1_2_BETA2));
|
|
||||||
REQUIRE(version_v2_0 == Version(VERSION_V2_0));
|
|
||||||
REQUIRE(version_1_2_it == Version(VERSION_1_2));
|
|
||||||
//REQUIRE_FALSE(version_1_2_snapshot_it == Version(VERSION_1_2_SNAPSHOT));
|
|
||||||
REQUIRE(version_1 == Version(VERSION_1, true));
|
|
||||||
REQUIRE(version_1_0 == Version(VERSION_1_0, true));
|
|
||||||
REQUIRE(version_v1_0 == Version(VERSION_V1_0, true));
|
|
||||||
REQUIRE(version_1_2 == Version(VERSION_1_2, true));
|
|
||||||
//REQUIRE_FALSE(version_1_2_snapshot == Version(VERSION_1_2_SNAPSHOT, true));
|
|
||||||
REQUIRE(version_1_2_it == Version(VERSION_1_2, true));
|
|
||||||
REQUIRE(version_1_2_snapshot_it == Version(VERSION_1_2_SNAPSHOT, true));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("testToString", "[Version]")
|
|
||||||
{
|
|
||||||
REQUIRE(VERSION_1 == static_cast<const std::string&>(version_1));
|
|
||||||
REQUIRE(VERSION_1_0 == static_cast<const std::string&>(version_1_0));
|
|
||||||
REQUIRE(VERSION_V1_0 == static_cast<const std::string&>(version_v1_0));
|
|
||||||
REQUIRE(VERSION_1_2 == static_cast<const std::string&>(version_1_2));
|
|
||||||
REQUIRE(VERSION_1_2 == static_cast<const std::string&>(version_1_2_it));
|
|
||||||
REQUIRE(VERSION_1_2_SNAPSHOT == static_cast<const std::string&>(version_1_2_snapshot));
|
|
||||||
REQUIRE(VERSION_1_2_SNAPSHOT == static_cast<const std::string&>(version_1_2_snapshot_it));
|
|
||||||
REQUIRE(VERSION_1_2_BETA == static_cast<const std::string&>(version_1_2_beta));
|
|
||||||
REQUIRE(VERSION_1_2_BETA2 == static_cast<const std::string&>(version_1_2_beta2));
|
|
||||||
REQUIRE("v2.0" == static_cast<const std::string&>(version_v2_0));
|
|
||||||
REQUIRE(VERSION_2_0_SNAPSHOT == static_cast<const std::string&>(version_2_0_snapshot));
|
|
||||||
REQUIRE_FALSE(VERSION_1_0 == static_cast<const std::string&>(version_v1_0));
|
|
||||||
REQUIRE_FALSE(VERSION_1_0 == static_cast<const std::string&>(version_1));
|
|
||||||
REQUIRE_FALSE(VERSION_1_0 == static_cast<const std::string&>(version_1_2));
|
|
||||||
REQUIRE_FALSE("2.0" == static_cast<const std::string&>(version_v2_0));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("testUnimportantVersionParts", "[Version]")
|
|
||||||
{
|
|
||||||
REQUIRE(Version("1.0.0.3") == Version("1.0.0.3.0"));
|
|
||||||
REQUIRE(Version("1.0.0.3") == Version("1.0.0.3.0.0"));
|
|
||||||
REQUIRE(Version("1.0.0.3") == Version("1.0.0.3.0.0.0"));
|
|
||||||
REQUIRE(Version("1.0.0.3") == Version("1.0.0.3.0.00.0"));
|
|
||||||
REQUIRE(Version("1.0.0.3") == Version("1.00.0.3"));
|
|
||||||
}
|
|
||||||
@@ -1,240 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 <vector>
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
#include "Data/Containers/Array.hpp"
|
|
||||||
|
|
||||||
class NonTrivial
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static int destructorCount;
|
|
||||||
|
|
||||||
NonTrivial() = default;
|
|
||||||
~NonTrivial() { destructorCount++; }
|
|
||||||
};
|
|
||||||
|
|
||||||
int NonTrivial::destructorCount = 0;
|
|
||||||
|
|
||||||
using namespace OpenVulkano;
|
|
||||||
|
|
||||||
TEST_CASE("Default constructor", "[Array]")
|
|
||||||
{
|
|
||||||
Array<int> array;
|
|
||||||
REQUIRE(array.Size() == 0);
|
|
||||||
REQUIRE(array.Empty());
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("Constructor with size", "[Array]")
|
|
||||||
{
|
|
||||||
Array<int> array(5);
|
|
||||||
REQUIRE(array.Size() == 5);
|
|
||||||
|
|
||||||
Array<int> arr(5, 42);
|
|
||||||
REQUIRE(arr.Size() == 5);
|
|
||||||
for (size_t i = 0; i < arr.Size(); ++i)
|
|
||||||
{
|
|
||||||
REQUIRE(arr[i] == 42);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("Constructor with initializer list", "[Array]")
|
|
||||||
{
|
|
||||||
Array<int> array { 1, 2, 3 };
|
|
||||||
REQUIRE(array.Size() == 3);
|
|
||||||
REQUIRE(array[0] == 1);
|
|
||||||
REQUIRE(array[1] == 2);
|
|
||||||
REQUIRE(array[2] == 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("Copy constructor", "[Array]")
|
|
||||||
{
|
|
||||||
Array<int> array1 { 1, 2, 3 };
|
|
||||||
Array<int> array2(array1);
|
|
||||||
REQUIRE(array2.Size() == 3);
|
|
||||||
REQUIRE(array2 == array1);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("Move constructor", "[Array]")
|
|
||||||
{
|
|
||||||
Array<int> array1 { 1, 2, 3 };
|
|
||||||
Array<int> array2(std::move(array1));
|
|
||||||
REQUIRE(array2.Size() == 3);
|
|
||||||
REQUIRE(array1.Size() == 0);
|
|
||||||
REQUIRE(array1.Empty());
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("Constructor from std::vector", "[Array]")
|
|
||||||
{
|
|
||||||
std::vector<int> vec { 4, 5, 6 };
|
|
||||||
Array<int> array(vec);
|
|
||||||
REQUIRE(array.Size() == 3);
|
|
||||||
REQUIRE(array[0] == 4);
|
|
||||||
REQUIRE(array[1] == 5);
|
|
||||||
REQUIRE(array[2] == 6);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("Constructor with default value", "[Array]")
|
|
||||||
{
|
|
||||||
Array<int> array(3, 7);
|
|
||||||
REQUIRE(array.Size() == 3);
|
|
||||||
for (size_t i = 0; i < 3; ++i)
|
|
||||||
{
|
|
||||||
REQUIRE(array[i] == 7);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("Resize method", "[Array]")
|
|
||||||
{
|
|
||||||
Array<int> array { 1, 2, 3 };
|
|
||||||
array = { 4, 5 };
|
|
||||||
REQUIRE(array.Size() == 2);
|
|
||||||
REQUIRE(array[0] == 4);
|
|
||||||
REQUIRE(array[1] == 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("Destructor for non-trivially destructible types", "[Array]")
|
|
||||||
{
|
|
||||||
{
|
|
||||||
NonTrivial::destructorCount = 0;
|
|
||||||
Array<NonTrivial> array(3);
|
|
||||||
}
|
|
||||||
REQUIRE(NonTrivial::destructorCount == 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("At() method with bounds checking", "[Array]")
|
|
||||||
{
|
|
||||||
Array<int> array { 1, 2, 3 };
|
|
||||||
REQUIRE(array.At(1) == 2);
|
|
||||||
REQUIRE_THROWS_AS(array.At(5), std::out_of_range);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("Assignment operator", "[Array]")
|
|
||||||
{
|
|
||||||
Array<int> array1 { 1, 2, 3 };
|
|
||||||
Array<int> array2;
|
|
||||||
array2 = array1;
|
|
||||||
REQUIRE(array2 == array1);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("Move assignment operator", "[Array]")
|
|
||||||
{
|
|
||||||
Array<int> array1 { 1, 2, 3 };
|
|
||||||
Array<int> array2;
|
|
||||||
array2 = std::move(array1);
|
|
||||||
REQUIRE(array2.Size() == 3);
|
|
||||||
REQUIRE(array1.Size() == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("Comparison operators", "[Array]")
|
|
||||||
{
|
|
||||||
Array<int> array1 { 1, 2, 3 };
|
|
||||||
Array<int> array2 { 1, 2, 3 };
|
|
||||||
Array<int> array3 { 4, 5, 6 };
|
|
||||||
|
|
||||||
REQUIRE(array1 == array2);
|
|
||||||
REQUIRE(array1 != array3);
|
|
||||||
REQUIRE(array1 < array3);
|
|
||||||
REQUIRE(array3 > array1);
|
|
||||||
REQUIRE(array1 <= array2);
|
|
||||||
REQUIRE(array1 >= array2);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("Fill method", "[Array]")
|
|
||||||
{
|
|
||||||
Array<int> array(5);
|
|
||||||
array.Fill(42);
|
|
||||||
for (size_t i = 0; i < 5; ++i)
|
|
||||||
{
|
|
||||||
REQUIRE(array[i] == 42);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("Front and Back methods", "[Array]")
|
|
||||||
{
|
|
||||||
Array<int> array { 1, 2, 3 };
|
|
||||||
REQUIRE(array.Front() == 1);
|
|
||||||
REQUIRE(array.Back() == 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("Iterators", "[Array]")
|
|
||||||
{
|
|
||||||
Array<int> array { 1, 2, 3 };
|
|
||||||
int sum = 0;
|
|
||||||
for (auto it = array.Begin(); it != array.End(); ++it)
|
|
||||||
{
|
|
||||||
sum += *it;
|
|
||||||
}
|
|
||||||
REQUIRE(sum == 6);
|
|
||||||
|
|
||||||
sum = 0;
|
|
||||||
for (auto it = array.ReverseBegin(); it != array.ReverseEnd(); ++it)
|
|
||||||
{
|
|
||||||
sum += *it;
|
|
||||||
}
|
|
||||||
REQUIRE(sum == 6);
|
|
||||||
|
|
||||||
Array<int> arr = { 1, 2, 3, 4, 5 };
|
|
||||||
{
|
|
||||||
int sum = 0;
|
|
||||||
for (auto it = arr.Begin(); it != arr.End(); ++it)
|
|
||||||
{
|
|
||||||
sum += *it;
|
|
||||||
}
|
|
||||||
REQUIRE(sum == 15);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
std::vector<int> reversedElements;
|
|
||||||
for (auto it = arr.ReverseBegin(); it != arr.ReverseEnd(); ++it)
|
|
||||||
{
|
|
||||||
reversedElements.push_back(*it);
|
|
||||||
}
|
|
||||||
REQUIRE(reversedElements == std::vector<int>({ 5, 4, 3, 2, 1 }));
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
const Array<int> constArr = { 1, 2, 3, 4, 5 };
|
|
||||||
int sum = 0;
|
|
||||||
for (auto it = constArr.Begin(); it != constArr.End(); ++it)
|
|
||||||
{
|
|
||||||
sum += *it;
|
|
||||||
}
|
|
||||||
REQUIRE(sum == 15);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
const Array<int> constArr = { 1, 2, 3, 4, 5 };
|
|
||||||
std::vector<int> reversedElements;
|
|
||||||
for (auto it = constArr.ReverseBegin(); it != constArr.ReverseEnd(); ++it)
|
|
||||||
{
|
|
||||||
reversedElements.push_back(*it);
|
|
||||||
}
|
|
||||||
REQUIRE(reversedElements == std::vector<int>({ 5, 4, 3, 2, 1 }));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("Data method", "[Array]")
|
|
||||||
{
|
|
||||||
Array<int> array { 1, 2, 3 };
|
|
||||||
int* data = array.Data();
|
|
||||||
REQUIRE(data[0] == 1);
|
|
||||||
REQUIRE(data[1] == 2);
|
|
||||||
REQUIRE(data[2] == 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE("Swap method", "[Array]")
|
|
||||||
{
|
|
||||||
Array<int> arr1 = { 1, 2, 3 };
|
|
||||||
Array<int> arr2 = { 4, 5, 6 };
|
|
||||||
arr1.Swap(arr2);
|
|
||||||
REQUIRE(arr1[0] == 4);
|
|
||||||
REQUIRE(arr2[0] == 1);
|
|
||||||
}
|
|
||||||
@@ -1,141 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 <vector>
|
|
||||||
#include <map>
|
|
||||||
#include <utility>
|
|
||||||
#include <type_traits>
|
|
||||||
|
|
||||||
#include "Data/Containers/BinSearchArrayMap.hpp"
|
|
||||||
#include "Data/Containers/StableVector.hpp"
|
|
||||||
|
|
||||||
using namespace OpenVulkano;
|
|
||||||
|
|
||||||
TEST_CASE("BinSearchArrayMap With Default")
|
|
||||||
{
|
|
||||||
SECTION("Insert")
|
|
||||||
{
|
|
||||||
BinSearchArrayMap<int, std::string> map;
|
|
||||||
|
|
||||||
for (int i = 0; i < 50; i++)
|
|
||||||
{
|
|
||||||
map.Insert(i, std::to_string(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
REQUIRE(map.Size() == 50);
|
|
||||||
REQUIRE(map.Get(16) == "16");
|
|
||||||
REQUIRE(map.Get(23) == "23");
|
|
||||||
REQUIRE(map.Get(48) == "48");
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("Remove")
|
|
||||||
{
|
|
||||||
BinSearchArrayMap<int, std::string> map;
|
|
||||||
|
|
||||||
for (int i = 0; i < 50; i++)
|
|
||||||
{
|
|
||||||
map.Insert(i, std::to_string(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
map.Remove(16);
|
|
||||||
map.Remove(23);
|
|
||||||
map.Remove(48);
|
|
||||||
|
|
||||||
REQUIRE(map.Size() == 47);
|
|
||||||
|
|
||||||
for (int i = 0; i < 50; i++)
|
|
||||||
{
|
|
||||||
if (i == 16 || i == 23 || i == 48)
|
|
||||||
{
|
|
||||||
REQUIRE(!map.Contains(i));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
REQUIRE(map.Get(i) == std::to_string(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("Emplace")
|
|
||||||
{
|
|
||||||
BinSearchArrayMap<int, std::string> map;
|
|
||||||
|
|
||||||
for (int i = 0; i < 50; i++)
|
|
||||||
{
|
|
||||||
map.Emplace(i, std::to_string(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
REQUIRE(map.Size() == 50);
|
|
||||||
REQUIRE(map.Get(16) == "16");
|
|
||||||
REQUIRE(map.Get(23) == "23");
|
|
||||||
REQUIRE(map.Get(48) == "48");
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("FindPair")
|
|
||||||
{
|
|
||||||
BinSearchArrayMap<int, std::string> map;
|
|
||||||
|
|
||||||
for (int i = 0; i < 50; i++)
|
|
||||||
{
|
|
||||||
map.Insert(i, std::to_string(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
auto pair = map.FindPair(16);
|
|
||||||
REQUIRE(pair.first == 16);
|
|
||||||
REQUIRE(pair.second == "16");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("BinSearchArrayMap With StableVector")
|
|
||||||
{
|
|
||||||
SECTION("Insert")
|
|
||||||
{
|
|
||||||
BinSearchArrayMap<int, std::string, std::pair, StableVector> map;
|
|
||||||
|
|
||||||
for (int i = 0; i < 50; i++)
|
|
||||||
{
|
|
||||||
map.Insert(i, std::to_string(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
REQUIRE(map.Size() == 50);
|
|
||||||
REQUIRE(map.Get(16) == "16");
|
|
||||||
REQUIRE(map.Get(23) == "23");
|
|
||||||
REQUIRE(map.Get(48) == "48");
|
|
||||||
|
|
||||||
for (int i = 0; i < 50; i++)
|
|
||||||
{
|
|
||||||
REQUIRE(map.Get(i) == std::to_string(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("Remove")
|
|
||||||
{
|
|
||||||
BinSearchArrayMap<int, std::string, std::pair, StableVector> map;
|
|
||||||
|
|
||||||
for (int i = 0; i < 50; i++)
|
|
||||||
{
|
|
||||||
map.Insert(i, std::to_string(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
map.Remove(16);
|
|
||||||
map.Remove(23);
|
|
||||||
map.Remove(48);
|
|
||||||
|
|
||||||
for (int i = 0; i < 50; i++)
|
|
||||||
{
|
|
||||||
if (i == 16 || i == 23 || i == 48)
|
|
||||||
{
|
|
||||||
REQUIRE(!map.Contains(i));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
REQUIRE(map.Get(i) == std::to_string(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,192 +0,0 @@
|
|||||||
#include <catch2/catch_all.hpp>
|
|
||||||
|
|
||||||
#include "Data/Containers/StableVector.hpp"
|
|
||||||
|
|
||||||
using namespace OpenVulkano;
|
|
||||||
|
|
||||||
struct Test
|
|
||||||
{
|
|
||||||
uint32_t mValue;
|
|
||||||
Test(uint32_t value) : mValue(value) {}
|
|
||||||
Test() : mValue(0) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
static int incrementCounter = 0;
|
|
||||||
static int decrementCounter = 0;
|
|
||||||
|
|
||||||
struct TestCount
|
|
||||||
{
|
|
||||||
TestCount() : m_value("") { ++incrementCounter; }
|
|
||||||
TestCount(const std::string& val) : m_value(val) { ++incrementCounter; }
|
|
||||||
TestCount(TestCount&& other) noexcept : m_value(std::move(other.m_value)) { ++incrementCounter; }
|
|
||||||
TestCount(const TestCount& other) : m_value(other.m_value) { ++incrementCounter; }
|
|
||||||
|
|
||||||
TestCount& operator=(const TestCount& other)
|
|
||||||
{
|
|
||||||
m_value = other.m_value;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
TestCount& operator=(TestCount&& other) noexcept
|
|
||||||
{
|
|
||||||
m_value = std::move(other.m_value);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
~TestCount() { ++decrementCounter; }
|
|
||||||
|
|
||||||
std::string m_value;
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_CASE("ChunkVector")
|
|
||||||
{
|
|
||||||
SECTION("PushBack")
|
|
||||||
{
|
|
||||||
StableVector<uint32_t> vec;
|
|
||||||
|
|
||||||
REQUIRE(vec.Size() == 0);
|
|
||||||
REQUIRE(vec.Capacity() == 32);
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < 100; ++i)
|
|
||||||
{
|
|
||||||
vec.PushBack(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
REQUIRE(vec.Size() == 100);
|
|
||||||
REQUIRE(vec.Capacity() == 224); // 32 + 64 + 128 = 3 | previous chunk size multiplied by 2
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("EmplaceBack")
|
|
||||||
{
|
|
||||||
StableVector<Test> vec;
|
|
||||||
|
|
||||||
REQUIRE(vec.Size() == 0);
|
|
||||||
REQUIRE(vec.Capacity() == 32);
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < 100; ++i)
|
|
||||||
{
|
|
||||||
vec.EmplaceBack(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
REQUIRE(vec.Size() == 100);
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < 100; ++i)
|
|
||||||
{
|
|
||||||
REQUIRE(vec[i].mValue == i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("PopBack")
|
|
||||||
{
|
|
||||||
StableVector<uint32_t> vec;
|
|
||||||
|
|
||||||
REQUIRE(vec.Size() == 0);
|
|
||||||
REQUIRE(vec.Capacity() == 32);
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < 100; ++i)
|
|
||||||
{
|
|
||||||
vec.PushBack(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
REQUIRE(vec.Size() == 100);
|
|
||||||
|
|
||||||
uint64_t tempVal = vec.Capacity();
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < 50; ++i)
|
|
||||||
{
|
|
||||||
vec.PopBack();
|
|
||||||
}
|
|
||||||
|
|
||||||
REQUIRE(vec.Size() == 50);
|
|
||||||
REQUIRE(vec.Capacity() == tempVal);
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("Clear")
|
|
||||||
{
|
|
||||||
StableVector<uint32_t> vec;
|
|
||||||
|
|
||||||
REQUIRE(vec.Size() == 0);
|
|
||||||
REQUIRE(vec.Capacity() == 32);
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < 100; ++i)
|
|
||||||
{
|
|
||||||
vec.PushBack(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
REQUIRE(vec.Size() == 100);
|
|
||||||
|
|
||||||
vec.Clear();
|
|
||||||
|
|
||||||
REQUIRE(vec.Size() == 0);
|
|
||||||
REQUIRE(vec.Capacity() == 32);
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("Add/Fill")
|
|
||||||
{
|
|
||||||
StableVector<std::string> vec;
|
|
||||||
|
|
||||||
REQUIRE(vec.Size() == 0);
|
|
||||||
REQUIRE(vec.Capacity() == 32);
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < 100; ++i)
|
|
||||||
{
|
|
||||||
vec.PushBack("a");
|
|
||||||
}
|
|
||||||
|
|
||||||
REQUIRE(vec.Size() == 100);
|
|
||||||
|
|
||||||
vec.Remove(56);
|
|
||||||
REQUIRE(vec[56] == "a");
|
|
||||||
|
|
||||||
vec.Push("z");
|
|
||||||
|
|
||||||
REQUIRE(vec.Size() == 100);
|
|
||||||
REQUIRE(vec[56] == "z");
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("Correct Initialization")
|
|
||||||
{
|
|
||||||
StableVector<TestCount> vec;
|
|
||||||
|
|
||||||
REQUIRE(incrementCounter == 0);
|
|
||||||
REQUIRE(decrementCounter == 0);
|
|
||||||
|
|
||||||
vec.EmplaceBack("a");
|
|
||||||
|
|
||||||
REQUIRE(incrementCounter == 1);
|
|
||||||
REQUIRE(decrementCounter == 0);
|
|
||||||
|
|
||||||
vec.PushBack(TestCount("b"));
|
|
||||||
|
|
||||||
REQUIRE(incrementCounter == 3);
|
|
||||||
REQUIRE(decrementCounter == 1);
|
|
||||||
|
|
||||||
TestCount testClass = TestCount("c");
|
|
||||||
vec.PushBack(std::move(testClass));
|
|
||||||
|
|
||||||
REQUIRE(incrementCounter == 5);
|
|
||||||
REQUIRE(decrementCounter == 1);
|
|
||||||
|
|
||||||
vec.Clear();
|
|
||||||
|
|
||||||
REQUIRE(incrementCounter == 5);
|
|
||||||
REQUIRE(decrementCounter == 4);
|
|
||||||
|
|
||||||
vec.PushBack(TestCount("d"));
|
|
||||||
|
|
||||||
REQUIRE(incrementCounter == 7);
|
|
||||||
REQUIRE(decrementCounter == 5);
|
|
||||||
|
|
||||||
TestCount testClass2 = TestCount("e");
|
|
||||||
vec.PushBack(testClass2);
|
|
||||||
|
|
||||||
REQUIRE(incrementCounter == 9);
|
|
||||||
REQUIRE(decrementCounter == 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("Out of scope check")
|
|
||||||
{
|
|
||||||
REQUIRE(incrementCounter == 9);
|
|
||||||
REQUIRE(decrementCounter == 9);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,281 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 "Data/Containers/String.hpp"
|
|
||||||
|
|
||||||
using namespace OpenVulkano;
|
|
||||||
|
|
||||||
TEST_CASE("Constructors")
|
|
||||||
{
|
|
||||||
String str1;
|
|
||||||
REQUIRE(str1 == "");
|
|
||||||
|
|
||||||
String str2("Hello");
|
|
||||||
REQUIRE(str2 == "Hello");
|
|
||||||
|
|
||||||
String str3(std::string("World"));
|
|
||||||
REQUIRE(str3 == "World");
|
|
||||||
|
|
||||||
String str4(str2);
|
|
||||||
REQUIRE(str4 == "Hello");
|
|
||||||
|
|
||||||
String str5(std::move(str3));
|
|
||||||
REQUIRE(str5 == "World");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("Assignment")
|
|
||||||
{
|
|
||||||
String str1;
|
|
||||||
str1 = "Hello";
|
|
||||||
REQUIRE(str1 == "Hello");
|
|
||||||
|
|
||||||
String str2;
|
|
||||||
str2 = std::string("World");
|
|
||||||
REQUIRE(str2 == "World");
|
|
||||||
|
|
||||||
String str3;
|
|
||||||
str3 = str1;
|
|
||||||
REQUIRE(str3 == "Hello");
|
|
||||||
|
|
||||||
String str4;
|
|
||||||
str4 = std::move(str2);
|
|
||||||
REQUIRE(str4 == "World");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("Concatenation")
|
|
||||||
{
|
|
||||||
String str1("Hello");
|
|
||||||
str1 += " World";
|
|
||||||
REQUIRE(str1 == "Hello World");
|
|
||||||
|
|
||||||
String str2("Hello");
|
|
||||||
String str3 = str2 + " World";
|
|
||||||
REQUIRE(str3 == "Hello World");
|
|
||||||
|
|
||||||
String str4("Hello");
|
|
||||||
str4 += std::string(" World");
|
|
||||||
REQUIRE(str4 == "Hello World");
|
|
||||||
|
|
||||||
String str5("Hello");
|
|
||||||
String str6 = str5 + std::string(" World");
|
|
||||||
REQUIRE(str6 == "Hello World");
|
|
||||||
|
|
||||||
String str7("Hello");
|
|
||||||
str7 += String(" World");
|
|
||||||
REQUIRE(str7 == "Hello World");
|
|
||||||
|
|
||||||
String str8("Hello");
|
|
||||||
String str9 = str8 + String(" World");
|
|
||||||
REQUIRE(str9 == "Hello World");
|
|
||||||
|
|
||||||
String str10 = String("Hello") + " World";
|
|
||||||
REQUIRE(str10 == "Hello World");
|
|
||||||
|
|
||||||
String str11 = String("Hello") + std::string(" World");
|
|
||||||
REQUIRE(str11 == "Hello World");
|
|
||||||
|
|
||||||
String str12 = std::string("Hello") + String(" World");
|
|
||||||
REQUIRE(str12 == "Hello World");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("Comparison")
|
|
||||||
{
|
|
||||||
String str1("Hello");
|
|
||||||
REQUIRE(str1 == "Hello");
|
|
||||||
REQUIRE(str1 != "World");
|
|
||||||
|
|
||||||
String str2("World");
|
|
||||||
REQUIRE(str2 == "World");
|
|
||||||
REQUIRE(str2 != "Hello");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("Trim")
|
|
||||||
{
|
|
||||||
String str1(" Hello World ");
|
|
||||||
REQUIRE(str1.Trim() == "Hello World");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("FindIndex")
|
|
||||||
{
|
|
||||||
String str1("Georg will save us all from our doom");
|
|
||||||
REQUIRE(str1.FindStartIndexOf("save") == 11);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("Upper/Lower")
|
|
||||||
{
|
|
||||||
String str1("Hello World");
|
|
||||||
str1.ToUpper();
|
|
||||||
REQUIRE(str1 == "HELLO WORLD");
|
|
||||||
|
|
||||||
String str2("Hello World");
|
|
||||||
str2.ToLower();
|
|
||||||
REQUIRE(str2 == "hello world");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("Substring")
|
|
||||||
{
|
|
||||||
String str1("Hello World");
|
|
||||||
REQUIRE(str1.SubString(0, 5) == "Hello");
|
|
||||||
REQUIRE(str1.SubString(6, 11) == "World");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("FromString")
|
|
||||||
{
|
|
||||||
String str1("42");
|
|
||||||
REQUIRE(str1.FromString<int>() == 42);
|
|
||||||
|
|
||||||
String str2("42.42");
|
|
||||||
REQUIRE(str2.FromString<float>() == 42.42f);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("StartsWith")
|
|
||||||
{
|
|
||||||
String str1("Hello World");
|
|
||||||
REQUIRE(str1.StartsWith("Hello"));
|
|
||||||
REQUIRE(!str1.StartsWith("World"));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("EndsWith")
|
|
||||||
{
|
|
||||||
String str1("Hello World");
|
|
||||||
REQUIRE(str1.EndsWith("World"));
|
|
||||||
REQUIRE(!str1.EndsWith("Hello"));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("Contains")
|
|
||||||
{
|
|
||||||
String str1("Hello World");
|
|
||||||
REQUIRE(str1.Contains("Hello"));
|
|
||||||
REQUIRE(str1.Contains("World"));
|
|
||||||
REQUIRE(!str1.Contains("Georg"));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("FindEndIndexOf")
|
|
||||||
{
|
|
||||||
String str1("Georg will save us all from our doom");
|
|
||||||
REQUIRE(str1.FindEndIndexOf("save") == 11);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("TrimFront")
|
|
||||||
{
|
|
||||||
String str1(" Hello World");
|
|
||||||
REQUIRE(str1.TrimFront() == "Hello World");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("TrimBack")
|
|
||||||
{
|
|
||||||
String str1("Hello World ");
|
|
||||||
REQUIRE(str1.TrimBack() == "Hello World");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("Empty")
|
|
||||||
{
|
|
||||||
String str1;
|
|
||||||
REQUIRE(str1.Empty());
|
|
||||||
REQUIRE(!str1);
|
|
||||||
|
|
||||||
String str2("Hello World");
|
|
||||||
REQUIRE(!str2.Empty());
|
|
||||||
REQUIRE(!!str2);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("Size")
|
|
||||||
{
|
|
||||||
String str1("Hello World");
|
|
||||||
REQUIRE(str1.Size() == 11);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("Capacity")
|
|
||||||
{
|
|
||||||
String str1("Hello World");
|
|
||||||
REQUIRE(str1.Capacity() >= 11);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("CharCount")
|
|
||||||
{
|
|
||||||
String str1("Hello World");
|
|
||||||
REQUIRE(str1.CharCount() == 11);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("PopBack")
|
|
||||||
{
|
|
||||||
String str1("Hello World");
|
|
||||||
str1.PopBack();
|
|
||||||
REQUIRE(str1 == "Hello Worl");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("Clear")
|
|
||||||
{
|
|
||||||
String str1("Hello World");
|
|
||||||
str1.Clear();
|
|
||||||
REQUIRE(str1.Empty());
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("Split")
|
|
||||||
{
|
|
||||||
String str1("Hello,World");
|
|
||||||
auto split = str1.Split(",");
|
|
||||||
REQUIRE(split.size() == 2);
|
|
||||||
REQUIRE(split[0] == "Hello");
|
|
||||||
REQUIRE(split[1] == "World");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("SplitAtLastOccurrence")
|
|
||||||
{
|
|
||||||
String str1 = "Hello,World,Georg";
|
|
||||||
auto split = str1.SplitAtLastOccurrence(",");
|
|
||||||
REQUIRE(split.first == "Hello,World");
|
|
||||||
REQUIRE(split.second == "Georg");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("SplitAtFirstOccurrence")
|
|
||||||
{
|
|
||||||
String str1 = "Hello,World,Georg";
|
|
||||||
auto split = str1.SplitAtFirstOccurrence(",");
|
|
||||||
REQUIRE(split.first == "Hello");
|
|
||||||
REQUIRE(split.second == "World,Georg");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("SplitAsStringViews")
|
|
||||||
{
|
|
||||||
String str1("Hello,World");
|
|
||||||
auto split = str1.SplitAsStringViews(",");
|
|
||||||
REQUIRE(split.size() == 2);
|
|
||||||
REQUIRE(split[0] == "Hello");
|
|
||||||
REQUIRE(split[1] == "World");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("SplitAtFirstOccurrenceAsStringViews")
|
|
||||||
{
|
|
||||||
String str1 = "Hello,World,Georg";
|
|
||||||
auto split = str1.SplitAtFirstOccurenceAsStringViews(",");
|
|
||||||
REQUIRE(split.first == "Hello");
|
|
||||||
REQUIRE(split.second == "World,Georg");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("SplitAtLastOccurenceAsStringViews")
|
|
||||||
{
|
|
||||||
String str1 = "Hello,World,Georg";
|
|
||||||
auto split = str1.SplitAtLastOccurenceAsStringViews(",");
|
|
||||||
REQUIRE(split.first == "Hello,World");
|
|
||||||
REQUIRE(split.second == "Georg");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("OctToInt")
|
|
||||||
{
|
|
||||||
String str1("47");
|
|
||||||
REQUIRE(str1.OctToInt() == 39);
|
|
||||||
REQUIRE(String::OctToInt("552") == 362);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("HexToInt")
|
|
||||||
{
|
|
||||||
String str1("2A");
|
|
||||||
REQUIRE(str1.HexToInt() == 42);
|
|
||||||
REQUIRE(String::HexToInt("FF") == 255);
|
|
||||||
}
|
|
||||||
@@ -1,123 +0,0 @@
|
|||||||
#include <catch2/catch_all.hpp>
|
|
||||||
|
|
||||||
#include "IO/MemMappedFile.hpp"
|
|
||||||
#include "IO/MemMappedFileWriteHelper.hpp"
|
|
||||||
#include "IO/AppFolders.hpp"
|
|
||||||
#include "Base/Logger.hpp"
|
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
#include <filesystem>
|
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
|
||||||
|
|
||||||
TEST_CASE("MemMappedFileWrite")
|
|
||||||
{
|
|
||||||
OpenVulkano::Logger::SetupLogger("", "tests.log");
|
|
||||||
|
|
||||||
auto path = OpenVulkano::AppFolders::GetAppTempDir();
|
|
||||||
path += "/MemFileTest.txt";
|
|
||||||
|
|
||||||
std::string data = "Hello World X\n"
|
|
||||||
"Hello World Y\n"
|
|
||||||
"Hello World Z\n"
|
|
||||||
"Hello World W\n"
|
|
||||||
"Hello World A\n"
|
|
||||||
"Hello World B\n"
|
|
||||||
"Hello World C\n"
|
|
||||||
"Hello World D\n"
|
|
||||||
"Hello World E\n"
|
|
||||||
"Hello World F\n"
|
|
||||||
"Hello World G\n"
|
|
||||||
"Hello World H\n"
|
|
||||||
"Hello World I\n"
|
|
||||||
"Hello World J\n"
|
|
||||||
"Hello World K\n"
|
|
||||||
"Hello World L\n"
|
|
||||||
"Hello World M\n"
|
|
||||||
"Hello World N\n";
|
|
||||||
|
|
||||||
|
|
||||||
SECTION("Write to MemMappedFile")
|
|
||||||
{
|
|
||||||
OpenVulkano::MemMappedFileWriter writer(path, 1024);
|
|
||||||
writer.Write(data.data(), data.size());
|
|
||||||
|
|
||||||
REQUIRE(writer.GetOffset() == data.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("Control Size")
|
|
||||||
{
|
|
||||||
OpenVulkano::MemMappedFile memFile(path, OpenVulkano::MemMappedFile::READ_ONLY);
|
|
||||||
REQUIRE(memFile.Size() == 1024); // The size that comes from the first Test.
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("Compare String Data for per char")
|
|
||||||
{
|
|
||||||
OpenVulkano::MemMappedFileWriteHelper memFileHelper(path, OpenVulkano::MemMappedFile::READ_ONLY);
|
|
||||||
REQUIRE(memFileHelper.Trim(data.size()));
|
|
||||||
|
|
||||||
std::string testData((char*) memFileHelper.Data());
|
|
||||||
|
|
||||||
for (size_t i = 0; i < data.size(); i++)
|
|
||||||
{
|
|
||||||
if (data[i] != testData[i])
|
|
||||||
{
|
|
||||||
REQUIRE(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
memFileHelper.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("Trim File")
|
|
||||||
{
|
|
||||||
OpenVulkano::MemMappedFileWriteHelper helper(path,
|
|
||||||
OpenVulkano::MemMappedFileWriteHelper::USE_CURRENT_FILE_SIZE);
|
|
||||||
REQUIRE(helper.Trim(100));
|
|
||||||
REQUIRE(helper.Size() == 100);
|
|
||||||
|
|
||||||
helper.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("Write Data 2")
|
|
||||||
{
|
|
||||||
OpenVulkano::MemMappedFileWriter writer(path, OpenVulkano::MemMappedFileWriteHelper::USE_CURRENT_FILE_SIZE);
|
|
||||||
writer.Write(data.data(), data.size());
|
|
||||||
writer.Write(data.data(), data.size());
|
|
||||||
writer.Write(data.data(), data.size());
|
|
||||||
|
|
||||||
REQUIRE(writer.GetOffset() == data.size() * 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("Compare Data")
|
|
||||||
{
|
|
||||||
OpenVulkano::MemMappedFileWriteHelper helper(path,
|
|
||||||
OpenVulkano::MemMappedFileWriteHelper::USE_CURRENT_FILE_SIZE);
|
|
||||||
REQUIRE(helper.Data() != nullptr);
|
|
||||||
std::string testData((char*) helper.Data());
|
|
||||||
helper.Close();
|
|
||||||
|
|
||||||
std::ifstream file(path, std::ios::binary);
|
|
||||||
std::string streamData;
|
|
||||||
std::getline(file, streamData, '\0');
|
|
||||||
file.close();
|
|
||||||
|
|
||||||
for (size_t i = 0; i < testData.size(); i++)
|
|
||||||
{
|
|
||||||
if (streamData[i] != testData[i])
|
|
||||||
{
|
|
||||||
REQUIRE(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
REQUIRE(streamData.size() == testData.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("Actual Size")
|
|
||||||
{
|
|
||||||
std::error_code ec;
|
|
||||||
std::uintmax_t size = fs::file_size(path, ec);
|
|
||||||
|
|
||||||
REQUIRE(size == 756);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,190 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 <cmath>
|
|
||||||
|
|
||||||
#include "Math/RGB565.hpp"
|
|
||||||
|
|
||||||
using namespace OpenVulkano::Math;
|
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
bool almostEqual(float a, float b, float epsilon = 0.001f) { return std::fabs(a - b) < epsilon; }
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("test_rgb565_default_ctor", "[RGB565]")
|
|
||||||
{
|
|
||||||
RGB565 color;
|
|
||||||
REQUIRE(color.GetR() == 0);
|
|
||||||
REQUIRE(color.GetG() == 0);
|
|
||||||
REQUIRE(color.GetB() == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("test_rgb565_creation", "[RGB565]")
|
|
||||||
{
|
|
||||||
RGB565 color1(Vector4uc(255, 255, 255, 129));
|
|
||||||
REQUIRE(color1.r == 31);
|
|
||||||
REQUIRE(color1.g == 63);
|
|
||||||
REQUIRE(color1.b == 31);
|
|
||||||
|
|
||||||
RGB565 color2(Vector4f(1.0f, 1.0f, 1.0f, 1.0f));
|
|
||||||
REQUIRE(color2.r == 31);
|
|
||||||
REQUIRE(color2.g == 63);
|
|
||||||
REQUIRE(color2.b == 31);
|
|
||||||
|
|
||||||
RGB565 color3(Vector4i(128, 128, 128, 0));
|
|
||||||
REQUIRE(color3.r == 15);
|
|
||||||
REQUIRE(color3.g == 31);
|
|
||||||
REQUIRE(color3.b == 15);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("test_rgb565_conversion_to_vector3", "[RGB565]")
|
|
||||||
{
|
|
||||||
RGB565 color(Vector4i(255, 0, 0, 1));
|
|
||||||
Vector3f vec = color.Get3Normalized<float>();
|
|
||||||
REQUIRE(almostEqual(vec.x, 1.0f));
|
|
||||||
REQUIRE(almostEqual(vec.y, 0.0f));
|
|
||||||
REQUIRE(almostEqual(vec.z, 0.0f));
|
|
||||||
|
|
||||||
Vector3f vec3 { 0.1f, 0.5f, 1.0f };
|
|
||||||
RGB565 color2(vec3);
|
|
||||||
REQUIRE(almostEqual(color2.GetR_Normalized(), 0.096));
|
|
||||||
REQUIRE(almostEqual(color2.GetG_Normalized(), 0.492));
|
|
||||||
REQUIRE(almostEqual(color2.GetB_Normalized(), 1.0));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("test_rgb565_conversion_to_vector4", "[RGB565]")
|
|
||||||
{
|
|
||||||
RGB565 color(Vector4i(255, 0, 0, 129));
|
|
||||||
Vector4f vec = color.Get4Normalized<float>();
|
|
||||||
REQUIRE(almostEqual(vec.x, 1.0f));
|
|
||||||
REQUIRE(almostEqual(vec.y, 0.0f));
|
|
||||||
REQUIRE(almostEqual(vec.z, 0.0f));
|
|
||||||
REQUIRE(almostEqual(vec.w, 1.0f));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("test_rgb565_conversion_from_vector3", "[RGB565]")
|
|
||||||
{
|
|
||||||
Vector3f vec(1.0f, 0.5f, 0.25f);
|
|
||||||
RGB565 color(vec);
|
|
||||||
REQUIRE(color.r == 31);
|
|
||||||
REQUIRE(color.g == 31);
|
|
||||||
REQUIRE(color.b == 7);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("test_rgb565_conversion_from_vector4", "[RGB565]")
|
|
||||||
{
|
|
||||||
Vector4f vec(0.0f, 1.0f, 0.5f, 0.0f);
|
|
||||||
RGB565 color(vec);
|
|
||||||
REQUIRE(color.r == 0);
|
|
||||||
REQUIRE(color.g == 63);
|
|
||||||
REQUIRE(color.b == 15);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("test_rgb565_cast_to_vector4", "[RGB565]")
|
|
||||||
{
|
|
||||||
RGB565 color;
|
|
||||||
color.r = 31;
|
|
||||||
color.g = 31;
|
|
||||||
color.b = 7;
|
|
||||||
Vector4f casted = (Vector4f)color;
|
|
||||||
REQUIRE(almostEqual(casted.r, 1.0));
|
|
||||||
REQUIRE(almostEqual(casted.g, 0.492));
|
|
||||||
REQUIRE(almostEqual(casted.b, 0.225));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("test_rgb565_getters_setters", "[RGB565]")
|
|
||||||
{
|
|
||||||
RGB565 color;
|
|
||||||
color.SetR_Normalized(0.1f);
|
|
||||||
color.SetG_Normalized(0.5f);
|
|
||||||
color.SetB_Normalized(1.0f);
|
|
||||||
|
|
||||||
REQUIRE(almostEqual(color.GetR_Normalized(), 0.096));
|
|
||||||
REQUIRE(almostEqual(color.GetG_Normalized(), 0.492));
|
|
||||||
REQUIRE(almostEqual(color.GetB_Normalized(), 1.0));
|
|
||||||
|
|
||||||
color = RGB565(Vector3<uint8_t> { 255, 127, 63 });
|
|
||||||
Vector3<uint8_t> vec3 = color;
|
|
||||||
|
|
||||||
REQUIRE(vec3.r == 255);
|
|
||||||
REQUIRE(vec3.g == 125);
|
|
||||||
REQUIRE(vec3.b == 57);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("test_rgb565_comparison", "[RGB565]")
|
|
||||||
{
|
|
||||||
RGB565 color1(Vector4<uint8_t>{255, 127, 63, 255});
|
|
||||||
RGB565 color2(Vector4<uint8_t>{255, 127, 63, 255});
|
|
||||||
RGB565 color3(Vector4<uint8_t>{63, 127, 255, 255});
|
|
||||||
|
|
||||||
REQUIRE(color1 == color2);
|
|
||||||
REQUIRE(color1 != color3);
|
|
||||||
|
|
||||||
{
|
|
||||||
RGB565 color4 = color1;
|
|
||||||
REQUIRE(color4 == color1);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector3<uint8_t> vec3 { 255, 127, 63 };
|
|
||||||
color1 = vec3;
|
|
||||||
REQUIRE(color1.GetR() == 255);
|
|
||||||
REQUIRE(color1.GetG() == 125);
|
|
||||||
REQUIRE(color1.GetB() == 57);
|
|
||||||
|
|
||||||
Vector4<float> vec4 { 0.1f, 0.5f, 1.0f, 0.7f };
|
|
||||||
color1 = vec4;
|
|
||||||
REQUIRE(almostEqual(color1.GetR_Normalized(), 0.096));
|
|
||||||
REQUIRE(almostEqual(color1.GetG_Normalized(), 0.492));
|
|
||||||
REQUIRE(almostEqual(color1.GetB_Normalized(), 1.0));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("test_rgb565_operators", "[RGB565]")
|
|
||||||
{
|
|
||||||
RGB565 rgb1, rgb2;
|
|
||||||
|
|
||||||
rgb1.SetR(255);
|
|
||||||
rgb1.SetG(127);
|
|
||||||
rgb1.SetB(63);
|
|
||||||
|
|
||||||
rgb2.SetR(255);
|
|
||||||
rgb2.SetG(127);
|
|
||||||
rgb2.SetB(63);
|
|
||||||
|
|
||||||
REQUIRE(rgb1 == rgb2);
|
|
||||||
|
|
||||||
rgb2.SetB(0);
|
|
||||||
REQUIRE(rgb1 != rgb2);
|
|
||||||
|
|
||||||
rgb1.SetR(255);
|
|
||||||
rgb1.SetG(127);
|
|
||||||
rgb1.SetB(63);
|
|
||||||
|
|
||||||
rgb2 = rgb1;
|
|
||||||
REQUIRE(rgb1 == rgb2);
|
|
||||||
|
|
||||||
Vector3i delta(10, 20, 30);
|
|
||||||
rgb1.SetR(100);
|
|
||||||
rgb1.SetG(50);
|
|
||||||
rgb1.SetB(25);
|
|
||||||
|
|
||||||
rgb1 += delta;
|
|
||||||
|
|
||||||
REQUIRE(rgb1.GetR() == 106);
|
|
||||||
REQUIRE(rgb1.GetG() == 64);
|
|
||||||
REQUIRE(rgb1.GetB() == 49);
|
|
||||||
|
|
||||||
rgb1.SetR(100);
|
|
||||||
rgb1.SetG(50);
|
|
||||||
rgb1.SetB(25);
|
|
||||||
|
|
||||||
rgb1 -= delta;
|
|
||||||
|
|
||||||
REQUIRE(rgb1.GetR() == 82);
|
|
||||||
REQUIRE(rgb1.GetG() == 24);
|
|
||||||
REQUIRE(rgb1.GetB() == 0); // Expect to clamp here
|
|
||||||
}
|
|
||||||
@@ -1,154 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 <cmath>
|
|
||||||
|
|
||||||
#include "Math/RGBA5551.hpp"
|
|
||||||
|
|
||||||
using namespace OpenVulkano::Math;
|
|
||||||
|
|
||||||
bool almostEqual(float a, float b, float epsilon = 0.001f) { return std::fabs(a - b) < epsilon; }
|
|
||||||
|
|
||||||
TEST_CASE("test_rgba5551_default_ctor", "[RGBA5551]")
|
|
||||||
{
|
|
||||||
RGBA5551 color;
|
|
||||||
REQUIRE(color.GetR() == 0);
|
|
||||||
REQUIRE(color.GetG() == 0);
|
|
||||||
REQUIRE(color.GetB() == 0);
|
|
||||||
REQUIRE(color.GetA() == 255);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("test_rgba5551_creation", "[RGBA5551]")
|
|
||||||
{
|
|
||||||
RGBA5551 color1(Vector4uc(255, 255, 255, 129));
|
|
||||||
REQUIRE(color1.r == 31);
|
|
||||||
REQUIRE(color1.g == 31);
|
|
||||||
REQUIRE(color1.b == 31);
|
|
||||||
REQUIRE(color1.a == 1);
|
|
||||||
|
|
||||||
RGBA5551 color2(Vector4f(1.0f, 1.0f, 1.0f, 1.0f));
|
|
||||||
REQUIRE(color2.r == 31);
|
|
||||||
REQUIRE(color2.g == 31);
|
|
||||||
REQUIRE(color2.b == 31);
|
|
||||||
REQUIRE(color2.a == 1);
|
|
||||||
|
|
||||||
RGBA5551 color3(Vector4i(128, 128, 128, 0));
|
|
||||||
REQUIRE(color3.r == 15);
|
|
||||||
REQUIRE(color3.g == 15);
|
|
||||||
REQUIRE(color3.b == 15);
|
|
||||||
REQUIRE(color3.a == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("test_rgba5551_conversion_to_vector3", "[RGBA5551]")
|
|
||||||
{
|
|
||||||
RGBA5551 color(Vector4i(255, 0, 0, 1));
|
|
||||||
Vector3f vec = color.Get3Normalized<float>();
|
|
||||||
REQUIRE(almostEqual(vec.x, 1.0f));
|
|
||||||
REQUIRE(almostEqual(vec.y, 0.0f));
|
|
||||||
REQUIRE(almostEqual(vec.z, 0.0f));
|
|
||||||
|
|
||||||
Vector3f vec3 { 0.1f, 0.5f, 1.0f };
|
|
||||||
RGBA5551 color2(vec3);
|
|
||||||
REQUIRE(almostEqual(color2.GetR_Normalized(), 0.096f));
|
|
||||||
REQUIRE(almostEqual(color2.GetG_Normalized(), 0.483f));
|
|
||||||
REQUIRE(almostEqual(color2.GetB_Normalized(), 1.0f));
|
|
||||||
REQUIRE(almostEqual(color2.GetA_Normalized(), 1.0f));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("test_rgba5551_conversion_to_vector4", "[RGBA5551]")
|
|
||||||
{
|
|
||||||
RGBA5551 color(Vector4i(255, 0, 0, 129));
|
|
||||||
Vector4f vec = color.Get4Normalized<float>();
|
|
||||||
REQUIRE(almostEqual(vec.x, 1.0f));
|
|
||||||
REQUIRE(almostEqual(vec.y, 0.0f));
|
|
||||||
REQUIRE(almostEqual(vec.z, 0.0f));
|
|
||||||
REQUIRE(almostEqual(vec.w, 1.0f));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("test_rgba5551_conversion_from_vector3", "[RGBA5551]")
|
|
||||||
{
|
|
||||||
Vector3f vec(1.0f, 0.5f, 0.25f);
|
|
||||||
RGBA5551 color(vec);
|
|
||||||
REQUIRE(color.r == 31);
|
|
||||||
REQUIRE(color.g == 15);
|
|
||||||
REQUIRE(color.b == 7);
|
|
||||||
REQUIRE(color.a == 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("test_rgba5551_conversion_from_vector4", "[RGBA5551]")
|
|
||||||
{
|
|
||||||
Vector4f vec(0.0f, 1.0f, 0.5f, 0.0f);
|
|
||||||
RGBA5551 color(vec);
|
|
||||||
REQUIRE(color.r == 0);
|
|
||||||
REQUIRE(color.g == 31);
|
|
||||||
REQUIRE(color.b == 15);
|
|
||||||
REQUIRE(color.a == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("test_rgba5551_cast_to_vector4", "[RGBA5551]")
|
|
||||||
{
|
|
||||||
RGBA5551 color;
|
|
||||||
color.r = 31;
|
|
||||||
color.g = 15;
|
|
||||||
color.b = 7;
|
|
||||||
color.a = 1;
|
|
||||||
Vector4f casted = (Vector4f)color;
|
|
||||||
REQUIRE(almostEqual(casted.r, 1.0));
|
|
||||||
REQUIRE(almostEqual(casted.g, 0.483));
|
|
||||||
REQUIRE(almostEqual(casted.b, 0.225));
|
|
||||||
REQUIRE(almostEqual(casted.a, 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("test_rgba5551_getters_setters", "[RGBA5551]")
|
|
||||||
{
|
|
||||||
RGBA5551 color;
|
|
||||||
color.SetR_Normalized(0.1f);
|
|
||||||
color.SetG_Normalized(0.5f);
|
|
||||||
color.SetB_Normalized(1.0f);
|
|
||||||
color.SetA_Normalized(0.7f);
|
|
||||||
|
|
||||||
REQUIRE(almostEqual(color.GetR_Normalized(), 0.096f));
|
|
||||||
REQUIRE(almostEqual(color.GetG_Normalized(), 0.483f));
|
|
||||||
REQUIRE(almostEqual(color.GetB_Normalized(), 1.0f));
|
|
||||||
REQUIRE(color.GetA() == 255);
|
|
||||||
|
|
||||||
color = RGBA5551(Vector3<uint8_t> { 255, 127, 63 });
|
|
||||||
Vector3<uint8_t> vec3 = color;
|
|
||||||
|
|
||||||
REQUIRE(vec3.r == 255);
|
|
||||||
REQUIRE(vec3.g == 123);
|
|
||||||
REQUIRE(vec3.b == 57);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("test_rgba5551_comparison", "[RGBA5551]")
|
|
||||||
{
|
|
||||||
RGBA5551 color1(Vector4<uint8_t>{255, 127, 63, 255});
|
|
||||||
RGBA5551 color2(Vector4<uint8_t>{255, 127, 63, 255});
|
|
||||||
RGBA5551 color3(Vector4<uint8_t>{63, 127, 255, 255});
|
|
||||||
|
|
||||||
REQUIRE(color1 == color2);
|
|
||||||
REQUIRE(color1 != color3);
|
|
||||||
|
|
||||||
{
|
|
||||||
RGBA5551 color4 = color1;
|
|
||||||
REQUIRE(color4 == color1);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector3<uint8_t> vec3 { 255, 127, 63 };
|
|
||||||
color1 = vec3;
|
|
||||||
REQUIRE(color1.GetR() == 255);
|
|
||||||
REQUIRE(color1.GetG() == 123);
|
|
||||||
REQUIRE(color1.GetB() == 57);
|
|
||||||
REQUIRE(color1.GetA() == 255);
|
|
||||||
|
|
||||||
Vector4<float> vec4 { 0.1f, 0.5f, 1.0f, 0.7f };
|
|
||||||
color1 = vec4;
|
|
||||||
REQUIRE(almostEqual(color1.GetR_Normalized(), 0.096f));
|
|
||||||
REQUIRE(almostEqual(color1.GetG_Normalized(), 0.483f));
|
|
||||||
REQUIRE(almostEqual(color1.GetB_Normalized(), 1.0f));
|
|
||||||
REQUIRE(color1.GetA() == 255);
|
|
||||||
}
|
|
||||||
@@ -1,230 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 <catch2/matchers/catch_matchers_floating_point.hpp>
|
|
||||||
|
|
||||||
#include "Math/Math.hpp"
|
|
||||||
#include "Scene/Ray.hpp"
|
|
||||||
#include "Scene/GeometryFactory.hpp"
|
|
||||||
|
|
||||||
using namespace OpenVulkano::Math;
|
|
||||||
using namespace OpenVulkano::Math::Utils;
|
|
||||||
using namespace OpenVulkano::Scene;
|
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
void CompareVec3Approx(const Vector3f& f, const Vector3f& s)
|
|
||||||
{
|
|
||||||
REQUIRE_THAT(f.x, Catch::Matchers::WithinRel(s.x));
|
|
||||||
REQUIRE_THAT(f.x, Catch::Matchers::WithinRel(s.x));
|
|
||||||
REQUIRE_THAT(f.x, Catch::Matchers::WithinRel(s.x));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_CASE("RaySphereIntersection")
|
|
||||||
{
|
|
||||||
auto sphere = GeometryFactory::MakeSphere(1, 32, 16);
|
|
||||||
// 2 intersections
|
|
||||||
{
|
|
||||||
RayHit h1, h2;
|
|
||||||
Ray ray(Vector3f(0, 0, -5), Vector3f(0, 0, 1));
|
|
||||||
REQUIRE(ray.IntersectSphere(Vector3f(0), 1, h1, h2) == 2);
|
|
||||||
REQUIRE((h1.point == Vector3f(0, 0, -1) && h2.point == Vector3f(0, 0, 1)));
|
|
||||||
REQUIRE((h1.normal == Vector3f(0, 0, -1) && h2.normal == Vector3f(0, 0, 1)));
|
|
||||||
REQUIRE(h1.distance2 < h2.distance2);
|
|
||||||
REQUIRE((h1.GetDistance() == distance(ray.GetOrigin(), h1.point)
|
|
||||||
&& h2.GetDistance() == distance(ray.GetOrigin(), h2.point)));
|
|
||||||
REQUIRE_THAT(h1.GetDistance(), Catch::Matchers::WithinRel(std::sqrt(h1.distance2)));
|
|
||||||
// this returns just closest point
|
|
||||||
if (auto opt = ray.IntersectSphere(Vector3f(0), 1))
|
|
||||||
{
|
|
||||||
opt->GetDistance();
|
|
||||||
REQUIRE(opt.value() == h1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 1 intersection
|
|
||||||
{
|
|
||||||
RayHit h1, h2;
|
|
||||||
Ray ray(Vector3f(1, 0, -1), Vector3f(0, 0, 1));
|
|
||||||
REQUIRE(ray.IntersectSphere(Vector3f(0), 1, h1, h2) == 1);
|
|
||||||
REQUIRE(h1 == h2);
|
|
||||||
REQUIRE(h1.point == Vector3f(1, 0, 0));
|
|
||||||
REQUIRE(ray.IntersectSphere(Vector3f(0), 1) == h1);
|
|
||||||
}
|
|
||||||
// 0 intersections
|
|
||||||
{
|
|
||||||
RayHit h1, h2;
|
|
||||||
Ray ray(Vector3f(2, 0, -1), Vector3f(0, 0, 1));
|
|
||||||
REQUIRE(ray.IntersectSphere(Vector3f(0), 1, h1, h2) == 0);
|
|
||||||
REQUIRE(!ray.IntersectSphere(Vector3f(0), 1).has_value());
|
|
||||||
}
|
|
||||||
// ray is inside sphere
|
|
||||||
{
|
|
||||||
RayHit h1, h2;
|
|
||||||
Ray ray(Vector3f(0, 0, 0), Vector3f(0.5, 0.5, 1));
|
|
||||||
REQUIRE(ray.IntersectSphere(Vector3f(0), 1, h1, h2) == 1);
|
|
||||||
REQUIRE(h1 == h2);
|
|
||||||
::CompareVec3Approx(h1.normal, h1.point);
|
|
||||||
auto value = ray.IntersectSphere(Vector3f(0), 1);
|
|
||||||
REQUIRE(value->GetDistance() == h1.GetDistance());
|
|
||||||
REQUIRE_THAT(value->distance2, Catch::Matchers::WithinRel(h1.distance2));
|
|
||||||
::CompareVec3Approx(value->normal, h1.normal);
|
|
||||||
::CompareVec3Approx(value->point, h1.point);
|
|
||||||
}
|
|
||||||
// ray intersects sphere behind the origin
|
|
||||||
{
|
|
||||||
RayHit h1, h2;
|
|
||||||
Ray ray(Vector3f(0, 0, 3), Vector3f(0, 0, 1));
|
|
||||||
REQUIRE(ray.IntersectSphere(Vector3f(0), 1, h1, h2) == 0);
|
|
||||||
REQUIRE(!ray.IntersectSphere(Vector3f(0), 1).has_value());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("RayTriangleIntersection")
|
|
||||||
{
|
|
||||||
auto tri = GeometryFactory::MakeTriangle(Vector3f(0), Vector3f(3, 0, 0), Vector3f(1.5, 2, 0));
|
|
||||||
// intersects
|
|
||||||
{
|
|
||||||
Ray ray(Vector3f(1.5, 2, -5), Vector3f(0, 0, 1));
|
|
||||||
std::optional<RayHit> hit = ray.IntersectTriangle(tri.vertices[0].position, tri.vertices[1].position, tri.vertices[2].position);
|
|
||||||
REQUIRE(hit.has_value());
|
|
||||||
REQUIRE(hit->GetDistance() == distance(ray.GetOrigin(), hit->point));
|
|
||||||
REQUIRE(hit->point == Vector3f(1.5, 2, 0));
|
|
||||||
}
|
|
||||||
{
|
|
||||||
Ray ray(Vector3f(1.5, 1, -1), Vector3f(0, 0, 1));
|
|
||||||
std::optional<RayHit> hit = ray.IntersectTriangle(tri.vertices[0].position, tri.vertices[1].position, tri.vertices[2].position);
|
|
||||||
REQUIRE(hit.has_value());
|
|
||||||
REQUIRE(hit->GetDistance() == distance(ray.GetOrigin(), hit->point));
|
|
||||||
REQUIRE(hit->point == Vector3f(1.5, 1, 0));
|
|
||||||
}
|
|
||||||
// no intersections
|
|
||||||
{
|
|
||||||
Ray ray(Vector3f(5, 0, 0), Vector3f(0, 0, 1));
|
|
||||||
std::optional<RayHit> hit = ray.IntersectTriangle(tri.vertices[0].position, tri.vertices[1].position, tri.vertices[2].position);
|
|
||||||
REQUIRE(!hit.has_value());
|
|
||||||
}
|
|
||||||
{
|
|
||||||
Ray ray(Vector3f(1.5, 1, 0.5), Vector3f(0, 0, 1));
|
|
||||||
std::optional<RayHit> hit = ray.IntersectTriangle(tri.vertices[0].position, tri.vertices[1].position, tri.vertices[2].position);
|
|
||||||
REQUIRE(!hit.has_value());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("RayQuadIntersection")
|
|
||||||
{
|
|
||||||
auto cube = GeometryFactory::MakeCube();
|
|
||||||
std::optional<RayHit> hit;
|
|
||||||
// intersects
|
|
||||||
{
|
|
||||||
Ray ray(Vector3f(0), Vector3f(0, 0, 1));
|
|
||||||
// front face
|
|
||||||
hit = ray.IntersectQuad(cube.vertices[0].position, cube.vertices[1].position, cube.vertices[2].position,
|
|
||||||
cube.vertices[3].position);
|
|
||||||
REQUIRE(hit.has_value());
|
|
||||||
REQUIRE(hit->point == Vector3f(0, 0, 0.5));
|
|
||||||
}
|
|
||||||
// no intersections
|
|
||||||
{
|
|
||||||
Ray ray(Vector3f(0), Vector3f(0, 0, -1));
|
|
||||||
hit = ray.IntersectQuad(cube.vertices[0].position, cube.vertices[1].position, cube.vertices[2].position,
|
|
||||||
cube.vertices[3].position);
|
|
||||||
REQUIRE(!hit.has_value());
|
|
||||||
}
|
|
||||||
{
|
|
||||||
Ray ray(Vector3f(1, 1, 0), Vector3f(0, 0, 1));
|
|
||||||
hit = ray.IntersectQuad(cube.vertices[0].position, cube.vertices[1].position, cube.vertices[2].position,
|
|
||||||
cube.vertices[3].position);
|
|
||||||
REQUIRE(!hit.has_value());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("RayAABBIntersection")
|
|
||||||
{
|
|
||||||
auto sphere = GeometryFactory::MakeSphere(1, 32, 16);
|
|
||||||
sphere.CalculateAABB();
|
|
||||||
std::optional<RayHit> hit;
|
|
||||||
// intersects
|
|
||||||
{
|
|
||||||
RayHit h1, h2;
|
|
||||||
Ray ray(Vector3f(0, 0, -2), Vector3f(0, 0, 1));
|
|
||||||
REQUIRE(ray.IntersectAABB(sphere.aabb, h1, h2) == 2);
|
|
||||||
REQUIRE(h1.distance2 < h2.distance2);
|
|
||||||
REQUIRE(h1.point == Vector3f(0, 0, -1));
|
|
||||||
REQUIRE(h2.point == Vector3f(0, 0, 1));
|
|
||||||
auto p = ray.IntersectAABB(sphere.aabb);
|
|
||||||
REQUIRE(p->point == h1.point);
|
|
||||||
REQUIRE(p->distance2 == h1.distance2);
|
|
||||||
REQUIRE(p->GetDistance() == h1.GetDistance());
|
|
||||||
}
|
|
||||||
{
|
|
||||||
RayHit h1, h2;
|
|
||||||
Ray ray(Vector3f(0, 0, 1), Vector3f(0, 0, 1));
|
|
||||||
REQUIRE(ray.IntersectAABB(sphere.aabb, h1, h2) == 1);
|
|
||||||
REQUIRE(h1.distance2 == h2.distance2);
|
|
||||||
CompareVec3Approx(h1.point, h2.point);
|
|
||||||
REQUIRE(h1.point == Vector3f(0, 0, 1));
|
|
||||||
REQUIRE(ray.IntersectAABB(sphere.aabb)->distance2 == h1.distance2);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
RayHit h1, h2;
|
|
||||||
// inside sphere
|
|
||||||
Ray ray(Vector3f(0), Vector3f(0.3));
|
|
||||||
REQUIRE(ray.IntersectAABB(sphere.aabb, h1, h2) == 1);
|
|
||||||
REQUIRE(h1 == h2);
|
|
||||||
auto val = ray.IntersectAABB(sphere.aabb);
|
|
||||||
REQUIRE(val.has_value());
|
|
||||||
REQUIRE_THAT(val->distance2, Catch::Matchers::WithinRel(h1.distance2));
|
|
||||||
CompareVec3Approx(val->point, h1.point);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
RayHit h1, h2;
|
|
||||||
Ray ray(Vector3f(2, -0.5, 1.5), Vector3f(-2, 0.5, -1.5));
|
|
||||||
REQUIRE(ray.IntersectAABB(sphere.aabb, h1, h2) == 2);
|
|
||||||
REQUIRE(h1.distance2 < h2.distance2);
|
|
||||||
auto val = ray.IntersectAABB(sphere.aabb);
|
|
||||||
REQUIRE(val.has_value());
|
|
||||||
REQUIRE(val->distance2 == h1.distance2);
|
|
||||||
REQUIRE_THAT(val->GetDistance(), Catch::Matchers::WithinRel(h1.GetDistance()));
|
|
||||||
CompareVec3Approx(val->point, h1.point);
|
|
||||||
}
|
|
||||||
// no intersections
|
|
||||||
{
|
|
||||||
RayHit h1, h2;
|
|
||||||
Ray ray(Vector3f(3, 0, 1), Vector3f(0, 0, 1));
|
|
||||||
REQUIRE(ray.IntersectAABB(sphere.aabb, h1, h2) == 0);
|
|
||||||
REQUIRE(!ray.IntersectAABB(sphere.aabb).has_value());
|
|
||||||
}
|
|
||||||
{
|
|
||||||
RayHit h1, h2;
|
|
||||||
Ray ray(Vector3f(0, 0, 1.1), Vector3f(0, 0, 1));
|
|
||||||
REQUIRE(ray.IntersectAABB(sphere.aabb, h1, h2) == 0);
|
|
||||||
REQUIRE(!ray.IntersectAABB(sphere.aabb).has_value());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("RayPlaneIntersection")
|
|
||||||
{
|
|
||||||
Vector3f pOrigin = Vector3f(0);
|
|
||||||
Vector3f pNorm = Vector3f(0, 1, 0);
|
|
||||||
{
|
|
||||||
Ray ray(Vector3f(2, -2, 2), Vector3f(0, 1, 0));
|
|
||||||
auto hit = ray.IntersectPlane(pOrigin, pNorm);
|
|
||||||
REQUIRE(hit.has_value());
|
|
||||||
REQUIRE(hit->normal == pNorm);
|
|
||||||
REQUIRE(hit->GetDistance() == 2.f);
|
|
||||||
REQUIRE(hit->point == Vector3f(2, 0, 2));
|
|
||||||
}
|
|
||||||
{
|
|
||||||
Ray ray(Vector3f(2, -2, 2), Vector3f(1, 0, 0));
|
|
||||||
REQUIRE(!ray.IntersectPlane(pOrigin, pNorm));
|
|
||||||
}
|
|
||||||
{
|
|
||||||
Ray ray(Vector3f(0), Vector3f(1, 0, 0));
|
|
||||||
REQUIRE(!ray.IntersectPlane(pOrigin, pNorm));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user