Fixed tests

This commit is contained in:
gingerBill
2026-03-12 16:55:46 +00:00
parent 6898cbe678
commit 6e9d6bfbe5
2 changed files with 15 additions and 12 deletions

View File

@@ -1404,8 +1404,8 @@ resize_fixed_capacity_dynamic_array :: proc "contextless" (array: ^$T/[dynamic;
if raw.len < length {
size_of_elem :: size_of(E)
num_reused := min(N, length) - a.len
intrinsics.mem_zero(([^]byte)(a.data)[a.len*size_of_elem:], num_reused*size_of_elem)
num_reused := min(N, length) - raw.len
intrinsics.mem_zero(([^]byte)(a.data)[raw.len*size_of_elem:], num_reused*size_of_elem)
}
new_length := clamp(length, 0, N)
raw.len = new_length

View File

@@ -26,11 +26,11 @@ test_fixed_capacity_dynamic_array_inject_at :: proc(t: ^testing.T) {
array: [dynamic; 13]int
append(&array, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
testing.expect(t, inject_at(&array, 0, 0), "Expected to be able to inject into small array")
testing.expect(t, inject_at(&array, 0, 0), "Expected to be able to inject into fixed capacity dynamic array")
testing.expect(t, slice_equal(array[:], []int { 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }))
testing.expect(t, inject_at(&array, 0, 5), "Expected to be able to inject into small array")
testing.expect(t, inject_at(&array, 0, 5), "Expected to be able to inject into fixed capacity dynamic array")
testing.expect(t, slice_equal(array[:], []int { 0, 0, 1, 2, 3, 0, 4, 5, 6, 7, 8, 9 }))
testing.expect(t, inject_at(&array, 0, len(array)), "Expected to be able to inject into small array")
testing.expect(t, inject_at(&array, 0, len(array)), "Expected to be able to inject into fixed capacity dynamic array")
testing.expect(t, slice_equal(array[:], []int { 0, 0, 1, 2, 3, 0, 4, 5, 6, 7, 8, 9, 0 }))
}
@@ -38,18 +38,21 @@ test_fixed_capacity_dynamic_array_inject_at :: proc(t: ^testing.T) {
test_fixed_capacity_dynamic_array_push_back_elems :: proc(t: ^testing.T) {
array: [dynamic; 2]int
testing.expect(t, slice_equal(array[:], []int { }))
testing.expect(t, append(&array, 0), "Expected to be able to append to empty small array")
testing.expect(t, append(&array, 0) == 1, "Expected to be able to append to empty fixed capacity dynamic array")
testing.expect(t, slice_equal(array[:], []int { 0 }))
testing.expect(t, append(&array, 1, 2) == false, "Expected to fail appending multiple elements beyond capacity of small array")
testing.expect(t, append(&array, 1), "Expected to be able to append to small array")
testing.expect(t, append(&array, 1) == 1, "Expected to be able to append to fixed capacity dynamic array")
testing.expect(t, slice_equal(array[:], []int { 0, 1 }))
testing.expect(t, append(&array, 1) == false, "Expected to fail appending to full small array")
testing.expect(t, append(&array, 1, 2) == false, "Expected to fail appending multiple elements to full small array")
testing.expect(t, append(&array, 1, 2) == 1, "Expected to fail appending multiple elements beyond capacity of fixed capacity dynamic array")
clear(&array)
testing.expect(t, append(&array, 1) == 1, "Expected to be able to append to fixed capacity dynamic array")
testing.expect(t, append(&array, 2) == 1, "Expected to be able to append to fixed capacity dynamic array")
testing.expect(t, append(&array, 1) != 1, "Expected to fail appending to full fixed capacity dynamic array")
testing.expect(t, append(&array, 1, 2) != 2, "Expected to fail appending multiple elements to full fixed capacity dynamic array")
clear(&array)
testing.expect(t, slice_equal(array[:], []int { }))
testing.expect(t, append(&array, 1, 2, 3) == false, "Expected to fail appending multiple elements to empty small array")
testing.expect(t, append(&array, 1, 2, 3) != 3, "Expected to fail appending multiple elements to empty fixed capacity dynamic array")
testing.expect(t, slice_equal(array[:], []int { }))
testing.expect(t, append(&array, 1, 2), "Expected to be able to append multiple elements to empty small array")
testing.expect(t, append(&array, 1, 2) == 2, "Expected to be able to append multiple elements to empty fixed capacity dynamic array")
testing.expect(t, slice_equal(array[:], []int { 1, 2 }))
}