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)

105 lines 3.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var rand_1 = require("../rand"); var cellular_automata_builder_1 = require("./cellular-automata-builder"); describe("CellularAutomata", function () { it("Will create with an empty table", function () { var width = 10; var height = 10; var a = new cellular_automata_builder_1.CellularAutomataBuilder({ width: width, height: height, wallValue: 1, floorValue: 0, }); for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { expect(a.getMap().get({ x: x, y: y })).toBeUndefined(); } } }); it("Will default 1/0 as Alive/Dead values", function () { var a = new cellular_automata_builder_1.CellularAutomataBuilder({ width: 10, height: 10, wallValue: 1, floorValue: 0, }); expect(a["aliveValue"]).toEqual(1); expect(a["deadValue"]).toEqual(0); var b = new cellular_automata_builder_1.CellularAutomataBuilder({ width: 10, height: 10, wallValue: 5, floorValue: 4, }); expect(b["aliveValue"]).toEqual(5); expect(b["deadValue"]).toEqual(4); }); it("Can randomize with an initial value", function () { var width = 10; var height = 10; var a = new cellular_automata_builder_1.CellularAutomataBuilder({ width: 10, height: 10, wallValue: 0, floorValue: 1, rng: new rand_1.AleaRNG("foo"), }); a.randomize(0.5); var alive = 0; var dead = 0; var m = a.getMap(); for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { var val = m.get({ x: x, y: y }); if (val === 1) alive++; if (val === 0) dead++; } } expect(alive + dead).toEqual(width * height); expect(Math.abs(alive - 50)).toBeLessThanOrEqual(10); expect(Math.abs(dead - 50)).toBeLessThanOrEqual(10); }); it("Can run a simulation step", function () { var width = 10; var height = 10; var a = new cellular_automata_builder_1.CellularAutomataBuilder({ width: width, height: height, wallValue: 1, floorValue: 0, rng: new rand_1.AleaRNG("foo"), }); a.randomize(); a.doSimulationStep(); expect(a.getMap().items).toMatchSnapshot(); }); it("Can connect areas", function () { var a = new cellular_automata_builder_1.CellularAutomataBuilder({ width: 10, height: 10, wallValue: 1, floorValue: 0, }); var m = a.getMap(); m.fill(1); m.set({ x: 3, y: 3 }, 0); m.set({ x: 6, y: 3 }, 0); var results = a.connect(); expect(results).toEqual({ groups: [[{ x: 3, y: 3 }], [{ x: 6, y: 3 }]], paths: [ [ { x: 6, y: 3, r: 0 }, { x: 5, y: 3, r: 1 }, { x: 4, y: 3, r: 2 }, { x: 3, y: 3, r: 3 }, ], ], }); }); }); //# sourceMappingURL=cellular-automata-builder.spec.js.map