mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 23:28:48 +00:00
Simplify core:bytes test
This commit is contained in:
@@ -1,45 +1,27 @@
|
|||||||
package test_core_bytes
|
package test_core_bytes
|
||||||
|
|
||||||
import "core:bytes"
|
import "core:bytes"
|
||||||
|
import "core:slice"
|
||||||
import "core:testing"
|
import "core:testing"
|
||||||
|
|
||||||
@test
|
@test
|
||||||
test_index_byte_sanity :: proc(t: ^testing.T) {
|
test_index_byte_sanity :: proc(t: ^testing.T) {
|
||||||
// We must be able to find the byte at the correct index.
|
// We must be able to find the byte at the correct index.
|
||||||
for n in 1..<256 {
|
data := make([]u8, 64)
|
||||||
data := make([]u8, n)
|
defer delete(data)
|
||||||
defer delete(data)
|
slice.fill(data, '-')
|
||||||
for i in 0..<n-1 {
|
|
||||||
data[i] = '-'
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find it at the end.
|
for offset in 0..<31 {
|
||||||
data[n-1] = 'o'
|
for idx in 0..<31 {
|
||||||
if !testing.expect_value(t, bytes.index_byte(data, 'o'), n-1) {
|
sub := data[offset:]
|
||||||
return
|
sub[idx] = 'o'
|
||||||
}
|
if !testing.expect_value(t, bytes.index_byte(sub, 'o'), idx) {
|
||||||
if !testing.expect_value(t, bytes.last_index_byte(data, 'o'), n-1) {
|
return
|
||||||
return
|
}
|
||||||
}
|
if !testing.expect_value(t, bytes.last_index_byte(sub, 'o'), idx) {
|
||||||
data[n-1] = '-'
|
return
|
||||||
|
}
|
||||||
// Find it in the middle.
|
sub[idx] = '-'
|
||||||
data[n/2] = 'o'
|
|
||||||
if !testing.expect_value(t, bytes.index_byte(data, 'o'), n/2) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if !testing.expect_value(t, bytes.last_index_byte(data, 'o'), n/2) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
data[n/2] = '-'
|
|
||||||
|
|
||||||
// Find it at the start.
|
|
||||||
data[0] = 'o'
|
|
||||||
if !testing.expect_value(t, bytes.index_byte(data, 'o'), 0) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if !testing.expect_value(t, bytes.last_index_byte(data, 'o'), 0) {
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -56,9 +38,7 @@ test_index_byte_multiple_hits :: proc(t: ^testing.T) {
|
|||||||
for n in 5..<256 {
|
for n in 5..<256 {
|
||||||
data := make([]u8, n)
|
data := make([]u8, n)
|
||||||
defer delete(data)
|
defer delete(data)
|
||||||
for i in 0..<n-1 {
|
slice.fill(data, '-')
|
||||||
data[i] = '-'
|
|
||||||
}
|
|
||||||
|
|
||||||
data[n-1] = 'o'
|
data[n-1] = 'o'
|
||||||
data[n-3] = 'o'
|
data[n-3] = 'o'
|
||||||
@@ -82,9 +62,7 @@ test_index_byte_zero :: proc(t: ^testing.T) {
|
|||||||
for n in 1..<256 {
|
for n in 1..<256 {
|
||||||
data := make([]u8, n + 64)
|
data := make([]u8, n + 64)
|
||||||
defer delete(data)
|
defer delete(data)
|
||||||
for i in 0..<n-1 {
|
slice.fill(data, '-')
|
||||||
data[i] = '-'
|
|
||||||
}
|
|
||||||
|
|
||||||
// Positive hit.
|
// Positive hit.
|
||||||
data[n-1] = 0
|
data[n-1] = 0
|
||||||
@@ -105,37 +83,3 @@ test_index_byte_zero :: proc(t: ^testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@test
|
|
||||||
test_misaligned_data :: proc(t: ^testing.T) {
|
|
||||||
for n in 2..<256 {
|
|
||||||
data := make([]u8, n)
|
|
||||||
defer delete(data)
|
|
||||||
for i in 0..<n-1 {
|
|
||||||
data[i] = '-'
|
|
||||||
}
|
|
||||||
|
|
||||||
for m in 1..<n {
|
|
||||||
data[n-1] = 'o'
|
|
||||||
if !testing.expect_value(t, bytes.index_byte(data[m:n], 'o'), n-1-m) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
data[n-1] = '-'
|
|
||||||
|
|
||||||
data[m+(n-m)/2] = 'o'
|
|
||||||
if !testing.expect_value(t, bytes.index_byte(data[m:n], 'o'), (n-m)/2) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if !testing.expect_value(t, bytes.last_index_byte(data[m:n], 'o'), (n-m)/2) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
data[m+(n-m)/2] = '-'
|
|
||||||
|
|
||||||
data[m] = 'o'
|
|
||||||
if !testing.expect_value(t, bytes.last_index_byte(data[m:n], 'o'), 0) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
data[m] = '-'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user