-
Notifications
You must be signed in to change notification settings - Fork 9
Devmy #8
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
wainch
wants to merge
6
commits into
gemtechd:main
Choose a base branch
from
wainch:devmy
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
Devmy #8
Changes from all commits
Commits
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 |
|---|---|---|
| @@ -1,50 +1,56 @@ | ||
| import Point from "./point"; | ||
|
|
||
| export default class Line { | ||
| point1: Point | ||
| point2: Point | ||
| n: number | undefined | ||
| slope: number | undefined | ||
| point1: Point; | ||
| point2: Point; | ||
| n: number | undefined; | ||
| slope: number | undefined; | ||
|
|
||
| constructor({ point1 = new Point(), point2 = new Point(), n = undefined, slope = undefined }: { point1?: Point, point2?: Point, n?: number, slope?: number } = {}) { | ||
| this.point1 = point1; | ||
| this.point2 = point2; | ||
| this.slope = slope; | ||
| this.n = n; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| calculateSlope() { | ||
| this.slope = (this.point1.y - this.point2.y) / (this.point1.x - this.point2.x) | ||
| this.slope = (this.point1.y - this.point2.y) / (this.point1.x - this.point2.x); | ||
| } | ||
|
|
||
| calculateNOfLineFunction() { | ||
| if (this.slope) | ||
| this.n = this.point1.y - this.slope * this.point1.x | ||
| if (this.slope !== undefined) { | ||
| this.n = this.point1.y - this.slope * this.point1.x; | ||
| } | ||
| } | ||
| ensureSlopeAndN() { | ||
| if (this.slope === undefined) { | ||
| this.calculateSlope(); | ||
| } | ||
| if (this.n === undefined) { | ||
| this.calculateNOfLineFunction(); | ||
| } | ||
| } | ||
|
|
||
| getPointOnXAsis() { | ||
| return this.getPointByY(0) | ||
| this.ensureSlopeAndN(); | ||
| return this.getPointByY(0); | ||
| } | ||
|
|
||
| getPointOnYAsis() { | ||
| return this.getPointByX(0) | ||
| this.ensureSlopeAndN(); | ||
| return this.getPointByX(0); | ||
| } | ||
|
|
||
|
|
||
| getPointByX(x: number) { | ||
| if (this.slope && this.n) { | ||
| let y = this.slope * x + this.n | ||
| return new Point({ x, y }) | ||
| this.ensureSlopeAndN(); | ||
| if (this.slope !== undefined && this.n !== undefined) { | ||
| const 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 }) | ||
| this.ensureSlopeAndN(); | ||
| if (this.slope !== undefined && this.n !== undefined) { | ||
| const x = (y - this.n) / this.slope; | ||
| return new Point({ x, y }); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| } | ||
| } |
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,99 @@ | ||
| import Line from "../ecs6-class/line"; | ||
| import Point from "../ecs6-class/point"; | ||
|
|
||
| describe("Line Class", () => { | ||
| test("Constructor initializes correctly", () => { | ||
| const point1 = new Point({ x: 1, y: 2 }); | ||
| const point2 = new Point({ x: 3, y: 4 }); | ||
| const line = new Line({ point1, point2 }); | ||
| expect(line.point1).toEqual(point1); | ||
| expect(line.point2).toEqual(point2); | ||
| expect(line.slope).toBeUndefined(); | ||
| expect(line.n).toBeUndefined(); | ||
| }); | ||
|
|
||
| test("calculateSlope calculates slope correctly", () => { | ||
| const point1 = new Point({ x: 1, y: 2 }); | ||
| const point2 = new Point({ x: 3, y: 6 }); | ||
| const line = new Line({ point1, point2 }); | ||
| line.calculateSlope(); | ||
| expect(line.slope).toBe(2); | ||
| }); | ||
|
|
||
| test("calculateNOfLineFunction calculates n correctly", () => { | ||
| const point1 = new Point({ x: 1, y: 2 }); | ||
| const point2 = new Point({ x: 3, y: 6 }); | ||
| const line = new Line({ point1, point2 }); | ||
| line.calculateSlope(); | ||
| line.calculateNOfLineFunction(); | ||
| expect(line.n).toBe(0); | ||
| }); | ||
|
|
||
| test("ensureSlopeAndN ensures slope and n are calculated", () => { | ||
| const point1 = new Point({ x: 1, y: 2 }); | ||
| const point2 = new Point({ x: 3, y: 6 }); | ||
| const line = new Line({ point1, point2 }); | ||
|
|
||
| expect(line.slope).toBeUndefined(); | ||
| expect(line.n).toBeUndefined(); | ||
|
|
||
| line.ensureSlopeAndN(); | ||
|
|
||
| expect(line.slope).toBe(2); | ||
| expect(line.n).toBe(0); | ||
| }); | ||
|
|
||
| test("getPointOnXAsis returns correct point", () => { | ||
| const point1 = new Point({ x: 1, y: 2 }); | ||
| const point2 = new Point({ x: 3, y: 6 }); | ||
| const line = new Line({ point1, point2 }); | ||
| line.calculateSlope(); | ||
| line.calculateNOfLineFunction(); | ||
| const pointOnXAxis = line.getPointOnXAsis(); | ||
| expect(pointOnXAxis).toEqual(new Point({ x: 0, y: 0 })); | ||
| }); | ||
|
|
||
| test("getPointOnYAsis returns correct point", () => { | ||
| const point1 = new Point({ x: 1, y: 2 }); | ||
| const point2 = new Point({ x: 3, y: 6 }); | ||
| const line = new Line({ point1, point2 }); | ||
| line.calculateSlope(); | ||
| line.calculateNOfLineFunction(); | ||
| const pointOnYAxis = line.getPointOnYAsis(); | ||
| expect(pointOnYAxis).toEqual(new Point({ x: 0, y: 0 })); | ||
| }); | ||
|
|
||
| test("getPointByX calculates point correctly", () => { | ||
| const point1 = new Point({ x: 1, y: 2 }); | ||
| const point2 = new Point({ x: 3, y: 6 }); | ||
| const line = new Line({ point1, point2 }); | ||
| line.calculateSlope(); | ||
| line.calculateNOfLineFunction(); | ||
| const point = line.getPointByX(2); | ||
| expect(point).toEqual(new Point({ x: 2, y: 4 })); | ||
| }); | ||
|
|
||
| test("getPointByY calculates point correctly", () => { | ||
| const point1 = new Point({ x: 1, y: 2 }); | ||
| const point2 = new Point({ x: 3, y: 6 }); | ||
| const line = new Line({ point1, point2 }); | ||
| line.calculateSlope(); | ||
| line.calculateNOfLineFunction(); | ||
| const point = line.getPointByY(4); | ||
| expect(point).toEqual(new Point({ x: 2, y: 4 })); | ||
| }); | ||
|
|
||
| test("getPointByX handles undefined slope or n", () => { | ||
| const point1 = new Point({ x: 1, y: 2 }); | ||
| const point2 = new Point({ x: 3, y: 6 }); | ||
| const line = new Line({ point1, point2 }); | ||
|
|
||
| expect(line.slope).toBeUndefined(); | ||
| expect(line.n).toBeUndefined(); | ||
|
|
||
| line.getPointByX(2); | ||
|
|
||
| expect(line.slope).toBe(2); | ||
| expect(line.n).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,67 @@ | ||
| import Point from "../ecs6-class/point"; | ||
| import Line from "../ecs6-class/line"; | ||
| // filepath: d:\chany waingort\build-tests-ts\modules\ecs6-class\point.test.ts | ||
|
|
||
| describe("Point Class", () => { | ||
| test("Constructor initializes correctly", () => { | ||
| const point = new Point({ x: 5, y: 10 }); | ||
| expect(point.x).toBe(5); | ||
| expect(point.y).toBe(10); | ||
| }); | ||
|
|
||
| test("Constructor initializes with default values", () => { | ||
| const point = new Point(); | ||
| expect(point.x).toBe(0); | ||
| expect(point.y).toBe(0); | ||
| }); | ||
|
|
||
| test("moveVertical moves the point vertically", () => { | ||
| const point = new Point({ x: 5, y: 10 }); | ||
| point.moveVertical(3); | ||
| expect(point.y).toBe(13); // 10 + 3 | ||
| }); | ||
|
|
||
| test("moveHorizontal moves the point horizontally", () => { | ||
| const point = new Point({ x: 5, y: 10 }); | ||
| point.moveHorizontal(-2); | ||
| expect(point.x).toBe(3); // 5 - 2 | ||
| }); | ||
| }); | ||
|
|
||
| test("Constructor initializes with default values", () => { | ||
| const line = new Line(); | ||
| expect(line.point1).toEqual(new Point()); | ||
| expect(line.point2).toEqual(new Point()); | ||
| expect(line.slope).toBeUndefined(); | ||
| expect(line.n).toBeUndefined(); | ||
| }); | ||
|
|
||
| test("Constructor initializes with custom values", () => { | ||
| const point1 = new Point({ x: 1, y: 2 }); | ||
| const point2 = new Point({ x: 3, y: 4 }); | ||
| const line = new Line({ point1, point2, slope: 2, n: 0 }); | ||
| expect(line.point1).toEqual(point1); | ||
| expect(line.point2).toEqual(point2); | ||
| expect(line.slope).toBe(2); | ||
| expect(line.n).toBe(0); | ||
| }); | ||
|
|
||
| test("getPointOnXAsis returns correct point", () => { | ||
| const point1 = new Point({ x: 1, y: 2 }); | ||
| const point2 = new Point({ x: 3, y: 6 }); | ||
| const line = new Line({ point1, point2 }); | ||
| line.calculateSlope(); | ||
| line.calculateNOfLineFunction(); | ||
| const pointOnXAxis = line.getPointOnXAsis(); | ||
| expect(pointOnXAxis).toEqual(new Point({ x: 0, y: 0 })); | ||
| }); | ||
|
|
||
| test("getPointOnYAsis returns correct point", () => { | ||
| const point1 = new Point({ x: 1, y: 2 }); | ||
| const point2 = new Point({ x: 3, y: 6 }); | ||
| const line = new Line({ point1, point2 }); | ||
| line.calculateSlope(); | ||
| line.calculateNOfLineFunction(); | ||
| const pointOnYAxis = line.getPointOnYAsis(); | ||
| expect(pointOnYAxis).toEqual(new Point({ x: 0, y: 0 })); | ||
| }); |
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 call two functions in one test
each test executes only one function
if you expect that a certain function will also be executed, do it inside the function
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.
still more then one function is executed