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

bitfield: fix bit order

This commit is contained in:
Silvan Büdenbender
2019-11-19 01:32:44 +01:00
committed by Alexander Medvednikov
parent 20d6492775
commit 94b36250a1
2 changed files with 8 additions and 27 deletions

View File

@ -127,16 +127,14 @@ fn test_bf_from_bytes() {
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 {
if (input[i / 8] >> (i % 8)) & 1 != output.getbit(i) {
result = 0
}
}
assert result == 1
}
fn test_bf_str2bf() {
fn test_bf_from_string() {
rand.seed(time.now().uni)
len := 80
mut input := ''
@ -148,7 +146,7 @@ fn test_bf_str2bf() {
input = input + '0'
}
}
output := bitfield.str2bf(input)
output := bitfield.from_string(input)
mut result := 1
for i := 0; i < len; i++ {
if input[i] != output.getbit(i) + 48 {