fix vlib/bitfield/bitfield_test.v

pull/4237/head
Delyan Angelov 2020-04-04 18:03:03 +03:00
parent 33b03449d5
commit 8f06d60084
2 changed files with 18 additions and 20 deletions

View File

@ -92,17 +92,17 @@ pub fn from_bytes(input []byte) BitField {
pub fn from_string(input string) BitField {
mut output := new(input.len)
for i in 0..input.len {
if input[i] != 48 {
if input[i] != `0` {
output.setbit(i)
}
}
return output
}
// string() converts the bit array to a string of characters ('0' and '1') and
// str() converts the bit array to a string of characters ('0' and '1') and
// return the string
pub fn (input BitField) string() string {
pub fn (input BitField) str() string {
mut output := ''
for i in 0..input.size {
if input.getbit(i) == 1 {
@ -291,22 +291,6 @@ pub fn join(input1 BitField, input2 BitField) BitField {
return output
}
// print(instance BitField) send the content of a bit array to stdout as a
// string of characters ('0' and '1').
pub fn print(instance BitField) {
mut i := 0
for i < instance.size {
if instance.getbit(i) == 1 {
print('1')
}
else {
print('0')
}
i++
}
}
// getsize() returns the number of bits the array can hold
pub fn (instance BitField) getsize() int {

View File

@ -177,7 +177,7 @@ fn test_bf_bf2str() {
check = check + '0'
}
}
output := input.string()
output := input.str()
mut result := 1
for i in 0..len {
if check[i] != output[i] {
@ -320,3 +320,17 @@ fn test_bf_rotate() {
}
assert result == 1
}
fn test_bf_printing(){
rand.seed(time.now().unix)
len := 80
mut input := bitfield.new(len)
for i in 0..len {
if rand.next(2) == 0 {
input.setbit(i)
}
}
// the following should convert the bitfield input into a string automatically
println(input)
assert true
}