UNPKG

malwoden

Version:

![alt text](./coverage/badge-lines.svg) ![alt text](./coverage/badge-statements.svg) ![alt text](./coverage/badge-functions.svg) ![alt text](./coverage/badge-branches.svg)

107 lines 3.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var alea_1 = require("./alea"); describe("AleaRNG", function () { it("Can generate numbers", function () { var aa = new alea_1.AleaRNG("hello"); var bb = new alea_1.AleaRNG("hello"); var cc = aa.clone(); // Run them in sync to compare for (var i = 0; i < 100; i++) { var a = aa.next(); var b = bb.next(); var c = cc.next(); expect(a).toEqual(b); expect(b).toEqual(c); } // Ints for (var i = 0; i < 100; i++) { var a = aa.nextInt(); var b = bb.nextInt(); var c = cc.nextInt(); expect(a).toEqual(b); expect(b).toEqual(c); } }); it("Will generate different numbers with different seeds", function () { var aa = new alea_1.AleaRNG(Math.random().toString()); var bb = new alea_1.AleaRNG(Math.random().toString()); var a = []; var b = []; for (var i = 0; i < 100; i++) { a.push(aa.next()); b.push(bb.next()); } expect(a).not.toEqual(b); }); it("will generate numbers in the correct ranges", function () { var aa = new alea_1.AleaRNG(); // ints var min = 50; var max = 55; for (var i = 0; i < 1000; i++) { var v = aa.nextInt(min, max); var v2 = aa.next(min, max); // Test int expect(v).toBeGreaterThanOrEqual(min); expect(v).toBeLessThan(max); // Test float expect(v2).toBeGreaterThanOrEqual(min); expect(v2).toBeLessThan(max); } }); it("Can reset itself", function () { var aa = new alea_1.AleaRNG("hello"); var bb = new alea_1.AleaRNG("hello"); for (var i = 0; i < 10; i++) { aa.next(); } aa.reset(); for (var i = 0; i < 100; i++) { expect(aa.next()).toEqual(bb.next()); } }); it("Can get booleans", function () { var aa = new alea_1.AleaRNG(); var bools = []; for (var i = 0; i < 100; i++) { bools.push(aa.nextBoolean()); } expect(bools.some(function (x) { return x; })).toBeTruthy(); expect(bools.some(function (x) { return !x; })).toBeTruthy(); }); it("Can get a random item from an array", function () { var aa = new alea_1.AleaRNG(); var nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; for (var i = 0; i < 100; i++) { var e = aa.nextItem(nums); expect(e).not.toBeUndefined(); expect(nums.includes(e)).toBeTruthy(); } expect(nums).toEqual([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); expect(aa.nextItem([])).toEqual(undefined); }); it("Can shuffle an array", function () { var aa = new alea_1.AleaRNG(); var alph = "abcdefghijklmnopqrstuvwxyz".split(""); var alph2 = aa.shuffle(alph); expect(alph).toEqual("abcdefghijklmnopqrstuvwxyz".split("")); expect(alph).not.toEqual(alph2); expect(alph).toHaveLength(alph2.length); for (var _i = 0, alph_1 = alph; _i < alph_1.length; _i++) { var c = alph_1[_i]; expect(alph2.indexOf(c)).toBeGreaterThanOrEqual(0); } }); it("Will sanitize the initial mash function 0 < x < 1", function () { var a = new alea_1.AleaRNG(); a["s0"] = -0.5; a["s1"] = -0.2; a["s2"] = -0.1; a["sanitize"](); expect(a["s0"]).toEqual(0.5); expect(a["s1"]).toEqual(0.8); expect(a["s2"]).toEqual(0.9); }); }); //# sourceMappingURL=alea.spec.js.map