mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
fmt: remove space in front of ? and ! (#14366)
This commit is contained in:
@@ -16,7 +16,7 @@ rand.seed([u32(3110), 50714])
|
||||
...
|
||||
|
||||
// Use the top-level functions
|
||||
rand.u32n(100) ?
|
||||
rand.u32n(100)?
|
||||
rand.int() // among others ...
|
||||
```
|
||||
|
||||
@@ -41,7 +41,7 @@ rng.seed(seed.time_seed_array(pcg32.seed_len))
|
||||
...
|
||||
|
||||
// Use functions of your choice
|
||||
rng.u32n(100) ?
|
||||
rng.u32n(100)?
|
||||
rng.int() // among others ...
|
||||
```
|
||||
|
||||
|
@@ -106,7 +106,7 @@ pub fn (mut rng PRNG) u32_in_range(min u32, max u32) ?u32 {
|
||||
if max <= min {
|
||||
return error('max must be greater than min')
|
||||
}
|
||||
return min + rng.u32n(max - min) ?
|
||||
return min + rng.u32n(max - min)?
|
||||
}
|
||||
|
||||
// u64_in_range returns a uniformly distributed pseudorandom 64-bit unsigned `u64` in range `[min, max)`.
|
||||
@@ -115,7 +115,7 @@ pub fn (mut rng PRNG) u64_in_range(min u64, max u64) ?u64 {
|
||||
if max <= min {
|
||||
return error('max must be greater than min')
|
||||
}
|
||||
return min + rng.u64n(max - min) ?
|
||||
return min + rng.u64n(max - min)?
|
||||
}
|
||||
|
||||
// i8 returns a (possibly negative) pseudorandom 8-bit `i8`.
|
||||
@@ -160,7 +160,7 @@ pub fn (mut rng PRNG) intn(max int) ?int {
|
||||
if max <= 0 {
|
||||
return error('max has to be positive.')
|
||||
}
|
||||
return int(rng.u32n(u32(max)) ?)
|
||||
return int(rng.u32n(u32(max))?)
|
||||
}
|
||||
|
||||
// i64n returns a pseudorandom int that lies in `[0, max)`.
|
||||
@@ -169,7 +169,7 @@ pub fn (mut rng PRNG) i64n(max i64) ?i64 {
|
||||
if max <= 0 {
|
||||
return error('max has to be positive.')
|
||||
}
|
||||
return i64(rng.u64n(u64(max)) ?)
|
||||
return i64(rng.u64n(u64(max))?)
|
||||
}
|
||||
|
||||
// int_in_range returns a pseudorandom `int` in range `[min, max)`.
|
||||
@@ -179,7 +179,7 @@ pub fn (mut rng PRNG) int_in_range(min int, max int) ?int {
|
||||
return error('max must be greater than min')
|
||||
}
|
||||
// This supports negative ranges like [-10, -5) because the difference is positive
|
||||
return min + rng.intn(max - min) ?
|
||||
return min + rng.intn(max - min)?
|
||||
}
|
||||
|
||||
// i64_in_range returns a pseudorandom `i64` in range `[min, max)`.
|
||||
@@ -188,7 +188,7 @@ pub fn (mut rng PRNG) i64_in_range(min i64, max i64) ?i64 {
|
||||
if max <= min {
|
||||
return error('max must be greater than min')
|
||||
}
|
||||
return min + rng.i64n(max - min) ?
|
||||
return min + rng.i64n(max - min)?
|
||||
}
|
||||
|
||||
// f32 returns a pseudorandom `f32` value in range `[0, 1)`.
|
||||
@@ -227,7 +227,7 @@ pub fn (mut rng PRNG) f32_in_range(min f32, max f32) ?f32 {
|
||||
if max < min {
|
||||
return error('max must be greater than or equal to min')
|
||||
}
|
||||
return min + rng.f32n(max - min) ?
|
||||
return min + rng.f32n(max - min)?
|
||||
}
|
||||
|
||||
// i64_in_range returns a pseudorandom `i64` in range `[min, max]`.
|
||||
@@ -236,7 +236,7 @@ pub fn (mut rng PRNG) f64_in_range(min f64, max f64) ?f64 {
|
||||
if max < min {
|
||||
return error('max must be greater than or equal to min')
|
||||
}
|
||||
return min + rng.f64n(max - min) ?
|
||||
return min + rng.f64n(max - min)?
|
||||
}
|
||||
|
||||
// ulid generates an Unique Lexicographically sortable IDentifier.
|
||||
@@ -298,7 +298,7 @@ fn (config ShuffleConfigStruct) validate_for<T>(a []T) ? {
|
||||
// shuffle all elements until the end.
|
||||
[direct_array_access]
|
||||
pub fn (mut rng PRNG) shuffle<T>(mut a []T, config ShuffleConfigStruct) ? {
|
||||
config.validate_for(a) ?
|
||||
config.validate_for(a)?
|
||||
new_end := if config.end == 0 { a.len } else { config.end }
|
||||
for i in config.start .. new_end {
|
||||
x := rng.int_in_range(i, new_end) or { config.start }
|
||||
@@ -313,7 +313,7 @@ pub fn (mut rng PRNG) shuffle<T>(mut a []T, config ShuffleConfigStruct) ? {
|
||||
// The permutation is done on a fresh clone of `a`, so `a` remains unchanged.
|
||||
pub fn (mut rng PRNG) shuffle_clone<T>(a []T, config ShuffleConfigStruct) ?[]T {
|
||||
mut res := a.clone()
|
||||
rng.shuffle(mut res, config) ?
|
||||
rng.shuffle(mut res, config)?
|
||||
return res
|
||||
}
|
||||
|
||||
@@ -327,7 +327,7 @@ pub fn (mut rng PRNG) choose<T>(array []T, k int) ?[]T {
|
||||
}
|
||||
mut results := []T{len: k}
|
||||
mut indices := []int{len: n, init: it}
|
||||
rng.shuffle(mut indices) ?
|
||||
rng.shuffle(mut indices)?
|
||||
for i in 0 .. k {
|
||||
results[i] = array[indices[i]]
|
||||
}
|
||||
@@ -542,7 +542,7 @@ pub fn ascii(len int) string {
|
||||
// optional and the entire array is shuffled by default. Leave the end as 0 to
|
||||
// shuffle all elements until the end.
|
||||
pub fn shuffle<T>(mut a []T, config ShuffleConfigStruct) ? {
|
||||
default_rng.shuffle(mut a, config) ?
|
||||
default_rng.shuffle(mut a, config)?
|
||||
}
|
||||
|
||||
// shuffle_clone returns a random permutation of the elements in `a`.
|
||||
|
@@ -3,7 +3,7 @@ import rand
|
||||
fn test_rand_bytes() ? {
|
||||
mut randoms := []string{}
|
||||
for i in 0 .. 100 {
|
||||
x := rand.bytes(i) ?.hex()
|
||||
x := rand.bytes(i)?.hex()
|
||||
if x.len > 0 {
|
||||
randoms << x
|
||||
}
|
||||
@@ -25,7 +25,7 @@ fn test_prng_rand_bytes() ? {
|
||||
mut randoms := []string{}
|
||||
mut rng := rand.get_current_rng()
|
||||
for i in 0 .. 100 {
|
||||
x := rng.bytes(i) ?.hex()
|
||||
x := rng.bytes(i)?.hex()
|
||||
if x.len > 0 {
|
||||
randoms << x
|
||||
}
|
||||
|
@@ -358,11 +358,11 @@ fn test_shuffle_partial() ? {
|
||||
mut a := [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
mut b := a.clone()
|
||||
|
||||
rand.shuffle(mut a, start: 4) ?
|
||||
rand.shuffle(mut a, start: 4)?
|
||||
assert a[..4] == b[..4]
|
||||
|
||||
a = b.clone()
|
||||
rand.shuffle(mut a, start: 3, end: 7) ?
|
||||
rand.shuffle(mut a, start: 3, end: 7)?
|
||||
assert a[..3] == b[..3]
|
||||
assert a[7..] == b[7..]
|
||||
}
|
||||
@@ -386,7 +386,7 @@ fn test_choose() ? {
|
||||
lengths := [1, 3, 4, 5, 6, 7]
|
||||
a := ['one', 'two', 'three', 'four', 'five', 'six', 'seven']
|
||||
for length in lengths {
|
||||
b := rand.choose(a, length) ?
|
||||
b := rand.choose(a, length)?
|
||||
assert b.len == length
|
||||
for element in b {
|
||||
assert element in a
|
||||
|
Reference in New Issue
Block a user