aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLaytan <laytanlaats@hotmail.com>2025-01-05 14:27:44 +0100
committerGitHub <noreply@github.com>2025-01-05 14:27:44 +0100
commitbf77036cb044aafbd0eaab21879d9f867a53d76e (patch)
tree5822e0800fc0efbed1c5345c2aaa453e4033115a /tests
parentaa4bc10a84bcb4df5f63033243c3ea9d3f4fe0c4 (diff)
parent1550eced046c61fed1121fa6245af6d564ba3149 (diff)
Merge pull request #4651 from flga/runtime_map_get
runtime: map_cell_index_static produced wrong results when the number of elements per cell was a power of 2
Diffstat (limited to 'tests')
-rw-r--r--tests/core/runtime/test_core_runtime.odin99
1 files changed, 98 insertions, 1 deletions
diff --git a/tests/core/runtime/test_core_runtime.odin b/tests/core/runtime/test_core_runtime.odin
index 84fd044cf..c1a3ed718 100644
--- a/tests/core/runtime/test_core_runtime.odin
+++ b/tests/core/runtime/test_core_runtime.odin
@@ -63,4 +63,101 @@ test_init_cap_map_dynarray :: proc(t: ^testing.T) {
defer delete(d2)
testing.expect(t, cap(d2) == 0)
testing.expect(t, d2.allocator.procedure == ally.procedure)
-} \ No newline at end of file
+}
+
+@(test)
+test_map_get :: proc(t: ^testing.T) {
+ check :: proc(t: ^testing.T, m: map[$K]$V, loc := #caller_location) {
+ for k, v in m {
+ got_key, got_val, ok := runtime.map_get(m, k)
+ testing.expect_value(t, got_key, k, loc = loc)
+ testing.expect_value(t, got_val, v, loc = loc)
+ testing.expect(t, ok, loc = loc)
+ }
+ }
+
+ // small keys & values
+ {
+ m := map[int]int{
+ 1 = 10,
+ 2 = 20,
+ 3 = 30,
+ }
+ defer delete(m)
+ check(t, m)
+ }
+
+ // small keys; 2 values per cell
+ {
+ m := map[int][3]int{
+ 1 = [3]int{10, 100, 1000},
+ 2 = [3]int{20, 200, 2000},
+ 3 = [3]int{30, 300, 3000},
+ }
+ defer delete(m)
+ check(t, m)
+ }
+
+ // 2 keys per cell; small values
+ {
+ m := map[[3]int]int{
+ [3]int{10, 100, 1000} = 1,
+ [3]int{20, 200, 2000} = 2,
+ [3]int{30, 300, 3000} = 3,
+ }
+ defer delete(m)
+ check(t, m)
+ }
+
+
+ // small keys; 3 values per cell
+ {
+ val :: struct #packed {
+ a, b: int,
+ c: i32,
+ }
+ m := map[int]val{
+ 1 = val{10, 100, 1000},
+ 2 = val{20, 200, 2000},
+ 3 = val{30, 300, 3000},
+ }
+ defer delete(m)
+ check(t, m)
+ }
+
+ // 3 keys per cell; small values
+ {
+ key :: struct #packed {
+ a, b: int,
+ c: i32,
+ }
+ m := map[key]int{
+ key{10, 100, 1000} = 1,
+ key{20, 200, 2000} = 2,
+ key{30, 300, 3000} = 3,
+ }
+ defer delete(m)
+ check(t, m)
+ }
+
+ // small keys; value bigger than a chacheline
+ {
+ m := map[int][9]int{
+ 1 = [9]int{10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000},
+ 2 = [9]int{20, 200, 2000, 20000, 200000, 2000000, 20000000, 200000000, 2000000000},
+ 3 = [9]int{30, 300, 3000, 30000, 300000, 3000000, 30000000, 300000000, 3000000000},
+ }
+ defer delete(m)
+ check(t, m)
+ }
+ // keys bigger than a chacheline; small values
+ {
+ m := map[[9]int]int{
+ [9]int{10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000} = 1,
+ [9]int{20, 200, 2000, 20000, 200000, 2000000, 20000000, 200000000, 2000000000} = 2,
+ [9]int{30, 300, 3000, 30000, 300000, 3000000, 30000000, 300000000, 3000000000} = 3,
+ }
+ defer delete(m)
+ check(t, m)
+ }
+}