Files
ww/lib/math/random/random_test.ww
Hojun-Cho 2338ea5d59 ww: lib tests run via -T test mode; bare mains retired (closes @test conversion)
'ww test' gains the istest build path (-T injection in build_one/
buildone) and do_test/dotest accept -I, mirroring do_run - both twins.
The 35 converted lib tests drop their interim bare mains (-T
synthesizes the entry from @test fns and rejects a user main); their
35 C run-drivers flip 'ww run' -> 'ww test'; 989_lib_byteid compiles
lib tests under -T (8 user-main probe fixtures stay non-T, gated on
the fixture field). Abort-on-first-failure stands until the deferred
record-and-continue harness lands with the multi-package arc.
2026-06-10 20:45:46 +09:00

55 lines
1.3 KiB
Plaintext

package random_test;
import random;
@test fn seq() void = {
let r: random.random = random.init(1234567u64);
assert(!(random.next(&r) != 6457827717110365317u64));
assert(!(random.next(&r) != 3203168211198807973u64));
assert(!(random.next(&r) != 9817491932198370423u64));
assert(!(random.next(&r) != 4593380528125082431u64));
assert(!(random.next(&r) != 16408922859458223821u64));
};
@test fn deterministic() void = {
let a: random.random = random.init(42u64);
let b: random.random = random.init(42u64);
let i: i32 = 0;
for (i < 32) {
assert(!(random.next(&a) != random.next(&b)));
i += 1;
};
};
@test fn u32n_inrange() void = {
let r: random.random = random.init(7u64);
let i: i32 = 0;
for (i < 200) {
let v: u32 = random.u32n(&r, 17u32);
// v stored as u64 with possible high bits — mask before compare.
let vv: u64 = (v: u64) & 0xFFFFFFFFu64;
assert(!(vv >= 17u64));
i += 1;
};
};
@test fn u64n_pow2() void = {
let r: random.random = random.init(99u64);
let i: i32 = 0;
for (i < 200) {
let v: u64 = random.u64n(&r, 16u64);
assert(!(v >= 16u64));
i += 1;
};
};
@test fn u64n_nonpow2() void = {
let r: random.random = random.init(123u64);
let i: i32 = 0;
for (i < 200) {
let v: u64 = random.u64n(&r, 100u64);
assert(!(v >= 100u64));
i += 1;
};
};