test/core/container: Refactor for multiple container types

This commit is contained in:
Yawning Angel
2024-02-16 18:58:02 +09:00
parent 9251e06143
commit db3279e7da
2 changed files with 35 additions and 20 deletions
@@ -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)
}
+10 -20
View File
@@ -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)