mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
rand: add rand.element and prng.element functions with unit test (#16068)
This commit is contained in:
parent
f7f0e0b5dc
commit
09e23e3ed6
2 changed files with 33 additions and 0 deletions
|
@ -411,3 +411,21 @@ fn test_sample() {
|
|||
assert element in a
|
||||
}
|
||||
}
|
||||
|
||||
fn test_element1() {
|
||||
a := ['one', 'two', 'four', 'five', 'six', 'seven']
|
||||
for _ in 0 .. 30 {
|
||||
e := rand.element(a)?
|
||||
assert e in a
|
||||
assert 'three' != e
|
||||
}
|
||||
}
|
||||
|
||||
fn test_element2() {
|
||||
for _ in 0 .. 30 {
|
||||
e := rand.element([1, 2, 5, 6, 7, 8])?
|
||||
assert e in [1, 2, 5, 6, 7, 8]
|
||||
assert 3 != e
|
||||
assert 4 != e
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue