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)

65 lines 2.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var display_1 = require("./display"); var glyph_1 = require("./glyph"); describe("Display", function () { it("Can get the Size", function () { var d = new display_1.Display(10, 20); expect(d.width).toEqual(10); expect(d.height).toEqual(20); expect(d.size()).toEqual({ x: 10, y: 20 }); }); it("Won't update the table until rendering", function () { var d = new display_1.Display(10, 10); d.setGlyph({ x: 5, y: 5 }, new glyph_1.Glyph("x")); d.render(function () { }); d.setGlyph({ x: 5, y: 5 }, new glyph_1.Glyph("x")); d.render(function (pos, glyph) { if (pos.x === 5 && pos.y === 5) { expect(glyph.isEqual(new glyph_1.Glyph("x"))).toBeTruthy(); } }); }); it("Won't store the glyph if out of bounds", function () { var d = new display_1.Display(10, 10); d.setGlyph({ x: -1, y: -1 }, new glyph_1.Glyph("x")); d.render(function (pos, g) { throw new Error("Render shouldn't call anything. Unexpected Glyph"); }); }); it("Can render", function () { var d = new display_1.Display(3, 3); d.setGlyph({ x: 0, y: 0 }, new glyph_1.Glyph("1")); d.setGlyph({ x: 1, y: 0 }, new glyph_1.Glyph("2")); d.setGlyph({ x: 2, y: 0 }, new glyph_1.Glyph("3")); d.setGlyph({ x: 0, y: 1 }, new glyph_1.Glyph("4")); d.setGlyph({ x: 1, y: 1 }, new glyph_1.Glyph("5")); d.setGlyph({ x: 2, y: 1 }, new glyph_1.Glyph("6")); d.setGlyph({ x: 0, y: 2 }, new glyph_1.Glyph("7")); d.setGlyph({ x: 1, y: 2 }, new glyph_1.Glyph("8")); d.setGlyph({ x: 2, y: 2 }, new glyph_1.Glyph("9")); var vectors = []; var glyphs = []; d.render(function (pos, glyph) { vectors.push(pos); glyphs.push(glyph); }); expect(vectors).toHaveLength(9); expect(vectors).toEqual([ { x: 2, y: 2 }, { x: 1, y: 2 }, { x: 0, y: 2 }, { x: 2, y: 1 }, { x: 1, y: 1 }, { x: 0, y: 1 }, { x: 2, y: 0 }, { x: 1, y: 0 }, { x: 0, y: 0 }, ]); expect(glyphs).toHaveLength(9); for (var i = 0; i < 9; i++) { expect(glyphs[i].isEqual(new glyph_1.Glyph((i + 1).toString()))); } }); }); //# sourceMappingURL=display.spec.js.map