-
Notifications
You must be signed in to change notification settings - Fork 41
tests and mocks #16
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
base: main
Are you sure you want to change the base?
tests and mocks #16
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,23 @@ | ||
| class Point { | ||
| constructor({x=0, y=0}={}) { | ||
| this.x = x; | ||
| this.y = y; | ||
| constructor({ x = 0, y = 0 } = {}) { | ||
| if (typeof (x) !== "number" || typeof (y) !== "number") | ||
| throw Error("this value is not a number") | ||
|
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. who is not a number, the x or the y? |
||
| else { | ||
| this.x = x; | ||
| this.y = y; | ||
| } | ||
| } | ||
|
|
||
| moveVertical(value) { | ||
| if (typeof (value) !== "number") | ||
| throw Error("this value is not a number") | ||
| this.y += value; | ||
| } | ||
| moveHorizontal(value) { | ||
| if (typeof (value) !== "number") | ||
| throw Error("this value is not a number") | ||
| this.x += value; | ||
| } | ||
| } | ||
|
|
||
| module.exports = Point | ||
| module.exports = Point | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,38 +1,53 @@ | ||
| const Line = require('./ecs6-class/line') | ||
| const Line = require('./ecs6-class/line'); | ||
| const Point = require('./ecs6-class/point'); | ||
|
|
||
| const calculateDistance = (point1, point2) => { | ||
| let distanceX = (point2.x - point1.x) ** 2; | ||
| let distanceY = (point2.y - point2.y) ** 2; | ||
| const distance = Math.sqrt(distanceX + distanceY); | ||
| return distance; | ||
| if (point1 instanceof Point || point2 instanceof Point) { | ||
| let distanceX = (point2.x - point1.x) ** 2; | ||
| let distanceY = (point2.y - point1.y) ** 2; | ||
| const distance = Math.sqrt(distanceX + distanceY); | ||
| return distance; | ||
| } | ||
| else | ||
| throw Error("this point is not a Point") | ||
|
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. which parameter is not a point |
||
| } | ||
|
|
||
|
|
||
| const calculateJunctionPoint = (line1, line2) => { | ||
| if (line1.slope === line2.slope) { | ||
| if (line1.n === line2.n) { | ||
| return true | ||
| if (line1 instanceof Line && line2 instanceof Line) { | ||
| if (line1.slope === line2.slope) { | ||
|
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. Is the slope already calculated?
Author
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. I didn't realize the slope is already calculated
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. It doesn't have to be |
||
| if (line1.n === line2.n) { | ||
| return true | ||
| } | ||
| else { | ||
| return false | ||
| } | ||
| } | ||
| else { | ||
| return false | ||
| const x = (line1.n - line2.n) / (line2.slope - line1.slope) | ||
| const junctionPoint = line1.getPointByX(x); | ||
| return junctionPoint | ||
| } | ||
| } | ||
| else { | ||
| const x = (line1.n - line2.n) / (line2.slope - line1.slope) | ||
| const junctionPoint = line1.getPointByX(x); | ||
| return junctionPoint | ||
| } | ||
| else | ||
| throw Error("this line is not a Line") | ||
|
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. which line is not a line? |
||
| } | ||
|
|
||
|
|
||
| const isPointOnLine = (line, point) => { | ||
| const proxyLine = new Line(line.point1, point) | ||
| proxyLine.calculateSlope() | ||
| if (line.slope === proxyLine.slope) { | ||
| proxyLine.calculateNOfLineFunction() | ||
| if (line.n === proxyLine.n2) { | ||
| return true | ||
| if ((line instanceof Line) && (point instanceof Point)) { | ||
| const proxyLine = new Line({ point1: line.point1, point2: point }) | ||
| proxyLine.calculateSlope() | ||
| if (line.slope === proxyLine.slope) { | ||
|
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. the slope of the line is already calculated? |
||
| proxyLine.calculateNOfLineFunction() | ||
| if (line.n === proxyLine.n) { | ||
|
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. is the n of the line already calculated |
||
| return true | ||
| } | ||
| } | ||
| return false | ||
| } | ||
| return false | ||
| else | ||
| throw Error("this object is not an Line or Point") | ||
|
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. a clearer error message |
||
| } | ||
|
|
||
| module.exports = { | ||
|
|
||
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.
which parameter is not a number?