Regression: Invalid is_random implementation due to changes in 0.6.

This commit is contained in:
Christoffer Lerno
2024-07-26 20:18:55 +02:00
parent 34993a20fd
commit e1565ccdc5
3 changed files with 82 additions and 14 deletions

View File

@@ -0,0 +1,35 @@
module std::math::random @test;
import std::math;
fn void test_regular_random()
{
for (int i = 0; i < 100; i++) assert(rand(45) < 45 && rand(45) >= 0);
}
fn void test_next_bool()
{
DefaultRandom rand;
random::seed_entropy(&rand);
for (int i = 0; i < 100; i++) random::next_bool(&rand);
}
fn void test_next()
{
DefaultRandom rand;
random::seed_entropy(&rand);
for (int i = 0; i < 100; i++) assert(random::next(&rand, 100) < 100.0 && random::next(&rand, 100) >= 0);
}
fn void test_next_double()
{
DefaultRandom rand;
random::seed_entropy(&rand);
for (int i = 0; i < 100; i++) assert(random::next_double(&rand) < 1.0 && random::next_double(&rand) >= 0);
}
fn void test_next_float()
{
DefaultRandom rand;
random::seed_entropy(&rand);
for (int i = 0; i < 100; i++) assert(random::next_float(&rand) < 1.0 && random::next_float(&rand) >= 0);
}