malwoden
Version:
   
69 lines • 2.47 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var rand_1 = require("../rand");
var drunkards_walk_builder_1 = require("./drunkards-walk-builder");
describe("Drunkards Walk", function () {
it("Can create a basic drunkards walk", function () {
var w = new drunkards_walk_builder_1.DrunkardsWalkBuilder({
width: 10,
height: 10,
rng: new rand_1.AleaRNG("foo"),
topology: "eight",
floorTile: 0,
wallTile: 1,
});
expect(w.getPaths()).toEqual([]);
expect(w.getCoverage()).toBe(0);
var m = w.getMap();
for (var x = 0; x < 10; x++) {
for (var y = 0; y < 10; y++) {
expect(m.get({ x: x, y: y })).toEqual(1);
}
}
});
it("Can use topology - 8", function () {
var w = new drunkards_walk_builder_1.DrunkardsWalkBuilder({
width: 10,
height: 10,
rng: new rand_1.AleaRNG("foo"),
topology: "eight",
wallTile: 0,
floorTile: 1,
});
w.walk({ stepsMin: 10, stepsMax: 10, pathCount: 2 });
expect(w.getPaths()).toHaveLength(2);
expect(w.getCoverage()).toBeLessThanOrEqual(1);
});
it("Can be given an initial point", function () {
var w = new drunkards_walk_builder_1.DrunkardsWalkBuilder({
width: 10,
height: 10,
floorTile: 0,
wallTile: 1,
});
w.walk({ stepsMin: 10, stepsMax: 10, start: { x: 1, y: 1 } });
expect(w.getPaths()[0][0]).toEqual({ x: 1, y: 1 });
});
it("will only increment covered when it hasn't been there", function () {
var w = new drunkards_walk_builder_1.DrunkardsWalkBuilder({
width: 10,
height: 10,
floorTile: 0,
wallTile: 1,
});
w["addPoint"]({ x: 1, y: 1 });
w["addPoint"]({ x: 1, y: 1 });
expect(w.getCoverage()).toBe(1 / 100);
});
it("Will stop if coveredCount is reached", function () {
var w = new drunkards_walk_builder_1.DrunkardsWalkBuilder({
width: 10,
height: 10,
floorTile: 0,
wallTile: 1,
});
w.walk({ stepsMin: 100, stepsMax: 100, maxCoverage: 5 / 100 });
expect(w.getCoverage()).toEqual(5 / 100);
});
});
//# sourceMappingURL=drunkards-walk-builder.spec.js.map