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

cleanup: replace C for loops with range

This commit is contained in:
spaceface777
2020-02-24 17:55:16 +01:00
committed by GitHub
parent 5918946feb
commit ef8c1203b4
50 changed files with 168 additions and 170 deletions

View File

@@ -49,7 +49,7 @@ fn test_clone_cmp() {
rand.seed(time.now().unix)
len := 80
mut input := bitfield.new(len)
for i := 0; i < len; i++ {
for i in 0..len {
if rand.next(2) == 1 {
input.setbit(i)
}
@@ -63,7 +63,7 @@ fn test_slice_join() {
rand.seed(time.now().unix)
len := 80
mut input := bitfield.new(len)
for i := 0; i < len; i++ {
for i in 0..len {
if rand.next(2) == 1 {
input.setbit(i)
}
@@ -87,7 +87,7 @@ fn test_popcount() {
len := 80
mut count0 := 0
mut input := bitfield.new(len)
for i := 0; i < len; i++ {
for i in 0..len {
if rand.next(2) == 1 {
input.setbit(i)
count0++
@@ -103,7 +103,7 @@ fn test_hamming() {
mut count := 0
mut input1 := bitfield.new(len)
mut input2 := bitfield.new(len)
for i := 0; i < len; i++ {
for i in 0..len {
match rand.next(4) {
0, 1 {
input1.setbit(i)
@@ -129,7 +129,7 @@ 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++ {
for i in 0..input.len * 8 {
if (input[i / 8] >> (i % 8)) & 1 != output.getbit(i) {
result = 0
}
@@ -141,7 +141,7 @@ fn test_bf_from_string() {
rand.seed(time.now().unix)
len := 80
mut input := ''
for i := 0; i < len; i++ {
for i in 0..len {
if rand.next(2) == 1 {
input = input + '1'
}
@@ -151,7 +151,7 @@ fn test_bf_from_string() {
}
output := bitfield.from_string(input)
mut result := 1
for i := 0; i < len; i++ {
for i in 0..len {
if input[i] != output.getbit(i) + 48 {
result = 0
}
@@ -163,13 +163,13 @@ fn test_bf_bf2str() {
rand.seed(time.now().unix)
len := 80
mut input := bitfield.new(len)
for i := 0; i < len; i++ {
for i in 0..len {
if rand.next(2) == 1 {
input.setbit(i)
}
}
mut check := ''
for i := 0; i < len; i++ {
for i in 0..len {
if input.getbit(i) == 1 {
check = check + '1'
}
@@ -179,7 +179,7 @@ fn test_bf_bf2str() {
}
output := input.string()
mut result := 1
for i := 0; i < len; i++ {
for i in 0..len {
if check[i] != output[i] {
result = 0
}
@@ -193,7 +193,7 @@ fn test_bf_setall() {
mut input := bitfield.new(len)
input.setall()
mut result := 1
for i := 0; i < len; i++ {
for i in 0..len {
if input.getbit(i) != 1 {
result = 0
}
@@ -205,14 +205,14 @@ fn test_bf_clearall() {
rand.seed(time.now().unix)
len := 80
mut input := bitfield.new(len)
for i := 0; i < len; i++ {
for i in 0..len {
if rand.next(2) == 1 {
input.setbit(i)
}
}
input.clearall()
mut result := 1
for i := 0; i < len; i++ {
for i in 0..len {
if input.getbit(i) != 0 {
result = 0
}
@@ -224,7 +224,7 @@ fn test_bf_reverse() {
rand.seed(time.now().unix)
len := 80
mut input := bitfield.new(len)
for i := 0; i < len; i++ {
for i in 0..len {
if rand.next(2) == 1 {
input.setbit(i)
}
@@ -232,7 +232,7 @@ fn test_bf_reverse() {
check := bitfield.clone(input)
output := input.reverse()
mut result := 1
for i := 0; i < len; i++ {
for i in 0..len {
if output.getbit(i) != check.getbit(len - i - 1) {
result = 0
}
@@ -244,7 +244,7 @@ fn test_bf_resize() {
rand.seed(time.now().unix)
len := 80
mut input := bitfield.new(rand.next(len) + 1)
for i := 0; i < 100; i++ {
for i in 0..100 {
input.resize(rand.next(len) + 1)
input.setbit(input.getsize() - 1)
}
@@ -263,12 +263,12 @@ fn test_bf_pos() {
len := 80
mut result := 1
for i := 1; i < len; i++ { // needle size
for j := 0; j < len - i; j++ { // needle position in the haystack
for j in 0..len - i { // needle position in the haystack
// create the needle
mut needle := bitfield.new(i)
// fill the needle with random values
for k := 0; k < i; k++ {
for k in 0..i {
if rand.next(2) == 1 {
needle.setbit(k)
}