tandem rng tandem-rs GitHub

Tests

cargo test

Suite

tests/vectors.rs checks every vector of the specification. tests/streams.rs compares long fills, scalar draws and random access against reference stream dumps in tests/data, complex fills included.

tests/conformance.rs reads the six conformance files of the spec: scalar and filled bounded integers, f64 and f32 normals, exponentials, weighted choices, and the hashes of long outputs. Every fill case checks its values, its end position, its scalar draws, and the fill cut at elements 1, 7, 20, 21 and n − 1 and continued on one generator. An f32 normal fill is cut at 2, 8, 20 and the largest even element below n, since a cut inside a pair drops a sin half. The tests then show each checklist item:

A fill whose end reaches 2^64 cannot be expressed: starts lie below 2^63, and a slice cannot hold the 2^57 or more elements needed to reach 2^64 from there. The checklist of tandem-spec 2a4bd08 lets a port skip that item, and the test states what the crate does instead.

With std the normals and exponentials compare bit for bit. Without it they compare within the tolerance of Appendix A.

tests/derived.rs checks the derived draws against their definitions and laws: the bounded fills against Lemire's rule with the fallback, the f32 normal against the Box-Muller formula in f64, fills cut across their internal passes, the mean and variance of 2^20 normals, the Exp(1) moments to the fourth order with a Kolmogorov-Smirnov statistic on 1e7 samples, and a chi-square test of 1e6 weighted choices.

tests/rand_core.rs checks the trait implementations against the inherent API. tests/distr.rs (with --features rand) compares every distribution with its inherent draw on the conformance cases, sample_iter with the fills at lengths that cut their passes, and with std the two normal dump hashes. It also checks that a foreign generator gets normals of unit variance. tests/parallel.rs (with --features rayon) compares each parallel fill with the serial fill at offsets and lengths that cut rows and tasks, and checks the final position. tests/serde.rs (with --features serde) round-trips a generator through JSON and rejects a bad chunk length or start position. tests/intrinsics.rs (with --features simd-intrinsics) compares every fill with the stream built from the scalar block, at offsets and lengths that cut rows and chunks. tests/gpu.rs (with --features wgpu) compares GPU fills with the CPU fills over keys, chunk lengths, positions and lengths, and with the dumps. It skips without an adapter.

Fixtures

tests/conformance/*.json are byte-identical copies of tandem-spec 2a4bd08 conformance/*.json, generated by tandem-c 1c75956. CI compares them with the spec at 2a4bd08. tests/vectors_data/mod.rs is generated from the spec repository's vectors.json by tools/gen_vectors.py. tools/gen_zig_tables.py writes src/zig_tables.rs from the spec's tables/normal_f64_zig1024.json. CI checks that both are current. cargo run --release --example dump_normals | shasum -a 256 writes the same bytes as tandem-c's tools/dump_normals.c, and cargo run --release --example dump_exponentials | shasum -a 256 the same bytes as tandem-c's tools/dump_exponentials.c.