summaryrefslogtreecommitdiffstats
path: root/src/tests/common/range_map.cpp
diff options
context:
space:
mode:
authorFernando Sahmkow <fsahmkow27@gmail.com>2022-11-17 16:36:53 +0100
committerFernando Sahmkow <fsahmkow27@gmail.com>2023-01-01 22:43:57 +0100
commit18637766efd1ff9a0c22967553983cfda69c96ca (patch)
tree142d4cab2de27ce250d246f0355fec97748a7bcf /src/tests/common/range_map.cpp
parentMacroHLE: Add HLE replacement for base vertex and base instance. (diff)
downloadyuzu-18637766efd1ff9a0c22967553983cfda69c96ca.tar
yuzu-18637766efd1ff9a0c22967553983cfda69c96ca.tar.gz
yuzu-18637766efd1ff9a0c22967553983cfda69c96ca.tar.bz2
yuzu-18637766efd1ff9a0c22967553983cfda69c96ca.tar.lz
yuzu-18637766efd1ff9a0c22967553983cfda69c96ca.tar.xz
yuzu-18637766efd1ff9a0c22967553983cfda69c96ca.tar.zst
yuzu-18637766efd1ff9a0c22967553983cfda69c96ca.zip
Diffstat (limited to 'src/tests/common/range_map.cpp')
-rw-r--r--src/tests/common/range_map.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/tests/common/range_map.cpp b/src/tests/common/range_map.cpp
new file mode 100644
index 000000000..5a4630a38
--- /dev/null
+++ b/src/tests/common/range_map.cpp
@@ -0,0 +1,70 @@
+// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#include <stdexcept>
+
+#include <catch2/catch.hpp>
+
+#include "common/range_map.h"
+
+enum class MappedEnum : u32 {
+ Invalid = 0,
+ Valid_1 = 1,
+ Valid_2 = 2,
+ Valid_3 = 3,
+};
+
+TEST_CASE("Range Map: Setup", "[video_core]") {
+ Common::RangeMap<u64, MappedEnum> my_map(MappedEnum::Invalid);
+ my_map.Map(3000, 3500, MappedEnum::Valid_1);
+ my_map.Unmap(3200, 3600);
+ my_map.Map(4000, 4500, MappedEnum::Valid_2);
+ my_map.Map(4200, 4400, MappedEnum::Valid_2);
+ my_map.Map(4200, 4400, MappedEnum::Valid_1);
+ REQUIRE(my_map.GetContinousSizeFrom(4200) == 200);
+ REQUIRE(my_map.GetContinousSizeFrom(3000) == 200);
+ REQUIRE(my_map.GetContinousSizeFrom(2900) == 0);
+
+ REQUIRE(my_map.GetValueAt(2900) == MappedEnum::Invalid);
+ REQUIRE(my_map.GetValueAt(3100) == MappedEnum::Valid_1);
+ REQUIRE(my_map.GetValueAt(3000) == MappedEnum::Valid_1);
+ REQUIRE(my_map.GetValueAt(3200) == MappedEnum::Invalid);
+
+ REQUIRE(my_map.GetValueAt(4199) == MappedEnum::Valid_2);
+ REQUIRE(my_map.GetValueAt(4200) == MappedEnum::Valid_1);
+ REQUIRE(my_map.GetValueAt(4400) == MappedEnum::Valid_2);
+ REQUIRE(my_map.GetValueAt(4500) == MappedEnum::Invalid);
+ REQUIRE(my_map.GetValueAt(4600) == MappedEnum::Invalid);
+
+ my_map.Unmap(0, 6000);
+ for (u64 address = 0; address < 10000; address += 1000) {
+ REQUIRE(my_map.GetContinousSizeFrom(address) == 0);
+ }
+
+ my_map.Map(1000, 3000, MappedEnum::Valid_1);
+ my_map.Map(4000, 5000, MappedEnum::Valid_1);
+ my_map.Map(2500, 4100, MappedEnum::Valid_1);
+ REQUIRE(my_map.GetContinousSizeFrom(1000) == 4000);
+
+ my_map.Map(1000, 3000, MappedEnum::Valid_1);
+ my_map.Map(4000, 5000, MappedEnum::Valid_2);
+ my_map.Map(2500, 4100, MappedEnum::Valid_3);
+ REQUIRE(my_map.GetContinousSizeFrom(1000) == 1500);
+ REQUIRE(my_map.GetContinousSizeFrom(2500) == 1600);
+ REQUIRE(my_map.GetContinousSizeFrom(4100) == 900);
+ REQUIRE(my_map.GetValueAt(900) == MappedEnum::Invalid);
+ REQUIRE(my_map.GetValueAt(1000) == MappedEnum::Valid_1);
+ REQUIRE(my_map.GetValueAt(2500) == MappedEnum::Valid_3);
+ REQUIRE(my_map.GetValueAt(4100) == MappedEnum::Valid_2);
+ REQUIRE(my_map.GetValueAt(5000) == MappedEnum::Invalid);
+
+ my_map.Map(2000, 6000, MappedEnum::Valid_3);
+ REQUIRE(my_map.GetContinousSizeFrom(1000) == 1000);
+ REQUIRE(my_map.GetContinousSizeFrom(3000) == 3000);
+ REQUIRE(my_map.GetValueAt(1000) == MappedEnum::Valid_1);
+ REQUIRE(my_map.GetValueAt(1999) == MappedEnum::Valid_1);
+ REQUIRE(my_map.GetValueAt(1500) == MappedEnum::Valid_1);
+ REQUIRE(my_map.GetValueAt(2001) == MappedEnum::Valid_3);
+ REQUIRE(my_map.GetValueAt(5999) == MappedEnum::Valid_3);
+ REQUIRE(my_map.GetValueAt(6000) == MappedEnum::Invalid);
+}