-
Notifications
You must be signed in to change notification settings - Fork 9
tests #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
leShmn
wants to merge
4
commits into
gemtechd:main
Choose a base branch
from
leShmn:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
tests #5
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| const {createDefaultPreset} = require("ts-jest") | ||
|
|
||
| const tsJestTransformCfg = createDefaultPreset().transform; | ||
|
|
||
| /** @type {import ("jest").Config} **/ | ||
| module.exports = { | ||
| preset: "ts-jest", | ||
| testEnvironment: "node", | ||
| transform: { | ||
| ...tsJestTransformCfg, | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import Point from '../ecs6-class/point'; | ||
| import Line from '../ecs6-class/line'; | ||
| import { calculateDistance, calculateJunctionPoint, isPointOnLine } from '../geometry-calculation'; | ||
|
|
||
| describe('geometry-calculation module', () => { | ||
| test('calculateDistance returns correct distance', () => { | ||
| const p1 = new Point({ x: 0, y: 0 }); | ||
| const p2 = new Point({ x: 3, y: 4 }); | ||
| expect(calculateDistance(p1, p2)).toBe(5); // 3-4-5 triangle | ||
| }); | ||
|
|
||
| test('calculateJunctionPoint returns 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.slope = (p2.y - p1.y) / (p2.x - p1.x); | ||
| line1.n = p1.y - line1.slope * p1.x; | ||
| line2.slope = (p2.y - p1.y) / (p2.x - p1.x); | ||
| line2.n = p1.y - line2.slope * p1.x; | ||
| expect(calculateJunctionPoint(line1, line2)).toBe(true); | ||
| }); | ||
|
|
||
| test('calculateJunctionPoint returns false for parallel lines', () => { | ||
| const p1 = new Point({ x: 0, y: 0 }); | ||
| const p2 = new Point({ x: 2, y: 2 }); | ||
| const p3 = new Point({ x: 0, y: 1 }); | ||
| const p4 = new Point({ x: 2, y: 3 }); | ||
| const line1 = new Line({ point1: p1, point2: p2 }); | ||
| const line2 = new Line({ point1: p3, point2: p4 }); | ||
| line1.slope = (p2.y - p1.y) / (p2.x - p1.x); | ||
| line1.n = p1.y - line1.slope * p1.x; | ||
| line2.slope = (p4.y - p3.y) / (p4.x - p3.x); | ||
| line2.n = p3.y - line2.slope * p3.x; | ||
| expect(calculateJunctionPoint(line1, line2)).toBe(false); | ||
| }); | ||
|
|
||
| test('calculateJunctionPoint returns intersection point for crossing lines', () => { | ||
| const p1 = new Point({ x: 0, y: 0 }); | ||
| const p2 = new Point({ x: 2, y: 2 }); | ||
| const p3 = new Point({ x: 0, y: 2 }); | ||
| const p4 = new Point({ x: 2, y: 0 }); | ||
| const line1 = new Line({ point1: p1, point2: p2 }); | ||
| const line2 = new Line({ point1: p3, point2: p4 }); | ||
| line1.slope = (p2.y - p1.y) / (p2.x - p1.x); | ||
| line1.n = p1.y - line1.slope * p1.x; | ||
| line2.slope = (p4.y - p3.y) / (p4.x - p3.x); | ||
| line2.n = p3.y - line2.slope * p3.x; | ||
| const intersection = calculateJunctionPoint(line1, line2); | ||
| if (intersection instanceof Point) { | ||
| expect(intersection.x).toBeCloseTo(1); | ||
| expect(intersection.y).toBeCloseTo(1); | ||
| } else { | ||
| throw new Error('Intersection is not a Point'); | ||
| } | ||
| }); | ||
|
|
||
| test('isPointOnLine returns true for point on line', () => { | ||
| const p1 = new Point({ x: 0, y: 0 }); | ||
| const p2 = new Point({ x: 2, y: 2 }); | ||
| const line = new Line({ point1: p1, point2: p2 }); | ||
| line.slope = (p2.y - p1.y) / (p2.x - p1.x); | ||
| line.n = p1.y - line.slope * p1.x; | ||
| const pointOnLine = new Point({ x: 1, y: 1 }); | ||
| expect(isPointOnLine(line, pointOnLine)).toBe(true); | ||
| }); | ||
|
|
||
| test('isPointOnLine returns false for point not on line', () => { | ||
| const p1 = new Point({ x: 0, y: 0 }); | ||
| const p2 = new Point({ x: 2, y: 2 }); | ||
| const line = new Line({ point1: p1, point2: p2 }); | ||
| line.slope = (p2.y - p1.y) / (p2.x - p1.x); | ||
| line.n = p1.y - line.slope * p1.x; | ||
| const pointNotOnLine = new Point({ x: 1, y: 2 }); | ||
| expect(isPointOnLine(line, pointNotOnLine)).toBe(false); | ||
| }); | ||
|
|
||
| test('calculateJunctionPoint throws error for undefined slope or n', () => { | ||
| const p1 = new Point({ x: 0, y: 0 }); | ||
| const p2 = new Point({ x: 2, y: 2 }); | ||
| const line1 = new Line({ point1: p1, point2: p2 }); | ||
| line1.slope = (p2.y - p1.y) / (p2.x - p1.x); | ||
| line1.n = p1.y - line1.slope * p1.x; | ||
| const line2 = new Line({ point1: p1, point2: p1 }); // קו עם אותו נקודה, שיפוע לא מוגדר | ||
| line2.slope = undefined; // או line2.n = undefined; | ||
|
|
||
| expect(() => calculateJunctionPoint(line1, line2)).toThrow(Error); | ||
| }); | ||
|
|
||
|
|
||
|
|
||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import Point from '../ecs6-class/point'; | ||
| import Line from '../ecs6-class/line'; | ||
|
|
||
| describe('Line Class', () => { | ||
| test('calculateSlope calculates correct slope', () => { | ||
| const p1 = new Point({ x: 0, y: 0 }); | ||
| const p2 = new Point({ x: 2, y: 4 }); | ||
| const line = new Line({ point1: p1, point2: p2 }); | ||
| line.calculateSlope(); | ||
| expect(line.slope).toBe((0 - 4) / (0 - 2)); // Should be 2 | ||
| }); | ||
|
|
||
| test('calculateNOfLineFunction calculates correct n', () => { | ||
| const p1 = new Point({ x: 1, y: 3 }); | ||
| const p2 = new Point({ x: 2, y: 5 }); | ||
| const line = new Line({ point1: p1, point2: p2 }); | ||
| const slope = (p2.y - p1.y) / (p2.x - p1.x); | ||
| line.slope = slope; | ||
| line.calculateNOfLineFunction(); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2 functions |
||
| expect(line.n).toBe(p1.y - line.slope! * p1.x); | ||
| }); | ||
|
|
||
| test('getPointByX returns correct point', () => { | ||
| const p1 = new Point({ x: 1, y: 3 }); | ||
| const p2 = new Point({ x: 2, y: 5 }); | ||
| const line = new Line({ point1: p1, point2: p2 }); | ||
| line.slope = (p2.y - p1.y) / (p2.x - p1.x); | ||
| line.n = p1.y - line.slope * p1.x; | ||
| const point = line.getPointByX(10); | ||
| expect(point?.x).toBe(10); | ||
| expect(point?.y).toBeCloseTo(line.slope! * 10 + line.n!); | ||
| }); | ||
|
|
||
| test('getPointByY returns correct point', () => { | ||
| const p1 = new Point({ x: 1, y: 3 }); | ||
| const p2 = new Point({ x: 2, y: 5 }); | ||
| const line = new Line({ point1: p1, point2: p2 }); | ||
| line.slope = (p2.y - p1.y) / (p2.x - p1.x); | ||
| line.n = p1.y - line.slope * p1.x; | ||
| const point = line.getPointByY(7); | ||
| expect(point?.y).toBe(7); | ||
| expect(point?.x).toBeCloseTo((7 - line.n!) / line.slope!); | ||
| }); | ||
|
|
||
| test('getPointOnXAsis returns point on X axis', () => { | ||
| const p1 = new Point({ x: 1, y: 3 }); | ||
| const p2 = new Point({ x: 2, y: 5 }); | ||
| const line = new Line({ point1: p1, point2: p2 }); | ||
| line.slope = (p2.y - p1.y) / (p2.x - p1.x); | ||
| line.n = p1.y - line.slope * p1.x; | ||
| const point = line.getPointOnXAsis(); | ||
| expect(point?.y).toBe(0); | ||
| }); | ||
|
|
||
| test('getPointOnYAsis returns point on Y axis', () => { | ||
| const p1 = new Point({ x: 1, y: 3 }); | ||
| const p2 = new Point({ x: 2, y: 5 }); | ||
| const line = new Line({ point1: p1, point2: p2 }); | ||
| line.slope = (p2.y - p1.y) / (p2.x - p1.x); | ||
| line.n = p1.y - line.slope * p1.x; | ||
| const point = line.getPointOnYAsis(); | ||
| expect(point?.x).toBe(0); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import Point from '../ecs6-class/point'; | ||
|
|
||
| describe('Point Class', () => { | ||
| test('Default values of x and y should be 0', () => { | ||
| const point = new Point(); | ||
| expect(point.x).toBe(0); | ||
| expect(point.y).toBe(0); | ||
| }); | ||
|
|
||
| test('Should initialize x and y with provided values', () => { | ||
| const point = new Point({ x: 5, y: 10 }); | ||
| expect(point.x).toBe(5); | ||
| expect(point.y).toBe(10); | ||
| }); | ||
|
|
||
| test('moveVertical should correctly update y value', () => { | ||
| const point = new Point({ x: 0, y: 0 }); | ||
| point.moveVertical(10); | ||
| expect(point.y).toBe(10); | ||
| point.moveVertical(-5); | ||
| expect(point.y).toBe(5); | ||
| }); | ||
|
|
||
| test('moveHorizontal should correctly update x value', () => { | ||
| const point = new Point({ x: 0, y: 0 }); | ||
| point.moveHorizontal(15); | ||
| expect(point.x).toBe(15); | ||
| point.moveHorizontal(-10); | ||
| expect(point.x).toBe(5); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't calculate here, call the functions inside the
calculateJunctionPointfunction