package xarr import "core:testing" @(test) test_msb :: proc(t: ^testing.T) { testing.expect_value(t, msb(0), -1) testing.expect_value(t, msb(1), 0) testing.expect_value(t, msb(2), 1) testing.expect_value(t, msb(3), 1) testing.expect_value(t, msb(4), 2) testing.expect_value(t, msb(5), 2) testing.expect_value(t, msb(6), 2) testing.expect_value(t, msb(7), 2) testing.expect_value(t, msb(8), 3) testing.expect_value(t, msb(16), 4) testing.expect_value(t, msb(64), 6) } @(test) test_chunk_sizes :: proc(t: ^testing.T) { testing.expect_value(t, chunk_size(0), BASE_CHUNK_SIZE) testing.expect_value(t, chunk_size(1), BASE_CHUNK_SIZE) testing.expect_value(t, chunk_size(2), BASE_CHUNK_SIZE * 2) testing.expect_value(t, chunk_size(3), BASE_CHUNK_SIZE * 4) testing.expect_value(t, chunk_size(4), BASE_CHUNK_SIZE * 8) } @(test) test_capacity_from_mask :: proc(t: ^testing.T) { testing.expect_value(t, capacity_from_allocated_mask(0b1), chunk_size(0)) testing.expect_value(t, capacity_from_allocated_mask(0b11), chunk_size(0) + chunk_size(1)) testing.expect_value( t, capacity_from_allocated_mask(0b111), chunk_size(0) + chunk_size(1) + chunk_size(2), ) testing.expect_value( t, capacity_from_allocated_mask(0b1111), chunk_size(0) + chunk_size(1) + chunk_size(2) + chunk_size(3), ) testing.expect_value( t, capacity_from_allocated_mask(0b11111), chunk_size(0) + chunk_size(1) + chunk_size(2) + chunk_size(3) + chunk_size(4), ) } @(test) test_indexing :: proc(t: ^testing.T) { chunk, idx := translate_index(0) testing.expect_value(t, chunk, 0) testing.expect_value(t, idx, 0) chunk, idx = translate_index(BASE_CHUNK_SIZE - 1) testing.expect_value(t, chunk, 0) testing.expect_value(t, idx, BASE_CHUNK_SIZE - 1) chunk, idx = translate_index(BASE_CHUNK_SIZE) testing.expect_value(t, chunk, 1) testing.expect_value(t, idx, 0) chunk, idx = translate_index(BASE_CHUNK_SIZE * 3 - 1) testing.expect_value(t, chunk, 2) testing.expect_value(t, idx, BASE_CHUNK_SIZE - 1) chunk, idx = translate_index(BASE_CHUNK_SIZE * 5) testing.expect_value(t, chunk, 3) testing.expect_value(t, idx, BASE_CHUNK_SIZE) } @(test) test_basic :: proc(t: ^testing.T) { a: Xarr(int) defer delete(&a) NUM :: 10000 RUNS :: 4 for _ in 0 ..< RUNS { defer clear(&a) for i in 0 ..< NUM { append(&a, i) } testing.expect_value(t, a.len, NUM) for i in 0 ..< NUM { testing.expect_value(t, get(a, i), i) } } } @(test) test_remove :: proc(t: ^testing.T) { a: Xarr(int) defer delete(&a) append(&a, 1, 2, 3, 4) unordered_remove(&a, 1) testing.expect_value(t, a.len, 3) testing.expect_value(t, get(a, 0), 1) testing.expect_value(t, get(a, 1), 4) testing.expect_value(t, get(a, 2), 3) } @(test) test_iterator :: proc(t: ^testing.T) { a: Xarr(int) defer delete(&a) append(&a, 0, 1, 2, 3, 4) it := iterator(&a) for e, i in iterator_next(&it) { testing.expect_value(t, e^, i) } } @(test) test_soa :: proc(t: ^testing.T) { My_Struct :: struct { x, y, z: f32, } a: Xarr(My_Struct, true) defer delete(&a) append(&a, My_Struct{x = 1, y = 2, z = 3}) testing.expect_value(t, get(a, 0), My_Struct{x = 1, y = 2, z = 3}) testing.expect_value(t, size_of(Xarr(My_Struct, false)), 0) }