hexagrid
Version:
Hexagonal grid with fast lookup
41 lines • 1.98 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const hex_1 = require("./hex");
describe("Hex", () => {
it("should rotate left", () => {
const hex = new hex_1.default(-3, 2);
hex.rotateLeft(2);
chai_1.expect(hex).to.include({ q: 2, r: 1 });
hex.rotateLeft(4);
chai_1.expect(hex).to.include({ q: -3, r: 2 });
});
it("should rotate right with center", () => {
const hex = new hex_1.default(-3, 2);
hex.rotateRight(3, { q: -3, r: 2, s: 1 });
chai_1.expect(hex).to.include({ q: -3, r: 2 });
hex.rotateRight(1, { q: -2, r: 1, s: 1 });
chai_1.expect(hex).to.include({ q: -3, r: 1 });
});
it("should have a third coordinate s", () => {
const hex = new hex_1.default(-3, 2);
chai_1.expect(hex.s).to.equal(1);
});
it("should have all three coordinates in the JSON object", () => {
const hex = new hex_1.default(5, -3);
const json = JSON.parse(JSON.stringify(hex));
chai_1.expect(json).to.include({ q: 5, r: -3, s: -2 });
});
it("should generate hexagons with data feeding", () => {
const HexNone = hex_1.default.extend("none");
const hexaNone = HexNone.hexagon(1);
chai_1.expect(hexaNone.map(hex => hex.data)).to.have.same.members(["none", "none", "none", "none", "none", "none", "none"]);
const hexaAbcdefg = hex_1.default.hexagon(1, { data: ["a", "b", "c", "d", "e", "f", "g"] });
chai_1.expect(hexaAbcdefg.map(hex => hex.data)).to.have.same.members(["a", "b", "c", "d", "e", "f", "g"]);
const HexA = hex_1.default.extend({ a: 5 });
const data = [{ a: 1 }, { a: 2 }];
const ringA = HexA.ring(1, { data });
chai_1.expect(ringA.map(hex => hex.data)).to.include.deep.members([{ a: 1 }, { a: 2 }, { a: 5 }]);
});
});
//# sourceMappingURL=hex.spec.js.map