From db3279e7da4d422005fa9224a9fb8c2301d88837 Mon Sep 17 00:00:00 2001 From: Yawning Angel Date: Fri, 16 Feb 2024 18:58:02 +0900 Subject: [PATCH] test/core/container: Refactor for multiple container types --- tests/core/container/test_core_container.odin | 25 ++++++++++++++++ .../core/container/test_core_small_array.odin | 30 +++++++------------ 2 files changed, 35 insertions(+), 20 deletions(-) create mode 100644 tests/core/container/test_core_container.odin diff --git a/tests/core/container/test_core_container.odin b/tests/core/container/test_core_container.odin new file mode 100644 index 000000000..9065bed2c --- /dev/null +++ b/tests/core/container/test_core_container.odin @@ -0,0 +1,25 @@ +package test_core_container + +import "core:fmt" +import "core:testing" + +import tc "tests:common" + +expect_equal :: proc(t: ^testing.T, the_slice, expected: []int, loc := #caller_location) { + _eq :: proc(a, b: []int) -> bool { + if len(a) != len(b) do return false + for a, i in a { + if b[i] != a do return false + } + return true + } + tc.expect(t, _eq(the_slice, expected), fmt.tprintf("Expected %v, got %v\n", the_slice, expected), loc) +} + +main :: proc() { + t := testing.T{} + + test_small_array(&t) + + tc.report(&t) +} diff --git a/tests/core/container/test_core_small_array.odin b/tests/core/container/test_core_small_array.odin index 88bc8e532..78998de16 100644 --- a/tests/core/container/test_core_small_array.odin +++ b/tests/core/container/test_core_small_array.odin @@ -1,29 +1,19 @@ -package test_core_compress +package test_core_container -import "core:fmt" import "core:testing" import "core:container/small_array" + import tc "tests:common" -main :: proc() { - t := testing.T{} - test_small_array_removes(&t) - test_small_array_inject_at(&t) - tc.report(&t) +@(test) +test_small_array :: proc(t: ^testing.T) { + tc.log(t, "Testing small_array") + + test_small_array_removes(t) + test_small_array_inject_at(t) } -expect_equal :: proc(t: ^testing.T, the_slice, expected: []int, loc := #caller_location) { - _eq :: proc(a, b: []int) -> bool { - if len(a) != len(b) do return false - for a, i in a { - if b[i] != a do return false - } - return true - } - tc.expect(t, _eq(the_slice, expected), fmt.tprintf("Expected %v, got %v\n", the_slice, expected), loc) -} - -@test +@(test) test_small_array_removes :: proc(t: ^testing.T) { array: small_array.Small_Array(10, int) small_array.append(&array, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9) @@ -42,7 +32,7 @@ test_small_array_removes :: proc(t: ^testing.T) { expect_equal(t, small_array.slice(&array), []int { 9, 2, 7, 4 }) } -@test +@(test) test_small_array_inject_at :: proc(t: ^testing.T) { array: small_array.Small_Array(13, int) small_array.append(&array, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9)