summaryrefslogtreecommitdiff
path: root/src/tests/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/common')
-rw-r--r--src/tests/common/container_hash.cpp44
-rw-r--r--src/tests/common/range_map.cpp20
-rw-r--r--src/tests/common/ring_buffer.cpp2
-rw-r--r--src/tests/common/scratch_buffer.cpp2
4 files changed, 56 insertions, 12 deletions
diff --git a/src/tests/common/container_hash.cpp b/src/tests/common/container_hash.cpp
new file mode 100644
index 000000000..dc45565ef
--- /dev/null
+++ b/src/tests/common/container_hash.cpp
@@ -0,0 +1,44 @@
1// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#include <catch2/catch_test_macros.hpp>
5
6#include "common/common_types.h"
7#include "common/container_hash.h"
8
9TEST_CASE("ContainerHash", "[common]") {
10 constexpr std::array<u8, 32> U8Values{
11 114, 10, 238, 189, 199, 242, 86, 96, 53, 193, 195, 247, 249, 56, 253, 61,
12 205, 3, 172, 4, 210, 197, 43, 72, 103, 8, 99, 89, 5, 97, 68, 196,
13 };
14 constexpr std::array<u16, 32> U16Values{
15 61586, 49151, 3313, 11641, 31695, 54795, 46764, 20965, 23287, 14039, 19265,
16 49093, 58932, 22518, 27139, 42825, 57417, 54237, 48057, 14586, 42813, 32994,
17 33970, 45501, 5619, 15895, 33227, 27509, 25391, 37275, 60218, 17599,
18 };
19 constexpr std::array<u32, 32> U32Values{
20 3838402410U, 2029146863U, 1730869921U, 985528872U, 186773874U, 2094639868U, 3324775932U,
21 1795512424U, 2571165571U, 3256934519U, 2358691590U, 2752682538U, 1484336451U, 378124520U,
22 3463015699U, 3395942161U, 1263211979U, 3473632889U, 3039822212U, 2068707357U, 2223837919U,
23 1823232191U, 1583884041U, 1264393380U, 4087566993U, 3188607101U, 3933680362U, 1464520765U,
24 1786838406U, 1311734848U, 2773642241U, 3993641692U,
25 };
26 constexpr std::array<u64, 32> U64Values{
27 5908025796157537817ULL, 10947547850358315100ULL, 844798943576724669ULL,
28 7999662937458523703ULL, 4006550374705895164ULL, 1832550525423503632ULL,
29 9323088254855830976ULL, 12028890075598379412ULL, 6021511300787826236ULL,
30 7864675007938747948ULL, 18099387408859708806ULL, 6438638299316820708ULL,
31 9029399285648501543ULL, 18195459433089960253ULL, 17214335092761966083ULL,
32 5549347964591337833ULL, 14899526073304962015ULL, 5058883181561464475ULL,
33 7436311795731206973ULL, 7535129567768649864ULL, 1287169596809258072ULL,
34 8237671246353565927ULL, 1715230541978016153ULL, 8443157615068813300ULL,
35 6098675262328527839ULL, 704652094100376853ULL, 1303411723202926503ULL,
36 7808312933946424854ULL, 6863726670433556594ULL, 9870361541383217495ULL,
37 9273671094091079488ULL, 17541434976160119010ULL,
38 };
39
40 REQUIRE(Common::HashValue(U8Values) == 5867183267093890552ULL);
41 REQUIRE(Common::HashValue(U16Values) == 9594135570564347135ULL);
42 REQUIRE(Common::HashValue(U32Values) == 13123757214696618460ULL);
43 REQUIRE(Common::HashValue(U64Values) == 7296500016546938380ULL);
44}
diff --git a/src/tests/common/range_map.cpp b/src/tests/common/range_map.cpp
index d301ac5f6..faaefd49f 100644
--- a/src/tests/common/range_map.cpp
+++ b/src/tests/common/range_map.cpp
@@ -21,9 +21,9 @@ TEST_CASE("Range Map: Setup", "[video_core]") {
21 my_map.Map(4000, 4500, MappedEnum::Valid_2); 21 my_map.Map(4000, 4500, MappedEnum::Valid_2);
22 my_map.Map(4200, 4400, MappedEnum::Valid_2); 22 my_map.Map(4200, 4400, MappedEnum::Valid_2);
23 my_map.Map(4200, 4400, MappedEnum::Valid_1); 23 my_map.Map(4200, 4400, MappedEnum::Valid_1);
24 REQUIRE(my_map.GetContinousSizeFrom(4200) == 200); 24 REQUIRE(my_map.GetContinuousSizeFrom(4200) == 200);
25 REQUIRE(my_map.GetContinousSizeFrom(3000) == 200); 25 REQUIRE(my_map.GetContinuousSizeFrom(3000) == 200);
26 REQUIRE(my_map.GetContinousSizeFrom(2900) == 0); 26 REQUIRE(my_map.GetContinuousSizeFrom(2900) == 0);
27 27
28 REQUIRE(my_map.GetValueAt(2900) == MappedEnum::Invalid); 28 REQUIRE(my_map.GetValueAt(2900) == MappedEnum::Invalid);
29 REQUIRE(my_map.GetValueAt(3100) == MappedEnum::Valid_1); 29 REQUIRE(my_map.GetValueAt(3100) == MappedEnum::Valid_1);
@@ -38,20 +38,20 @@ TEST_CASE("Range Map: Setup", "[video_core]") {
38 38
39 my_map.Unmap(0, 6000); 39 my_map.Unmap(0, 6000);
40 for (u64 address = 0; address < 10000; address += 1000) { 40 for (u64 address = 0; address < 10000; address += 1000) {
41 REQUIRE(my_map.GetContinousSizeFrom(address) == 0); 41 REQUIRE(my_map.GetContinuousSizeFrom(address) == 0);
42 } 42 }
43 43
44 my_map.Map(1000, 3000, MappedEnum::Valid_1); 44 my_map.Map(1000, 3000, MappedEnum::Valid_1);
45 my_map.Map(4000, 5000, MappedEnum::Valid_1); 45 my_map.Map(4000, 5000, MappedEnum::Valid_1);
46 my_map.Map(2500, 4100, MappedEnum::Valid_1); 46 my_map.Map(2500, 4100, MappedEnum::Valid_1);
47 REQUIRE(my_map.GetContinousSizeFrom(1000) == 4000); 47 REQUIRE(my_map.GetContinuousSizeFrom(1000) == 4000);
48 48
49 my_map.Map(1000, 3000, MappedEnum::Valid_1); 49 my_map.Map(1000, 3000, MappedEnum::Valid_1);
50 my_map.Map(4000, 5000, MappedEnum::Valid_2); 50 my_map.Map(4000, 5000, MappedEnum::Valid_2);
51 my_map.Map(2500, 4100, MappedEnum::Valid_3); 51 my_map.Map(2500, 4100, MappedEnum::Valid_3);
52 REQUIRE(my_map.GetContinousSizeFrom(1000) == 1500); 52 REQUIRE(my_map.GetContinuousSizeFrom(1000) == 1500);
53 REQUIRE(my_map.GetContinousSizeFrom(2500) == 1600); 53 REQUIRE(my_map.GetContinuousSizeFrom(2500) == 1600);
54 REQUIRE(my_map.GetContinousSizeFrom(4100) == 900); 54 REQUIRE(my_map.GetContinuousSizeFrom(4100) == 900);
55 REQUIRE(my_map.GetValueAt(900) == MappedEnum::Invalid); 55 REQUIRE(my_map.GetValueAt(900) == MappedEnum::Invalid);
56 REQUIRE(my_map.GetValueAt(1000) == MappedEnum::Valid_1); 56 REQUIRE(my_map.GetValueAt(1000) == MappedEnum::Valid_1);
57 REQUIRE(my_map.GetValueAt(2500) == MappedEnum::Valid_3); 57 REQUIRE(my_map.GetValueAt(2500) == MappedEnum::Valid_3);
@@ -59,8 +59,8 @@ TEST_CASE("Range Map: Setup", "[video_core]") {
59 REQUIRE(my_map.GetValueAt(5000) == MappedEnum::Invalid); 59 REQUIRE(my_map.GetValueAt(5000) == MappedEnum::Invalid);
60 60
61 my_map.Map(2000, 6000, MappedEnum::Valid_3); 61 my_map.Map(2000, 6000, MappedEnum::Valid_3);
62 REQUIRE(my_map.GetContinousSizeFrom(1000) == 1000); 62 REQUIRE(my_map.GetContinuousSizeFrom(1000) == 1000);
63 REQUIRE(my_map.GetContinousSizeFrom(3000) == 3000); 63 REQUIRE(my_map.GetContinuousSizeFrom(3000) == 3000);
64 REQUIRE(my_map.GetValueAt(1000) == MappedEnum::Valid_1); 64 REQUIRE(my_map.GetValueAt(1000) == MappedEnum::Valid_1);
65 REQUIRE(my_map.GetValueAt(1999) == MappedEnum::Valid_1); 65 REQUIRE(my_map.GetValueAt(1999) == MappedEnum::Valid_1);
66 REQUIRE(my_map.GetValueAt(1500) == MappedEnum::Valid_1); 66 REQUIRE(my_map.GetValueAt(1500) == MappedEnum::Valid_1);
diff --git a/src/tests/common/ring_buffer.cpp b/src/tests/common/ring_buffer.cpp
index 7dee988c8..e85f9977b 100644
--- a/src/tests/common/ring_buffer.cpp
+++ b/src/tests/common/ring_buffer.cpp
@@ -52,7 +52,7 @@ TEST_CASE("RingBuffer: Basic Tests", "[common]") {
52 52
53 REQUIRE(buf.Size() == 1U); 53 REQUIRE(buf.Size() == 1U);
54 54
55 // Pushing more values than space available should partially suceed. 55 // Pushing more values than space available should partially succeed.
56 { 56 {
57 std::vector<char> to_push(6); 57 std::vector<char> to_push(6);
58 std::iota(to_push.begin(), to_push.end(), 88); 58 std::iota(to_push.begin(), to_push.end(), 88);
diff --git a/src/tests/common/scratch_buffer.cpp b/src/tests/common/scratch_buffer.cpp
index 132f139fa..26e401760 100644
--- a/src/tests/common/scratch_buffer.cpp
+++ b/src/tests/common/scratch_buffer.cpp
@@ -191,7 +191,7 @@ TEST_CASE("ScratchBuffer: Span Writes", "[common]") {
191 191
192 for (size_t i = 0; i < buf_span.size(); ++i) { 192 for (size_t i = 0; i < buf_span.size(); ++i) {
193 const auto new_value = static_cast<u8>(i + 1U); 193 const auto new_value = static_cast<u8>(i + 1U);
194 // Writes to a span of the scratch buffer will propogate to the buffer itself 194 // Writes to a span of the scratch buffer will propagate to the buffer itself
195 buf_span[i] = new_value; 195 buf_span[i] = new_value;
196 REQUIRE(buf[i] == new_value); 196 REQUIRE(buf[i] == new_value);
197 } 197 }