-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.spec.ts
68 lines (57 loc) · 1.66 KB
/
mod.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { assert, assertEquals } from "jsr:@std/assert@^0.226.0";
import Alea, { Mash } from "./mod.ts";
import OldAlea, { OldMash } from "./mod.old.ts";
const newMash = new Mash();
const oldMash = OldMash();
//@ts-ignore: typescript is being silly
const aleaFactory = () => [new Alea({ seed: "meow" }), new OldAlea("meow")];
// deno-lint-ignore no-explicit-any
let [newAlea, oldAlea] = aleaFactory() as [Alea, any];
Deno.test("mash", () => {
let ok = 0;
for (let i = 0; i < 1000; i++) {
if (newMash.mash(" ") === oldMash(" ")) ok += 1;
}
assertEquals(ok, 1000);
});
Deno.test("alea", async (t) => {
await t.step("seed", () => {
assertEquals(newAlea.seed, "meow");
});
await t.step("normal", () => {
const normal = [] as number[];
for (let i = 0; i < 1e3; i++) {
normal.push(newAlea.normal());
}
// just test that it works right now :p
});
await t.step("triangular", () => {
const triangular = [] as number[];
for (let i = 0; i < 1e3; i++) {
triangular.push(newAlea.triangular(0, 3, 0));
}
assert(triangular.every((n) => n >= 0 && n <= 3));
});
let ok = 0;
[newAlea, oldAlea] = aleaFactory();
await t.step("random", () => {
for (let i = 0; i < 1e3; i++) {
if (newAlea.random() === oldAlea()) ok += 1;
}
assertEquals(ok, 1000);
});
ok = 0;
await t.step("fract53", () => {
for (let i = 0; i < 1e3; i++) {
if (newAlea.fract53() === oldAlea.fract53()) ok += 1;
}
assertEquals(ok, 1000);
});
ok = 0;
await t.step("uint32", () => {
for (let i = 0; i < 1e3; i++) {
if (newAlea.uint32() === oldAlea.uint32()) ok += 1;
}
assertEquals(ok, 1000);
});
});