diff options
| author | thetarnav <gthetarnav@gmail.com> | 2025-11-02 12:13:11 +0100 |
|---|---|---|
| committer | thetarnav <gthetarnav@gmail.com> | 2025-11-02 12:13:11 +0100 |
| commit | e364e76f7f8978ffef78321f962324a4fc4dcaae (patch) | |
| tree | e7de4d1fd0989659414342f65337b552735f2dd6 /tests | |
| parent | 91d923bd8f89dd11208d7d67783e5085955377fc (diff) | |
Add `inject_at_soa` and `append_nothing_soa` procedures
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/core/runtime/test_core_runtime.odin | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/core/runtime/test_core_runtime.odin b/tests/core/runtime/test_core_runtime.odin index 881b5f41a..f3559954d 100644 --- a/tests/core/runtime/test_core_runtime.odin +++ b/tests/core/runtime/test_core_runtime.odin @@ -293,6 +293,65 @@ test_soa_array_allocator_resize_overlapping :: proc(t: ^testing.T) { } @(test) +test_soa_array_inject_at_elem :: proc(t: ^testing.T) { + + V :: struct {a: u8, b: f32} + + array := make(#soa[dynamic]V, 0, 2) + defer delete(array) + + append(&array, V{1, 1.5}, V{2, 2.5}, V{3, 3.5}) + + expect_inject(t, &array, 0, {0, 0.5}, {{0, 0.5}, {1, 1.5}, {2, 2.5}, {3, 3.5}}) + expect_inject(t, &array, 2, {5, 5.5}, {{0, 0.5}, {1, 1.5}, {5, 5.5}, {2, 2.5}, {3, 3.5}}) + expect_inject(t, &array, 5, {9, 9.5}, {{0, 0.5}, {1, 1.5}, {5, 5.5}, {2, 2.5}, {3, 3.5}, {9, 9.5}}) + + expect_inject :: proc(t: ^testing.T, arr: ^#soa[dynamic]V, index: int, arg: V, expected_slice: []V) { + ok, err := inject_at_soa(arr, index, arg) + testing.expectf(t, ok == true, "Injection of %v at index %d failed", arg, index) + testing.expectf(t, err == nil, "Injection allocation of %v at index %d failed: %v", arg, index, err) + equals := len(arr) == len(expected_slice) + for e, i in expected_slice { + if arr[i] != e { + equals = false + break + } + } + testing.expectf(t, equals, "After injection of %v at index %d, expected array to be\n&%v, got\n%v", arg, index, expected_slice, arr) + } +} + +@(test) +test_soa_array_inject_at_elems :: proc(t: ^testing.T) { + + V :: struct {a: u8, b: f32} + + array := make(#soa[dynamic]V, 0, 2) + defer delete(array) + + append(&array, V{1, 1.5}, V{2, 2.5}, V{3, 3.5}) + + expect_inject(t, &array, 0, {{0, 0.5}}, {{0, 0.5}, {1, 1.5}, {2, 2.5}, {3, 3.5}}) + expect_inject(t, &array, 2, {{5, 5.5}, {6, 6.5}}, {{0, 0.5}, {1, 1.5}, {5, 5.5}, {6, 6.5}, {2, 2.5}, {3, 3.5}}) + expect_inject(t, &array, 6, {{9, 9.5}, {10, 10.5}}, {{0, 0.5}, {1, 1.5}, {5, 5.5}, {6, 6.5}, {2, 2.5}, {3, 3.5}, {9, 9.5}, {10, 10.5}}) + expect_inject(t, &array, 6, {}, {{0, 0.5}, {1, 1.5}, {5, 5.5}, {6, 6.5}, {2, 2.5}, {3, 3.5}, {9, 9.5}, {10, 10.5}}) + + expect_inject :: proc(t: ^testing.T, arr: ^#soa[dynamic]V, index: int, args: []V, expected_slice: []V) { + ok, err := inject_at_soa(arr, index, ..args) + testing.expectf(t, ok == true, "Injection of %v at index %d failed", args, index) + testing.expectf(t, err == nil, "Injection allocation of %v at index %d failed: %v", args, index, err) + equals := len(arr) == len(expected_slice) + for e, i in expected_slice { + if arr[i] != e { + equals = false + break + } + } + testing.expectf(t, equals, "After injection of %v at index %d, expected array to be\n&%v, got\n%v", args, index, expected_slice, arr) + } +} + +@(test) test_memory_equal :: proc(t: ^testing.T) { data: [256]u8 cmp: [256]u8 |