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)

69 lines 2.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var line_1 = require("./line"); describe("line", function () { it("can create a new line", function () { var line = new line_1.Line({ x: 1, y: 1 }, { x: 2, y: 2 }); expect(line.v1).toEqual({ x: 1, y: 1 }); expect(line.v2).toEqual({ x: 2, y: 2 }); expect(line.getDeltaX()).toBe(1); expect(line.getDeltaY()).toBe(1); }); it("can set new points", function () { var line = new line_1.Line({ x: 1, y: 1 }, { x: 2, y: 2 }); expect(line.getDeltaX()).toBe(1); expect(line.getDeltaY()).toBe(1); line.v1 = { x: 3, y: 3 }; line.v2 = { x: 5, y: 5 }; expect(line.getDeltaX()).toBe(2); expect(line.getDeltaY()).toBe(2); }); it("can clone a line", function () { var line = new line_1.Line({ x: 1, y: 2 }, { x: 3, y: 4 }); var cloned = line.clone(); expect(line.v1).toEqual(cloned.v1); expect(line.v2).toEqual(cloned.v2); }); it("can calculate collinear points", function () { var line = new line_1.Line({ x: 1, y: 1 }, { x: 2, y: 2 }); // Valid test cases var collinearPoints = [ { x: 1, y: 1 }, { x: 2, y: 2 }, { x: 3, y: 3 }, ]; for (var _i = 0, collinearPoints_1 = collinearPoints; _i < collinearPoints_1.length; _i++) { var v = collinearPoints_1[_i]; expect(line.isCollinear(v.x, v.y)).toBeTruthy(); expect(line.isAboveOrCollinear(v.x, v.y)).toBeTruthy(); expect(line.isBelowOrCollinear(v.x, v.y)).toBeTruthy(); } for (var _a = 0, collinearPoints_2 = collinearPoints; _a < collinearPoints_2.length; _a++) { var v = collinearPoints_2[_a]; expect(line.isAbove(v.x, v.y)).toBeFalsy(); expect(line.isBelow(v.x, v.y)).toBeFalsy(); } }); it("can calculate collinear lines", function () { var lineA = new line_1.Line({ x: 0, y: 0 }, { x: 1, y: 1 }); var lineB = new line_1.Line({ x: 1, y: 1 }, { x: 3, y: 3 }); expect(lineA.isLineCollinear(lineB)).toBeTruthy(); }); it("can calculate points above", function () { var line = new line_1.Line({ x: 1, y: 1 }, { x: 2, y: 2 }); var abovePoints = [ { x: 2, y: 3 }, { x: 4, y: 100 }, { x: -4, y: -3 }, ]; for (var _i = 0, abovePoints_1 = abovePoints; _i < abovePoints_1.length; _i++) { var v = abovePoints_1[_i]; expect(line.isBelow(v.x, v.y)).toBeTruthy(); expect(line.isBelowOrCollinear(v.x, v.y)).toBeTruthy(); expect(line.isAbove(v.x, v.y)).toBeFalsy(); expect(line.isAboveOrCollinear(v.x, v.y)).toBeFalsy(); expect(line.isCollinear(v.x, v.y)).toBeFalsy(); } }); }); //# sourceMappingURL=line.spec.js.map