Used strings.builder_reset instead of clear for the string builder

This commit is contained in:
Hector
2023-11-25 16:26:29 +00:00
parent b12bfe407d
commit 82088e4a75

View File

@@ -185,20 +185,22 @@ test_sort_by_indices :: proc(t: ^testing.T) {
@test
test_binary_search :: proc(t: ^testing.T) {
index: int
found: bool
builder := strings.Builder{}
defer strings.builder_destroy(&builder)
test_search :: proc(t: ^testing.T, b: ^strings.Builder, s: []i32, v: i32) -> (int, bool) {
log(t, fmt.sbprintf(b, "Searching for %v in %v", v, s))
clear(&b.buf)
strings.builder_reset(b)
index, found := slice.binary_search(s, v)
log(t, fmt.sbprintf(b, "index: %v, found: %v", index, found))
clear(&b.buf)
strings.builder_reset(b )
return index, found
}
index: int
found: bool
s := []i32{0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55}
index, found = test_search(t, &builder, s, 13)