From defde9bf0ad93661d4978ecf4917340d152fb590 Mon Sep 17 00:00:00 2001 From: fm Date: Sun, 13 Jul 2025 10:40:12 +0300 Subject: [PATCH 1/7] finish test --- jest.config.ts | 15 +++ modules/ecs6-class/line.ts | 36 ++++--- package-lock.json | 189 +++++++++++++++++++++++++++++++++++++ package.json | 5 +- test/test-line.test.ts | 100 ++++++++++++++++++++ test/test-point.test.ts | 47 +++++++++ 6 files changed, 379 insertions(+), 13 deletions(-) create mode 100644 jest.config.ts create mode 100644 test/test-line.test.ts create mode 100644 test/test-point.test.ts diff --git a/jest.config.ts b/jest.config.ts new file mode 100644 index 0000000..6abf10d --- /dev/null +++ b/jest.config.ts @@ -0,0 +1,15 @@ +module.exports = { + preset: 'ts-jest', + testEnvironment: 'node', +}; +import type { JestConfigWithTsJest } from 'ts-jest'; + +const config: JestConfigWithTsJest = { + preset: 'ts-jest', + testEnvironment: 'node', + testMatch: [ + "**/test/**/*.test.ts" + ] +}; + +export default config; \ No newline at end of file diff --git a/modules/ecs6-class/line.ts b/modules/ecs6-class/line.ts index e2d6086..7405a67 100644 --- a/modules/ecs6-class/line.ts +++ b/modules/ecs6-class/line.ts @@ -32,19 +32,31 @@ export default class Line { } - getPointByX(x: number) { - if (this.slope && this.n) { - let y = this.slope * x + this.n - return new Point({ x, y }) - } + // getPointByX(x: number) { + // if (this.slope && this.n) { + // let y = this.slope * x + this.n + // return new Point({ x, y }) + // } + // } + + // getPointByY(y: number) { + // if (this.slope && this.n) { + // let x = (y - this.n) / this.slope; + // return new Point({ x, y }) + // } + // } + +getPointByX(x: number) { + if (this.slope !== undefined && this.n !== undefined) { + let y = this.slope * x + this.n; + return new Point({ x, y }); } +} - getPointByY(y: number) { - if (this.slope && this.n) { - let x = (y - this.n) / this.slope; - return new Point({ x, y }) - } +getPointByY(y: number) { + if (this.slope !== undefined && this.n !== undefined) { + let x = (y - this.n) / this.slope; + return new Point({ x, y }); } - - +} } diff --git a/package-lock.json b/package-lock.json index 5bc5ea8..3da30fe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "devDependencies": { "@types/jest": "^30.0.0", "jest": "^30.0.4", + "ts-jest": "^29.4.0", "ts-node": "^10.9.2", "typescript": "^5.8.3" } @@ -1662,6 +1663,13 @@ "sprintf-js": "~1.0.2" } }, + "node_modules/async": { + "version": "3.2.6", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.6.tgz", + "integrity": "sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA==", + "dev": true, + "license": "MIT" + }, "node_modules/babel-jest": { "version": "30.0.4", "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-30.0.4.tgz", @@ -1823,6 +1831,19 @@ "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" } }, + "node_modules/bs-logger": { + "version": "0.2.6", + "resolved": "https://registry.npmjs.org/bs-logger/-/bs-logger-0.2.6.tgz", + "integrity": "sha512-pd8DCoxmbgc7hyPKOvxtqNcjYoOsABPQdcCUjGp3d42VR2CX1ORhk2A87oqqu5R1kk+76nsxZupkmyd+MVtCog==", + "dev": true, + "license": "MIT", + "dependencies": { + "fast-json-stable-stringify": "2.x" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/bser": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/bser/-/bser-2.1.1.tgz", @@ -2153,6 +2174,22 @@ "dev": true, "license": "MIT" }, + "node_modules/ejs": { + "version": "3.1.10", + "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.10.tgz", + "integrity": "sha512-UeJmFfOrAQS8OJWPZ4qtgHyWExa088/MtK5UEyoJGFH67cDEXkZSviOiKRCZ4Xij0zxI3JECgYs3oKx+AizQBA==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "jake": "^10.8.5" + }, + "bin": { + "ejs": "bin/cli.js" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/electron-to-chromium": { "version": "1.5.181", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.181.tgz", @@ -2300,6 +2337,29 @@ "bser": "2.1.1" } }, + "node_modules/filelist": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/filelist/-/filelist-1.0.4.tgz", + "integrity": "sha512-w1cEuf3S+DrLCQL7ET6kz+gmlJdbq9J7yXCSjK/OZCPA+qEN1WyF4ZAf0YYJa4/shHJra2t/d/r8SV4Ji+x+8Q==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "minimatch": "^5.0.1" + } + }, + "node_modules/filelist/node_modules/minimatch": { + "version": "5.1.6", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", + "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/fill-range": { "version": "7.1.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", @@ -2681,6 +2741,49 @@ "@pkgjs/parseargs": "^0.11.0" } }, + "node_modules/jake": { + "version": "10.9.2", + "resolved": "https://registry.npmjs.org/jake/-/jake-10.9.2.tgz", + "integrity": "sha512-2P4SQ0HrLQ+fw6llpLnOaGAvN2Zu6778SJMrCUwns4fOoG9ayrTiZk3VV8sCPkVZF8ab0zksVpS8FDY5pRCNBA==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "async": "^3.2.3", + "chalk": "^4.0.2", + "filelist": "^1.0.4", + "minimatch": "^3.1.2" + }, + "bin": { + "jake": "bin/cli.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/jake/node_modules/brace-expansion": { + "version": "1.1.12", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.12.tgz", + "integrity": "sha512-9T9UjW3r0UW5c1Q7GTwllptXwhvYmEzFhzMfZ9H7FQWt+uZePjZPjBP/W1ZEyZ1twGWom5/56TF4lPcqjnDHcg==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/jake/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, "node_modules/jest": { "version": "30.0.4", "resolved": "https://registry.npmjs.org/jest/-/jest-30.0.4.tgz", @@ -3371,6 +3474,13 @@ "node": ">=8" } }, + "node_modules/lodash.memoize": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz", + "integrity": "sha512-t7j+NzmgnQzTAYXcsHYLgimltOV1MXHtlOWf6GjL9Kj8GK5FInw5JotxvbOs+IvV1/Dzo04/fCGfLVs7aXb4Ag==", + "dev": true, + "license": "MIT" + }, "node_modules/lru-cache": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", @@ -4221,6 +4331,85 @@ "node": ">=8.0" } }, + "node_modules/ts-jest": { + "version": "29.4.0", + "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-29.4.0.tgz", + "integrity": "sha512-d423TJMnJGu80/eSgfQ5w/R+0zFJvdtTxwtF9KzFFunOpSeD+79lHJQIiAhluJoyGRbvj9NZJsl9WjCUo0ND7Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "bs-logger": "^0.2.6", + "ejs": "^3.1.10", + "fast-json-stable-stringify": "^2.1.0", + "json5": "^2.2.3", + "lodash.memoize": "^4.1.2", + "make-error": "^1.3.6", + "semver": "^7.7.2", + "type-fest": "^4.41.0", + "yargs-parser": "^21.1.1" + }, + "bin": { + "ts-jest": "cli.js" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || ^18.0.0 || >=20.0.0" + }, + "peerDependencies": { + "@babel/core": ">=7.0.0-beta.0 <8", + "@jest/transform": "^29.0.0 || ^30.0.0", + "@jest/types": "^29.0.0 || ^30.0.0", + "babel-jest": "^29.0.0 || ^30.0.0", + "jest": "^29.0.0 || ^30.0.0", + "jest-util": "^29.0.0 || ^30.0.0", + "typescript": ">=4.3 <6" + }, + "peerDependenciesMeta": { + "@babel/core": { + "optional": true + }, + "@jest/transform": { + "optional": true + }, + "@jest/types": { + "optional": true + }, + "babel-jest": { + "optional": true + }, + "esbuild": { + "optional": true + }, + "jest-util": { + "optional": true + } + } + }, + "node_modules/ts-jest/node_modules/semver": { + "version": "7.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.2.tgz", + "integrity": "sha512-RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJemA==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/ts-jest/node_modules/type-fest": { + "version": "4.41.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.41.0.tgz", + "integrity": "sha512-TeTSQ6H5YHvpqVwBRcnLDCBnDOHWYu7IvGbHT6N8AOymcr9PJGjc1GTtiWZTYg0NCgYwvnYWEkVChQAr9bjfwA==", + "dev": true, + "license": "(MIT OR CC0-1.0)", + "engines": { + "node": ">=16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/ts-node": { "version": "10.9.2", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz", diff --git a/package.json b/package.json index f9371ee..4b1fa23 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,9 @@ "description": "", "main": "index.js", "scripts": { - "test": "jest" + "test": "jest", + "coverage": "jest --coverage" + }, "repository": { "type": "git", @@ -22,6 +24,7 @@ "devDependencies": { "@types/jest": "^30.0.0", "jest": "^30.0.4", + "ts-jest": "^29.4.0", "ts-node": "^10.9.2", "typescript": "^5.8.3" } diff --git a/test/test-line.test.ts b/test/test-line.test.ts new file mode 100644 index 0000000..9c28e4f --- /dev/null +++ b/test/test-line.test.ts @@ -0,0 +1,100 @@ +import Line from "../modules/ecs6-class/line"; +import Point from "../modules/ecs6-class/point"; + +describe('Line', () => { + it('should create a line with default points', () => { + const line = new Line(); + expect(line.point1.x).toBe(0); + expect(line.point1.y).toBe(0); + expect(line.point2.x).toBe(0); + expect(line.point2.y).toBe(0); + }); + + it('should calculate slope correctly', () => { + const p1 = new Point({ x: 1, y: 2 }); + const p2 = new Point({ x: 3, y: 6 }); + const line = new Line({ point1: p1, point2: p2 }); + line.calculateSlope(); + expect(line.slope).toBe((2 - 6) / (1 - 3)); // -4 / -2 = 2 + }); + + it('should calculate n (intercept) correctly', () => { + const p1 = new Point({ x: 1, y: 2 }); + const p2 = new Point({ x: 3, y: 6 }); + const line = new Line({ point1: p1, point2: p2 }); + line.calculateSlope(); + line.calculateNOfLineFunction(); + expect(line.n).toBe(0); // y = 2x, so n = 0 + }); + + it('should get point by X', () => { + const p1 = new Point({ x: 1, y: 2 }); + const p2 = new Point({ x: 3, y: 6 }); + const line = new Line({ point1: p1, point2: p2 }); + line.calculateSlope(); + line.calculateNOfLineFunction(); + const point = line.getPointByX(2); + expect(point?.x).toBe(2); + expect(point?.y).toBe(4); + }); + + it('should get point by Y', () => { + const p1 = new Point({ x: 1, y: 2 }); + const p2 = new Point({ x: 3, y: 6 }); + const line = new Line({ point1: p1, point2: p2 }); + line.calculateSlope(); + line.calculateNOfLineFunction(); + const point = line.getPointByY(8); + expect(point?.y).toBe(8); + expect(point?.x).toBe(4); + }); + it('should get point on X axis', () => { + const p1 = new Point({ x: 1, y: 2 }); + const p2 = new Point({ x: 3, y: 6 }); + const line = new Line({ point1: p1, point2: p2 }); + line.calculateSlope(); + line.calculateNOfLineFunction(); + const point = line.getPointOnXAsis(); + expect(point?.y).toBe(0); +}); + +it('should get point on Y axis', () => { + const p1 = new Point({ x: 1, y: 2 }); + const p2 = new Point({ x: 3, y: 6 }); + const line = new Line({ point1: p1, point2: p2 }); + line.calculateSlope(); + line.calculateNOfLineFunction(); + const point = line.getPointOnYAsis(); + expect(point?.x).toBe(0); +}); +it('should return undefined if slope or n is undefined', () => { + const line = new Line(); + expect(line.getPointByX(5)).toBeUndefined(); + expect(line.getPointByY(5)).toBeUndefined(); +}); +it('should not set n if slope is undefined', () => { + const line = new Line(); + line.calculateNOfLineFunction(); + expect(line.n).toBeUndefined(); +}); + +// it('should not set n if slope is 0', () => { +// const p1 = new Point({ x: 1, y: 2 }); +// const p2 = new Point({ x: 3, y: 2 }); // אותו y -> שיפוע 0 +// const line = new Line({ point1: p1, point2: p2 }); +// line.calculateSlope(); +// line.calculateNOfLineFunction(); + +// expect(line.n).toBeUndefined(); + +// }); +it('should not set n if slope is 0', () => { + const p1 = new Point({ x: 1, y: 2 }); + const p2 = new Point({ x: 3, y: 2 }); // אותו y -> שיפוע 0 + const line = new Line({ point1: p1, point2: p2 }); + line.calculateSlope(); + line.calculateNOfLineFunction(); + // expect(line.slope).toBeCloseTo(0); + expect(line.n).toBeUndefined(); +}); +}); \ No newline at end of file diff --git a/test/test-point.test.ts b/test/test-point.test.ts new file mode 100644 index 0000000..d9b75f4 --- /dev/null +++ b/test/test-point.test.ts @@ -0,0 +1,47 @@ +import Point from "../modules/ecs6-class/point"; + +describe('Point', () => { + it('should create a point at (0,0) by default', () => { + const p = new Point(); + expect(p.x).toBe(0); + expect(p.y).toBe(0); + }); + + it('should create a point at given coordinates', () => { + const p = new Point({ x: 5, y: 7 }); + expect(p.x).toBe(5); + expect(p.y).toBe(7); + }); + + it('should move vertically', () => { + const p = new Point({ x: 1, y: 1 }); + p.moveVertical(3); + expect(p.y).toBe(4); + }); + + it('should move horizontally', () => { + const p = new Point({ x: 1, y: 1 }); + p.moveHorizontal(-2); + expect(p.x).toBe(-1); + }); + + +}); +// import Point from "../modules/ecs6-class/point"; +// import { calculateDistance } from "../modules/geometry-calculation"; + +// describe("calculateDistance", () => { +// it("should calculate distance only on x axis (y is ignored)", () => { +// const p1 = new Point({ x: 1, y: 2 }); +// const p2 = new Point({ x: 4, y: 10 }); +// // הפונקציה מתעלמת מה-y, לכן התוצאה היא |4-1| = 3 +// expect(calculateDistance(p1, p2)).toBe(3); +// }); + +// it("should return 0 for same x", () => { +// const p1 = new Point({ x: 5, y: 2 }); +// const p2 = new Point({ x: 5, y: 100 }); +// // הפונקציה מתעלמת מה-y, לכן התוצאה היא 0 +// expect(calculateDistance(p1, p2)).toBe(0); +// }); +// }); \ No newline at end of file From c640dd59689b490541f1675d28ed9c8f2ff29304 Mon Sep 17 00:00:00 2001 From: fm Date: Sun, 13 Jul 2025 10:46:03 +0300 Subject: [PATCH 2/7] try pass to branch --- test/test-point.test.ts | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/test/test-point.test.ts b/test/test-point.test.ts index d9b75f4..ae3d211 100644 --- a/test/test-point.test.ts +++ b/test/test-point.test.ts @@ -27,21 +27,3 @@ describe('Point', () => { }); -// import Point from "../modules/ecs6-class/point"; -// import { calculateDistance } from "../modules/geometry-calculation"; - -// describe("calculateDistance", () => { -// it("should calculate distance only on x axis (y is ignored)", () => { -// const p1 = new Point({ x: 1, y: 2 }); -// const p2 = new Point({ x: 4, y: 10 }); -// // הפונקציה מתעלמת מה-y, לכן התוצאה היא |4-1| = 3 -// expect(calculateDistance(p1, p2)).toBe(3); -// }); - -// it("should return 0 for same x", () => { -// const p1 = new Point({ x: 5, y: 2 }); -// const p2 = new Point({ x: 5, y: 100 }); -// // הפונקציה מתעלמת מה-y, לכן התוצאה היא 0 -// expect(calculateDistance(p1, p2)).toBe(0); -// }); -// }); \ No newline at end of file From d0d2a7a09e6b20c7c312911854fe9e6931e371cf Mon Sep 17 00:00:00 2001 From: fm Date: Sun, 13 Jul 2025 12:07:40 +0300 Subject: [PATCH 3/7] fix the mistake --- modules/ecs6-class/line.ts | 15 +------- test/test-geometry.test.ts | 70 ++++++++++++++++++++++++++++++++++++++ test/test-line.test.ts | 25 +++----------- 3 files changed, 76 insertions(+), 34 deletions(-) create mode 100644 test/test-geometry.test.ts diff --git a/modules/ecs6-class/line.ts b/modules/ecs6-class/line.ts index 7405a67..7d37a52 100644 --- a/modules/ecs6-class/line.ts +++ b/modules/ecs6-class/line.ts @@ -32,20 +32,7 @@ export default class Line { } - // getPointByX(x: number) { - // if (this.slope && this.n) { - // let y = this.slope * x + this.n - // return new Point({ x, y }) - // } - // } - - // getPointByY(y: number) { - // if (this.slope && this.n) { - // let x = (y - this.n) / this.slope; - // return new Point({ x, y }) - // } - // } - + getPointByX(x: number) { if (this.slope !== undefined && this.n !== undefined) { let y = this.slope * x + this.n; diff --git a/test/test-geometry.test.ts b/test/test-geometry.test.ts new file mode 100644 index 0000000..8c86918 --- /dev/null +++ b/test/test-geometry.test.ts @@ -0,0 +1,70 @@ +import Point from "../modules/ecs6-class/point"; +import Line from "../modules/ecs6-class/line"; +import { calculateDistance, calculateJunctionPoint, isPointOnLine } from "../modules/geometry-calculation"; + +describe("geometry-calculation", () => { + describe("calculateDistance", () => { + it("should calculate distance only on x axis (y is ignored)", () => { + const p1 = new Point({ x: 1, y: 2 }); + const p2 = new Point({ x: 4, y: 10 }); + expect(calculateDistance(p1, p2)).toBe(3); + }); + + it("should return 0 for same x", () => { + const p1 = new Point({ x: 5, y: 2 }); + const p2 = new Point({ x: 5, y: 100 }); + expect(calculateDistance(p1, p2)).toBe(0); + }); + }); + + describe("calculateJunctionPoint", () => { + it("should return true for identical lines", () => { + const l1 = new Line({ point1: new Point({ x: 0, y: 0 }), point2: new Point({ x: 1, y: 1 }) }); + l1.calculateSlope(); + l1.calculateNOfLineFunction(); + const l2 = new Line({ point1: new Point({ x: 2, y: 2 }), point2: new Point({ x: 3, y: 3 }) }); + l2.calculateSlope(); + l2.calculateNOfLineFunction(); + expect(calculateJunctionPoint(l1, l2)).toBe(true); + }); + + it("should return false for parallel lines with different n", () => { + const l1 = new Line({ point1: new Point({ x: 0, y: 0 }), point2: new Point({ x: 1, y: 1 }) }); + l1.calculateSlope(); + l1.calculateNOfLineFunction(); + const l2 = new Line({ point1: new Point({ x: 0, y: 1 }), point2: new Point({ x: 1, y: 2 }) }); + l2.calculateSlope(); + l2.calculateNOfLineFunction(); + expect(calculateJunctionPoint(l1, l2)).toBe(false); + }); + + it("should return a Point for intersecting lines", () => { + const l1 = new Line({ point1: new Point({ x: 0, y: 0 }), point2: new Point({ x: 1, y: 1 }) }); + l1.calculateSlope(); + l1.calculateNOfLineFunction(); + const l2 = new Line({ point1: new Point({ x: 0, y: 1 }), point2: new Point({ x: 1, y: 0 }) }); + l2.calculateSlope(); + l2.calculateNOfLineFunction(); + const result = calculateJunctionPoint(l1, l2); + expect(result).toBeInstanceOf(Point); + }); + }); + + describe("isPointOnLine", () => { + it("should return true if point is on the line", () => { + const l = new Line({ point1: new Point({ x: 0, y: 0 }), point2: new Point({ x: 2, y: 2 }) }); + l.calculateSlope(); + l.calculateNOfLineFunction(); + const p = new Point({ x: 1, y: 1 }); + expect(isPointOnLine(l, p)).toBe(true); + }); + + it("should return false if point is not on the line", () => { + const l = new Line({ point1: new Point({ x: 0, y: 0 }), point2: new Point({ x: 2, y: 2 }) }); + l.calculateSlope(); + l.calculateNOfLineFunction(); + const p = new Point({ x: 1, y: 2 }); + expect(isPointOnLine(l, p)).toBe(false); + }); + }); +}); \ No newline at end of file diff --git a/test/test-line.test.ts b/test/test-line.test.ts index 9c28e4f..1506b35 100644 --- a/test/test-line.test.ts +++ b/test/test-line.test.ts @@ -10,13 +10,7 @@ describe('Line', () => { expect(line.point2.y).toBe(0); }); - it('should calculate slope correctly', () => { - const p1 = new Point({ x: 1, y: 2 }); - const p2 = new Point({ x: 3, y: 6 }); - const line = new Line({ point1: p1, point2: p2 }); - line.calculateSlope(); - expect(line.slope).toBe((2 - 6) / (1 - 3)); // -4 / -2 = 2 - }); + it('should calculate n (intercept) correctly', () => { const p1 = new Point({ x: 1, y: 2 }); @@ -24,7 +18,7 @@ describe('Line', () => { const line = new Line({ point1: p1, point2: p2 }); line.calculateSlope(); line.calculateNOfLineFunction(); - expect(line.n).toBe(0); // y = 2x, so n = 0 + expect(line.n).toBe(0); }); it('should get point by X', () => { @@ -78,23 +72,14 @@ it('should not set n if slope is undefined', () => { expect(line.n).toBeUndefined(); }); -// it('should not set n if slope is 0', () => { -// const p1 = new Point({ x: 1, y: 2 }); -// const p2 = new Point({ x: 3, y: 2 }); // אותו y -> שיפוע 0 -// const line = new Line({ point1: p1, point2: p2 }); -// line.calculateSlope(); -// line.calculateNOfLineFunction(); - -// expect(line.n).toBeUndefined(); - -// }); + it('should not set n if slope is 0', () => { const p1 = new Point({ x: 1, y: 2 }); - const p2 = new Point({ x: 3, y: 2 }); // אותו y -> שיפוע 0 + const p2 = new Point({ x: 3, y: 2 }); const line = new Line({ point1: p1, point2: p2 }); line.calculateSlope(); line.calculateNOfLineFunction(); - // expect(line.slope).toBeCloseTo(0); + expect(line.n).toBeUndefined(); }); }); \ No newline at end of file From 2ecb55c0add721e0fedb03f1fb30cae70ae4d8a7 Mon Sep 17 00:00:00 2001 From: fm Date: Sun, 13 Jul 2025 16:45:07 +0300 Subject: [PATCH 4/7] try2 fix --- modules/geometry-calculation.ts | 20 +++-- test/test-geometry.test.ts | 145 ++++++++++++++++++++++---------- 2 files changed, 113 insertions(+), 52 deletions(-) diff --git a/modules/geometry-calculation.ts b/modules/geometry-calculation.ts index 22ab78b..c395ed6 100644 --- a/modules/geometry-calculation.ts +++ b/modules/geometry-calculation.ts @@ -3,14 +3,18 @@ import Point from './ecs6-class/point'; export const calculateDistance = (point1: Point, point2: Point): number => { let distanceX = (point2.x - point1.x) ** 2; - let distanceY = (point2.y - point2.y) ** 2; + let distanceY = (point2.y - point1.y) ** 2; const distance = Math.sqrt(distanceX + distanceY); return distance; } export const calculateJunctionPoint = (line1: Line, line2: Line): Boolean | Point | undefined => { - if (line1.slope === line2.slope) { - if (line1.n === line2.n) { + if (line1.slope ===undefined|| line2.slope===undefined + || line1.n === undefined || line2.n === undefined) { + return undefined; + } + if (line1.slope === line2.slope) { + if(line1.n === line2.n) { return true } else { @@ -18,24 +22,22 @@ export const calculateJunctionPoint = (line1: Line, line2: Line): Boolean | Poin } } else { - if (line1.n !== undefined && line1.slope !== undefined && line2.n !== undefined && line2.slope !== undefined) { + const x = (line1.n - line2.n) / (line2.slope - line1.slope) const junctionPoint = line1.getPointByX(x); return junctionPoint } } -} + export const isPointOnLine = (line: Line, point: Point): Boolean => { const proxyLine = new Line({ point1: line.point1, point2: point }) proxyLine.calculateSlope() if (line.slope === proxyLine.slope) { proxyLine.calculateNOfLineFunction() - if (line.n === proxyLine.n) { - return true - } + } return false } - +// diff --git a/test/test-geometry.test.ts b/test/test-geometry.test.ts index 8c86918..71a02ba 100644 --- a/test/test-geometry.test.ts +++ b/test/test-geometry.test.ts @@ -1,70 +1,129 @@ + + import Point from "../modules/ecs6-class/point"; import Line from "../modules/ecs6-class/line"; import { calculateDistance, calculateJunctionPoint, isPointOnLine } from "../modules/geometry-calculation"; describe("geometry-calculation", () => { describe("calculateDistance", () => { - it("should calculate distance only on x axis (y is ignored)", () => { - const p1 = new Point({ x: 1, y: 2 }); - const p2 = new Point({ x: 4, y: 10 }); - expect(calculateDistance(p1, p2)).toBe(3); + it("should calculate the correct distance between two points", () => { + const p1 = new Point({ x: 0, y: 0 }); + const p2 = new Point({ x: 3, y: 4 }); + expect(calculateDistance(p1, p2)).toBe(5); }); + }); - it("should return 0 for same x", () => { - const p1 = new Point({ x: 5, y: 2 }); - const p2 = new Point({ x: 5, y: 100 }); - expect(calculateDistance(p1, p2)).toBe(0); - }); - }); describe("calculateJunctionPoint", () => { it("should return true for identical lines", () => { - const l1 = new Line({ point1: new Point({ x: 0, y: 0 }), point2: new Point({ x: 1, y: 1 }) }); - l1.calculateSlope(); - l1.calculateNOfLineFunction(); - const l2 = new Line({ point1: new Point({ x: 2, y: 2 }), point2: new Point({ x: 3, y: 3 }) }); - l2.calculateSlope(); - l2.calculateNOfLineFunction(); - expect(calculateJunctionPoint(l1, l2)).toBe(true); + const p1 = new Point({ x: 0, y: 0 }); + const p2 =new Point({ x: 2, y: 2 }); + const line1 = new Line({ point1: p1, point2: p2 }); + const line2 = new Line({ point1: p1, point2: p2 }); + + line1.calculateSlope(); + line1.calculateNOfLineFunction(); +// + line2.calculateNOfLineFunction(); + expect(calculateJunctionPoint(line1, line2)).toBe(true); }); it("should return false for parallel lines with different n", () => { - const l1 = new Line({ point1: new Point({ x: 0, y: 0 }), point2: new Point({ x: 1, y: 1 }) }); - l1.calculateSlope(); - l1.calculateNOfLineFunction(); - const l2 = new Line({ point1: new Point({ x: 0, y: 1 }), point2: new Point({ x: 1, y: 2 }) }); - l2.calculateSlope(); - l2.calculateNOfLineFunction(); - expect(calculateJunctionPoint(l1, l2)).toBe(false); + const line1 = new Line({ point1: new Point({ x: 0, y: 0 }), point2: new Point({ x: 1, y: 1 }) }); + const line2 = new Line({ point1: new Point({ x: 0, y: 1 }), point2: new Point({ x: 1, y: 2 }) }); + line1.calculateSlope(); + line1.calculateNOfLineFunction(); + line2.calculateSlope(); + line2.calculateNOfLineFunction(); + expect(calculateJunctionPoint(line1, line2)).toBe(false); }); it("should return a Point for intersecting lines", () => { - const l1 = new Line({ point1: new Point({ x: 0, y: 0 }), point2: new Point({ x: 1, y: 1 }) }); - l1.calculateSlope(); - l1.calculateNOfLineFunction(); - const l2 = new Line({ point1: new Point({ x: 0, y: 1 }), point2: new Point({ x: 1, y: 0 }) }); - l2.calculateSlope(); - l2.calculateNOfLineFunction(); - const result = calculateJunctionPoint(l1, l2); + const line1 = new Line({ point1: new Point({ x: 0, y: 0 }), point2: new Point({ x: 1, y: 1 }) }); + const line2 = new Line({ point1: new Point({ x: 0, y: 1 }), point2: new Point({ x: 1, y: 0 }) }); + line1.calculateSlope(); + line1.calculateNOfLineFunction(); + line2.calculateSlope(); + line2.calculateNOfLineFunction(); + const result= calculateJunctionPoint(line1, line2) expect(result).toBeInstanceOf(Point); + expect((result as Point).x).toBeCloseTo(0.5,4); + expect((result as Point).y).toBeCloseTo(0.5,4); }); - }); + + it("should return undefined if slope or n is undefined", () => { + const line1 = new Line({ point1: new Point({ x: 0, y: 2 }), point2: new Point({ x: 1, y: 1 }) }); + const line2 = new Line({ point1: new Point({ x: 2, y: 2 }), point2: new Point({ x: 3, y: 3 }) }); + + expect(calculateJunctionPoint(line1, line2)).toBeUndefined(); + }); + it("should return false if slope is equal but n is different", () => { + const line1 = new Line({ point1: new Point({ x: 0, y: 1 }), point2: new Point({ x: 2, y: 3 }) }); + const line2 = new Line({ point1: new Point({ x: 0, y: 2 }), point2: new Point({ x: 2, y: 4 }) }); + line1.calculateSlope(); + line1.calculateNOfLineFunction(); + line2.calculateSlope(); + line2.calculateNOfLineFunction(); + + expect(calculateJunctionPoint(line1, line2)).toBe(false); + }); + + + + }); + describe("isPointOnLine", () => { it("should return true if point is on the line", () => { - const l = new Line({ point1: new Point({ x: 0, y: 0 }), point2: new Point({ x: 2, y: 2 }) }); - l.calculateSlope(); - l.calculateNOfLineFunction(); - const p = new Point({ x: 1, y: 1 }); - expect(isPointOnLine(l, p)).toBe(true); + const line = new Line({ point1: new Point({ x: 0, y: 0 }), point2: new Point({ x: 2, y: 2 }) }); + line.calculateSlope(); + line.calculateNOfLineFunction(); + const point = new Point({ x: 1, y: 2 }); + expect(isPointOnLine(line, point)).toBe(false); }); it("should return false if point is not on the line", () => { - const l = new Line({ point1: new Point({ x: 0, y: 0 }), point2: new Point({ x: 2, y: 2 }) }); - l.calculateSlope(); - l.calculateNOfLineFunction(); - const p = new Point({ x: 1, y: 2 }); - expect(isPointOnLine(l, p)).toBe(false); + const line = new Line({ point1: new Point({ x: 0, y: 0 }), point2: new Point({ x: 2, y: 2 }) }); + line.calculateSlope(); + line.calculateNOfLineFunction(); + const point = new Point({ x: 1, y: 2 }); + expect(isPointOnLine(line, point)).toBe(false); }); + + }); -}); \ No newline at end of file + it("should return false if line points are diffrent", () => { + const line=new Line({point1: new Point({ x: 0, y: 0 }) ,point2:new Point({x:2,y:2}) }); + + line.calculateSlope(); + line.calculateNOfLineFunction(); + const point = new Point({ x: 1, y:3 }); + expect(isPointOnLine(line, point)).toBe(false); + }); + it("should return false if proxyLine slope is undefined", () => { + const line = new Line({ point1: new Point({ x: 0, y: 0 }), point2: new Point({ x: 2, y: 2 }) }); + line.calculateSlope(); + line.calculateNOfLineFunction(); + + const point = new Point({ x: 1, y: 1 }); + expect(isPointOnLine(line, point)).toBe(false); + }); +// + it("should return false if slope is equal but n is different", () => { + const line = new Line({ point1: new Point({ x: 0, y: 1 }), point2: new Point({ x: 2, y: 3 }) }); + line.calculateSlope(); + line.calculateNOfLineFunction(); + + const point = new Point({ x: 1, y: 0 }); + expect(isPointOnLine(line, point)).toBe(false); + }); + + + }); + + + + + + + \ No newline at end of file From 2a26931d15d94d72da8f1ed3ea6b88598d79e33c Mon Sep 17 00:00:00 2001 From: fm Date: Tue, 15 Jul 2025 14:47:52 +0300 Subject: [PATCH 5/7] try3 if the project good --- modules/geometry-calculation.ts | 49 +++++------- test/test-geometry.test.ts | 137 +++++++++----------------------- 2 files changed, 61 insertions(+), 125 deletions(-) diff --git a/modules/geometry-calculation.ts b/modules/geometry-calculation.ts index c395ed6..fd2bb81 100644 --- a/modules/geometry-calculation.ts +++ b/modules/geometry-calculation.ts @@ -8,36 +8,31 @@ export const calculateDistance = (point1: Point, point2: Point): number => { return distance; } -export const calculateJunctionPoint = (line1: Line, line2: Line): Boolean | Point | undefined => { - if (line1.slope ===undefined|| line2.slope===undefined - || line1.n === undefined || line2.n === undefined) { - return undefined; - } - if (line1.slope === line2.slope) { - if(line1.n === line2.n) { - return true - } - else { - return false - } + +export const calculateJunctionPoint = (line1: Line, line2: Line): boolean | Point | undefined => { + if (line1.slope === undefined || line2.slope === undefined || line1.n === undefined || line2.n === undefined) { + return undefined; } - else { - - const x = (line1.n - line2.n) / (line2.slope - line1.slope) - const junctionPoint = line1.getPointByX(x); - return junctionPoint - } + + + if (line1.slope === line2.slope && line1.n === line2.n) { + return true; + } else if (line1.slope === line2.slope) { + return false; + } else { + const x = (line1.n - line2.n) / (line2.slope - line1.slope); + const junctionPoint = line1.getPointByX(x); + return junctionPoint; } +}; -export const isPointOnLine = (line: Line, point: Point): Boolean => { - const proxyLine = new Line({ point1: line.point1, point2: point }) - proxyLine.calculateSlope() +export const isPointOnLine = (line: Line, point: Point): boolean => { + const proxyLine = new Line({ point1: line.point1, point2: point }); + proxyLine.calculateSlope(); if (line.slope === proxyLine.slope) { - proxyLine.calculateNOfLineFunction() - + proxyLine.calculateNOfLineFunction(); + return line.n === proxyLine.n; } - return false -} - -// + return false; +}; diff --git a/test/test-geometry.test.ts b/test/test-geometry.test.ts index 71a02ba..9b5e7b4 100644 --- a/test/test-geometry.test.ts +++ b/test/test-geometry.test.ts @@ -11,119 +11,60 @@ describe("geometry-calculation", () => { const p2 = new Point({ x: 3, y: 4 }); expect(calculateDistance(p1, p2)).toBe(5); }); - }); - - - describe("calculateJunctionPoint", () => { - it("should return true for identical lines", () => { - const p1 = new Point({ x: 0, y: 0 }); - const p2 =new Point({ x: 2, y: 2 }); - const line1 = new Line({ point1: p1, point2: p2 }); - const line2 = new Line({ point1: p1, point2: p2 }); - - line1.calculateSlope(); - line1.calculateNOfLineFunction(); -// - line2.calculateNOfLineFunction(); - expect(calculateJunctionPoint(line1, line2)).toBe(true); }); - - it("should return false for parallel lines with different n", () => { - const line1 = new Line({ point1: new Point({ x: 0, y: 0 }), point2: new Point({ x: 1, y: 1 }) }); - const line2 = new Line({ point1: new Point({ x: 0, y: 1 }), point2: new Point({ x: 1, y: 2 }) }); - line1.calculateSlope(); - line1.calculateNOfLineFunction(); - line2.calculateSlope(); - line2.calculateNOfLineFunction(); - expect(calculateJunctionPoint(line1, line2)).toBe(false); +describe("calculateJunctionPoint", () => { + it("should return undefined if line1 slope is undefined", () => { + const line1 = new Line({ slope: undefined, n: 1 }); + const line2 = new Line({ slope: 2, n: 1 }); + expect(calculateJunctionPoint(line1, line2)).toBeUndefined(); }); - it("should return a Point for intersecting lines", () => { - const line1 = new Line({ point1: new Point({ x: 0, y: 0 }), point2: new Point({ x: 1, y: 1 }) }); - const line2 = new Line({ point1: new Point({ x: 0, y: 1 }), point2: new Point({ x: 1, y: 0 }) }); - line1.calculateSlope(); - line1.calculateNOfLineFunction(); - line2.calculateSlope(); - line2.calculateNOfLineFunction(); - const result= calculateJunctionPoint(line1, line2) - expect(result).toBeInstanceOf(Point); - expect((result as Point).x).toBeCloseTo(0.5,4); - expect((result as Point).y).toBeCloseTo(0.5,4); + it("should return undefined if line2 slope is undefined", () => { + const line1 = new Line({ slope: 1, n: 1 }); + const line2 = new Line({ slope: undefined, n: 2 }); + expect(calculateJunctionPoint(line1, line2)).toBeUndefined(); }); - it("should return undefined if slope or n is undefined", () => { - const line1 = new Line({ point1: new Point({ x: 0, y: 2 }), point2: new Point({ x: 1, y: 1 }) }); - const line2 = new Line({ point1: new Point({ x: 2, y: 2 }), point2: new Point({ x: 3, y: 3 }) }); - - expect(calculateJunctionPoint(line1, line2)).toBeUndefined(); + it("should return true for identical lines", () => { + const line1 = new Line({ slope: 1, n: 1 }); + const line2 = new Line({ slope: 1, n: 1 }); + expect(calculateJunctionPoint(line1, line2)).toBe(true); }); - it("should return false if slope is equal but n is different", () => { - const line1 = new Line({ point1: new Point({ x: 0, y: 1 }), point2: new Point({ x: 2, y: 3 }) }); - const line2 = new Line({ point1: new Point({ x: 0, y: 2 }), point2: new Point({ x: 2, y: 4 }) }); - line1.calculateSlope(); - line1.calculateNOfLineFunction(); - line2.calculateSlope(); - line2.calculateNOfLineFunction(); - + + it("should return false for parallel lines", () => { + const line1 = new Line({ slope: 1, n: 1 }); + const line2 = new Line({ slope: 1, n: 2 }); expect(calculateJunctionPoint(line1, line2)).toBe(false); }); - - - - }); - - describe("isPointOnLine", () => { + it("should return a point for intersecting lines", () => { + const line1 = new Line({ slope: 1, n: 1 }); + const line2 = new Line({ slope: -1, n: 2 }); + const point = calculateJunctionPoint(line1, line2); + expect(point).toBeDefined(); + expect(point).toHaveProperty('x'); + expect(point).toHaveProperty('y'); + }); +}); + describe("isPointOnLine", () => { it("should return true if point is on the line", () => { - const line = new Line({ point1: new Point({ x: 0, y: 0 }), point2: new Point({ x: 2, y: 2 }) }); - line.calculateSlope(); - line.calculateNOfLineFunction(); - const point = new Point({ x: 1, y: 2 }); - expect(isPointOnLine(line, point)).toBe(false); + const line = new Line({ point1: new Point({ x: 0, y: 0 }), point2: new Point({ x: 2, y: 2 }) }); + line.calculateSlope(); + line.calculateNOfLineFunction(); + const point = new Point({ x: 1, y: 1 }); + expect(isPointOnLine(line, point)).toBe(true); }); it("should return false if point is not on the line", () => { - const line = new Line({ point1: new Point({ x: 0, y: 0 }), point2: new Point({ x: 2, y: 2 }) }); - line.calculateSlope(); - line.calculateNOfLineFunction(); - const point = new Point({ x: 1, y: 2 }); - expect(isPointOnLine(line, point)).toBe(false); + const line = new Line({ point1: new Point({ x: 0, y: 0 }), point2: new Point({ x: 2, y: 2 }) }); + line.calculateSlope(); + line.calculateNOfLineFunction(); + const point = new Point({ x: 1, y: 2 }); + expect(isPointOnLine(line, point)).toBe(false); }); - - }); - it("should return false if line points are diffrent", () => { - const line=new Line({point1: new Point({ x: 0, y: 0 }) ,point2:new Point({x:2,y:2}) }); - - line.calculateSlope(); - line.calculateNOfLineFunction(); - const point = new Point({ x: 1, y:3 }); - expect(isPointOnLine(line, point)).toBe(false); - }); - it("should return false if proxyLine slope is undefined", () => { - const line = new Line({ point1: new Point({ x: 0, y: 0 }), point2: new Point({ x: 2, y: 2 }) }); - line.calculateSlope(); - line.calculateNOfLineFunction(); - - const point = new Point({ x: 1, y: 1 }); - expect(isPointOnLine(line, point)).toBe(false); - }); -// - it("should return false if slope is equal but n is different", () => { - const line = new Line({ point1: new Point({ x: 0, y: 1 }), point2: new Point({ x: 2, y: 3 }) }); - line.calculateSlope(); - line.calculateNOfLineFunction(); - - const point = new Point({ x: 1, y: 0 }); - expect(isPointOnLine(line, point)).toBe(false); - }); - - - }); - - - - +}); + }); \ No newline at end of file From 826312f9f186dfa89b3173a1596316c68bd55a1f Mon Sep 17 00:00:00 2001 From: fm Date: Tue, 15 Jul 2025 17:12:29 +0300 Subject: [PATCH 6/7] try3 if the project good --- modules/geometry-calculation.ts | 24 ++++++---- test/test-geometry.test.ts | 82 ++++++++++++++++----------------- 2 files changed, 55 insertions(+), 51 deletions(-) diff --git a/modules/geometry-calculation.ts b/modules/geometry-calculation.ts index fd2bb81..b2115d1 100644 --- a/modules/geometry-calculation.ts +++ b/modules/geometry-calculation.ts @@ -9,24 +9,28 @@ export const calculateDistance = (point1: Point, point2: Point): number => { } + export const calculateJunctionPoint = (line1: Line, line2: Line): boolean | Point | undefined => { if (line1.slope === undefined || line2.slope === undefined || line1.n === undefined || line2.n === undefined) { - return undefined; + return undefined; } - + if (line1.slope === line2.slope && line1.n === line2.n) { return true; - } else if (line1.slope === line2.slope) { - return false; - } else { - const x = (line1.n - line2.n) / (line2.slope - line1.slope); - const junctionPoint = line1.getPointByX(x); - return junctionPoint; } -}; + + if (line1.slope === line2.slope) { + return false; + } + + const x = (line1.n - line2.n) / (line2.slope - line1.slope); + const y = line1.slope * x + line1.n; + const junctionPoint = new Point({x, y}); + return junctionPoint; +}; export const isPointOnLine = (line: Line, point: Point): boolean => { const proxyLine = new Line({ point1: line.point1, point2: point }); proxyLine.calculateSlope(); @@ -35,4 +39,4 @@ export const isPointOnLine = (line: Line, point: Point): boolean => { return line.n === proxyLine.n; } return false; -}; + }; diff --git a/test/test-geometry.test.ts b/test/test-geometry.test.ts index 9b5e7b4..78f66cb 100644 --- a/test/test-geometry.test.ts +++ b/test/test-geometry.test.ts @@ -1,70 +1,70 @@ + + import Point from "../modules/ecs6-class/point"; import Line from "../modules/ecs6-class/line"; import { calculateDistance, calculateJunctionPoint, isPointOnLine } from "../modules/geometry-calculation"; - -describe("geometry-calculation", () => { + describe("geometry-calculation", () => { describe("calculateDistance", () => { + it("should calculate the correct distance between two points", () => { const p1 = new Point({ x: 0, y: 0 }); const p2 = new Point({ x: 3, y: 4 }); expect(calculateDistance(p1, p2)).toBe(5); }); - }); -describe("calculateJunctionPoint", () => { + }); + + describe("calculateJunctionPoint", () => { it("should return undefined if line1 slope is undefined", () => { - const line1 = new Line({ slope: undefined, n: 1 }); - const line2 = new Line({ slope: 2, n: 1 }); - expect(calculateJunctionPoint(line1, line2)).toBeUndefined(); + const line1 = new Line({ slope: undefined, n: 1 }); + const line2 = new Line({ slope: 2, n: 1 }); + expect(calculateJunctionPoint(line1, line2)).toBeUndefined(); }); it("should return undefined if line2 slope is undefined", () => { - const line1 = new Line({ slope: 1, n: 1 }); - const line2 = new Line({ slope: undefined, n: 2 }); - expect(calculateJunctionPoint(line1, line2)).toBeUndefined(); + const line1 = new Line({ slope: 1, n: 1 }); + const line2 = new Line({ slope: undefined, n: 2 }); + expect(calculateJunctionPoint(line1, line2)).toBeUndefined(); }); - it("should return true for identical lines", () => { - const line1 = new Line({ slope: 1, n: 1 }); - const line2 = new Line({ slope: 1, n: 1 }); - expect(calculateJunctionPoint(line1, line2)).toBe(true); + it("should return true for identical lines", () => { + const line1 = new Line({ slope: 1, n: 0 }); + const line2 = new Line({ slope: 1, n: 0 }); + expect(calculateJunctionPoint(line1, line2)).toBe(true); }); - it("should return false for parallel lines", () => { - const line1 = new Line({ slope: 1, n: 1 }); - const line2 = new Line({ slope: 1, n: 2 }); - expect(calculateJunctionPoint(line1, line2)).toBe(false); + it("should return false for parallel lines with different intercepts", () => { + const line1 = new Line({ slope: 2, n: 1 }); + const line2 = new Line({ slope: 2, n: 3 }); + expect(calculateJunctionPoint(line1, line2)).toBe(false); }); it("should return a point for intersecting lines", () => { - const line1 = new Line({ slope: 1, n: 1 }); - const line2 = new Line({ slope: -1, n: 2 }); - const point = calculateJunctionPoint(line1, line2); - expect(point).toBeDefined(); - expect(point).toHaveProperty('x'); - expect(point).toHaveProperty('y'); + const line1 = new Line({ slope: 1, n: 1 }); + const line2 = new Line({ slope: -1, n: 2 }); + const point = calculateJunctionPoint(line1, line2); + expect(point).toBeDefined(); + expect(point).toHaveProperty('x'); + expect(point).toHaveProperty('y'); }); -}); - describe("isPointOnLine", () => { + }); + + describe("isPointOnLine", () => { it("should return true if point is on the line", () => { - const line = new Line({ point1: new Point({ x: 0, y: 0 }), point2: new Point({ x: 2, y: 2 }) }); - line.calculateSlope(); - line.calculateNOfLineFunction(); - const point = new Point({ x: 1, y: 1 }); - expect(isPointOnLine(line, point)).toBe(true); + const line = new Line({ point1: new Point({ x: 0, y: 0 }), point2: new Point({ x: 2, y: 2 }) }); + line.calculateSlope(); + line.calculateNOfLineFunction(); + const point = new Point({ x: 1, y: 1 }); + expect(isPointOnLine(line, point)).toBe(true); }); it("should return false if point is not on the line", () => { - const line = new Line({ point1: new Point({ x: 0, y: 0 }), point2: new Point({ x: 2, y: 2 }) }); - line.calculateSlope(); - line.calculateNOfLineFunction(); - const point = new Point({ x: 1, y: 2 }); - expect(isPointOnLine(line, point)).toBe(false); + const line = new Line({ point1: new Point({ x: 0, y: 0 }), point2: new Point({ x: 2, y: 2 }) }); + line.calculateSlope(); + line.calculateNOfLineFunction(); + const point = new Point({ x: 1, y: 2 }); + expect(isPointOnLine(line, point)).toBe(false); }); - - -}); }); - - \ No newline at end of file +}); \ No newline at end of file From d2402bf3fb33d014ef85e8baeafc0fb436e030ff Mon Sep 17 00:00:00 2001 From: fm Date: Tue, 15 Jul 2025 17:27:35 +0300 Subject: [PATCH 7/7] try4 --- test/test-geometry.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test-geometry.test.ts b/test/test-geometry.test.ts index 78f66cb..dd48811 100644 --- a/test/test-geometry.test.ts +++ b/test/test-geometry.test.ts @@ -67,4 +67,5 @@ import { calculateDistance, calculateJunctionPoint, isPointOnLine } from "../mod expect(isPointOnLine(line, point)).toBe(false); }); }); -}); \ No newline at end of file +}); +