1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

bitfield: add from_bytes() function

This commit is contained in:
Silvan Büdenbender
2019-11-13 17:48:00 +01:00
committed by Alexander Medvednikov
parent ffa6bcfff5
commit f30b0f1017
2 changed files with 40 additions and 0 deletions

View File

@@ -122,6 +122,20 @@ fn test_hamming() {
assert count == bitfield.hamming(input1, input2)
}
fn test_bf_from_bytes() {
input := [byte(0xF0), byte(0x0F), byte(0xF0), byte(0xFF)]
output := bitfield.from_bytes(input)
mut result := 1
for i := 0; i < input.len * 8; i++ {
expected := input[input.len - 1 - i / 8] >> i % 8 & 1
actual := output.getbit(i)
if expected != actual {
result = 0
}
}
assert result == 1
}
fn test_bf_str2bf() {
rand.seed(time.now().uni)
len := 80