mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
More soa tests
This commit is contained in:
@@ -179,6 +179,22 @@ test_map_get :: proc(t: ^testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_soa_make_len :: proc(t: ^testing.T) {
|
||||||
|
|
||||||
|
array, err := make(#soa[dynamic][2]int, 2)
|
||||||
|
defer delete(array)
|
||||||
|
array[0] = [2]int{1, 2}
|
||||||
|
array[1] = [2]int{3, 4}
|
||||||
|
|
||||||
|
testing.expect_value(t, err, nil)
|
||||||
|
testing.expect_value(t, len(array), 2)
|
||||||
|
testing.expect_value(t, cap(array), 2)
|
||||||
|
|
||||||
|
testing.expect_value(t, array[0], [2]int{1, 2})
|
||||||
|
testing.expect_value(t, array[1], [2]int{3, 4})
|
||||||
|
}
|
||||||
|
|
||||||
@(test)
|
@(test)
|
||||||
test_soa_array_allocator_resize :: proc(t: ^testing.T) {
|
test_soa_array_allocator_resize :: proc(t: ^testing.T) {
|
||||||
|
|
||||||
@@ -186,53 +202,60 @@ test_soa_array_allocator_resize :: proc(t: ^testing.T) {
|
|||||||
context.allocator = runtime.arena_allocator(&arena)
|
context.allocator = runtime.arena_allocator(&arena)
|
||||||
defer runtime.arena_destroy(&arena)
|
defer runtime.arena_destroy(&arena)
|
||||||
|
|
||||||
{
|
// |1 3 _ 2 4 _|
|
||||||
// |1 3 _ 2 4 _|
|
// |1 3 _ _ 2 4 _ _|
|
||||||
// |1 3 _ _ 2 4 _ _|
|
|
||||||
|
|
||||||
array, err := make(#soa[dynamic][2]int, 2, 3)
|
array, err := make(#soa[dynamic][2]int, 2, 3)
|
||||||
array[0] = [2]int{1, 2}
|
defer delete(array)
|
||||||
array[1] = [2]int{3, 4}
|
array[0] = [2]int{1, 2}
|
||||||
|
array[1] = [2]int{3, 4}
|
||||||
|
|
||||||
testing.expect_value(t, err, nil)
|
testing.expect_value(t, err, nil)
|
||||||
testing.expect_value(t, len(array), 2)
|
testing.expect_value(t, len(array), 2)
|
||||||
testing.expect_value(t, cap(array), 3)
|
testing.expect_value(t, cap(array), 3)
|
||||||
|
|
||||||
err = resize(&array, 4)
|
err = resize(&array, 4)
|
||||||
|
|
||||||
testing.expect_value(t, err, nil)
|
testing.expect_value(t, err, nil)
|
||||||
testing.expect_value(t, len(array), 4)
|
testing.expect_value(t, len(array), 4)
|
||||||
testing.expect_value(t, cap(array), 4)
|
testing.expect_value(t, cap(array), 4)
|
||||||
|
|
||||||
testing.expect_value(t, array[0], [2]int{1, 2})
|
testing.expect_value(t, array[0], [2]int{1, 2})
|
||||||
testing.expect_value(t, array[1], [2]int{3, 4})
|
testing.expect_value(t, array[1], [2]int{3, 4})
|
||||||
testing.expect_value(t, array[2], [2]int{0, 0})
|
testing.expect_value(t, array[2], [2]int{0, 0})
|
||||||
testing.expect_value(t, array[3], [2]int{0, 0})
|
testing.expect_value(t, array[3], [2]int{0, 0})
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
|
||||||
// |1 4 2 5 3 6|
|
|
||||||
// |1 4 _ _ 2 5 _ _ 3 6 _ _|
|
|
||||||
|
|
||||||
array, err := make(#soa[dynamic][3]int, 2, 2)
|
@(test)
|
||||||
array[0] = [3]int{1, 2, 3}
|
test_soa_array_allocator_resize_overlapping :: proc(t: ^testing.T) {
|
||||||
array[1] = [3]int{4, 5, 6}
|
|
||||||
|
|
||||||
testing.expect_value(t, err, nil)
|
arena: runtime.Arena
|
||||||
testing.expect_value(t, len(array), 2)
|
context.allocator = runtime.arena_allocator(&arena)
|
||||||
testing.expect_value(t, cap(array), 2)
|
defer runtime.arena_destroy(&arena)
|
||||||
|
|
||||||
err = resize(&array, 4)
|
// |1 4 2 5 3 6|
|
||||||
|
// |1 4 _ _ 2 5 _ _ 3 6 _ _|
|
||||||
|
|
||||||
testing.expect_value(t, err, nil)
|
array, err := make(#soa[dynamic][3]int, 2, 2)
|
||||||
testing.expect_value(t, len(array), 4)
|
defer delete(array)
|
||||||
testing.expect_value(t, cap(array), 4)
|
array[0] = [3]int{1, 2, 3}
|
||||||
|
array[1] = [3]int{4, 5, 6}
|
||||||
|
|
||||||
testing.expect_value(t, array[0], [3]int{1, 2, 3})
|
testing.expect_value(t, err, nil)
|
||||||
testing.expect_value(t, array[1], [3]int{4, 5, 6})
|
testing.expect_value(t, len(array), 2)
|
||||||
testing.expect_value(t, array[2], [3]int{0, 0, 0})
|
testing.expect_value(t, cap(array), 2)
|
||||||
testing.expect_value(t, array[3], [3]int{0, 0, 0})
|
|
||||||
}
|
err = resize(&array, 4)
|
||||||
|
|
||||||
|
testing.expect_value(t, err, nil)
|
||||||
|
testing.expect_value(t, len(array), 4)
|
||||||
|
testing.expect_value(t, cap(array), 4)
|
||||||
|
|
||||||
|
testing.expect_value(t, array[0], [3]int{1, 2, 3})
|
||||||
|
testing.expect_value(t, array[1], [3]int{4, 5, 6})
|
||||||
|
testing.expect_value(t, array[2], [3]int{0, 0, 0})
|
||||||
|
testing.expect_value(t, array[3], [3]int{0, 0, 0})
|
||||||
}
|
}
|
||||||
|
|
||||||
@(test)
|
@(test)
|
||||||
|
|||||||
Reference in New Issue
Block a user