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)

186 lines 6.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var rand_1 = require("../rand"); var bsp_dungeon_builder_1 = require("./bsp-dungeon-builder"); describe("bsp-dungeon", function () { it("can create a basic bsp dungeon", function () { var bsp = new bsp_dungeon_builder_1.BSPDungeonBuilder({ width: 10, height: 20, wallTile: 1, floorTile: 0, }); expect(bsp["map"]["width"]).toEqual(10); expect(bsp["map"]["height"]).toEqual(20); }); it("can accept an rng", function () { var bsp = new bsp_dungeon_builder_1.BSPDungeonBuilder({ width: 10, height: 20, wallTile: 1, floorTile: 0, rng: new rand_1.AleaRNG(), }); }); it("can get leaf nodes with the default tree", function () { var bsp = new bsp_dungeon_builder_1.BSPDungeonBuilder({ width: 10, height: 20, wallTile: 1, floorTile: 0, }); var leafs = bsp.getLeafNodes(); var expected = [bsp["root"]]; expect(leafs).toEqual(expected); }); it("Can split the dungeon", function () { var bsp = new bsp_dungeon_builder_1.BSPDungeonBuilder({ width: 10, height: 20, wallTile: 1, floorTile: 0, }); bsp.splitByCount(1); expect(bsp.getLeafNodes()).toHaveLength(2); }); it("Can create rooms/hallways", function () { var bsp = new bsp_dungeon_builder_1.BSPDungeonBuilder({ width: 40, height: 40, wallTile: 1, floorTile: 0, }); bsp.splitByCount(1); bsp.createRooms({ minWidth: 3, minHeight: 3, padding: 1 }); bsp.createSimpleHallways(); expect(bsp.getLeafNodes()).toHaveLength(2); expect(bsp.getRooms()).toHaveLength(2); expect(bsp.getHallways()).toHaveLength(1); }); it("can get a map table of all the rooms", function () { var bsp = new bsp_dungeon_builder_1.BSPDungeonBuilder({ width: 10, height: 20, wallTile: 1, floorTile: 0, }); bsp.splitByCount(1); bsp.createRooms({ minWidth: 3, minHeight: 3, maxWidth: 5, maxHeight: 5 }); bsp.createSimpleHallways(); var map = bsp.getMap(); expect(map.width).toEqual(10); expect(map.height).toEqual(20); for (var x = 0; x < 10; x++) { for (var y = 0; y < 20; y++) { expect(map.get({ x: x, y: y }) === undefined); } } }); it("won't return rooms if they aren't generated", function () { var bsp = new bsp_dungeon_builder_1.BSPDungeonBuilder({ width: 10, height: 20, wallTile: 1, floorTile: 0, }); var rooms = bsp.getRooms(); expect(rooms).toEqual([]); }); }); describe("bsp-node", function () { it("can get children nodes", function () { var rng = new rand_1.AleaRNG(); var a = new bsp_dungeon_builder_1.BSPDungeonNode({ v1: { x: 0, y: 0 }, v2: { x: 5, y: 5 }, rng: rng, }); var b = new bsp_dungeon_builder_1.BSPDungeonNode({ v1: { x: 0, y: 0 }, v2: { x: 5, y: 5 }, rng: rng, }); var bA = new bsp_dungeon_builder_1.BSPDungeonNode({ v1: { x: 0, y: 0 }, v2: { x: 2, y: 5 }, rng: rng, }); var bB = new bsp_dungeon_builder_1.BSPDungeonNode({ v1: { x: 3, y: 0 }, v2: { x: 5, y: 5 }, rng: rng, }); b["childA"] = bA; b["childB"] = bB; expect(a.getChildren()).toEqual([]); expect(b.getChildren()).toEqual([bA, bB]); }); it("will catch if minROom size is larger than maxRoom", function () { var bsp = new bsp_dungeon_builder_1.BSPDungeonBuilder({ width: 10, height: 20, wallTile: 1, floorTile: 0, }); bsp.splitByCount(2); bsp.createRooms({ minHeight: 5, minWidth: 5, maxHeight: 3, maxWidth: 3, }); var bsp2 = new bsp_dungeon_builder_1.BSPDungeonBuilder({ width: 10, height: 20, wallTile: 1, floorTile: 0, }); bsp2.splitByCount(2); bsp2.createRooms({ minHeight: 5, minWidth: 1, maxHeight: 3, maxWidth: 3, }); expect(bsp.getRooms()).toEqual([]); expect(bsp2.getRooms()).toEqual([]); }); it("will throw an error if split multiple times", function () { var rng = new rand_1.AleaRNG(); var a = new bsp_dungeon_builder_1.BSPDungeonNode({ v1: { x: 0, y: 0 }, v2: { x: 50, y: 50 }, rng: rng, }); a.split(); expect(function () { return a.splitHorizontal(); }).toThrow(); expect(function () { return a.splitVertical(); }).toThrow(); }); it("will force a split if w/h or h/w is > 1.25", function () { var rng = new rand_1.AleaRNG(); var wide = new bsp_dungeon_builder_1.BSPDungeonNode({ v1: { x: 0, y: 0 }, v2: { x: 40, y: 20 }, rng: rng, }); var tall = new bsp_dungeon_builder_1.BSPDungeonNode({ v1: { x: 0, y: 0 }, v2: { x: 20, y: 40 }, rng: rng, }); expect(wide["getRandomSplitDir"]()).toEqual("horizontal"); expect(tall["getRandomSplitDir"]()).toEqual("vertical"); }); it("will return without splitting if maxH < minH or maxW < minW", function () { var rng = new rand_1.AleaRNG(); var small = new bsp_dungeon_builder_1.BSPDungeonNode({ v1: { x: 0, y: 0 }, v2: { x: 3, y: 3 }, rng: rng, }); small.splitHorizontal(); small.splitVertical(); expect(small.isLeafNode()).toBeTruthy(); }); }); //# sourceMappingURL=bsp-dungeon-builder.spec.js.map