-
Notifications
You must be signed in to change notification settings - Fork 41
create tests #18
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?
create tests #18
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}={}) { | ||
| if(typeof(x)!="number" || typeof(y)!="number"){ | ||
| throw new Error('argument must be type number') | ||
sh-silberberg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| this.x = x; | ||
| this.y = y; | ||
| } | ||
| moveVertical(value) { | ||
| if(typeof(value)!="number"){ | ||
| throw new Error('argument must be type number') | ||
| } | ||
| this.y += value; | ||
| } | ||
| moveHorizontal(value) { | ||
| if(typeof(value)!="number"){ | ||
| throw new Error('argument must be type number') | ||
| } | ||
| this.x += value; | ||
| } | ||
| } | ||
|
|
||
| module.exports = Point | ||
| module.exports = Point | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,24 @@ | ||
| const Line = require('./ecs6-class/line') | ||
| const Point = require('./ecs6-class/point') | ||
|
|
||
| const calculateDistance = (point1, point2) => { | ||
| if(!point1 || !point2){ | ||
| throw new Error('missing data') | ||
| } | ||
| if(typeof(point1)!= 'object' |typeof(point2)!='object'){ | ||
| throw new Error('argument must by type 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. write a test that gets an array |
||
| } | ||
|
|
||
| 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; | ||
| } | ||
|
|
||
| const calculateJunctionPoint = (line1, line2) => { | ||
| if(line1==undefined || line2==undefined){ | ||
| throw new Error("missing data") | ||
| } | ||
| 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. what happens if the slope of line1 or line2 are not defined? |
||
| if (line1.n === line2.n) { | ||
| return true | ||
|
|
@@ -24,6 +35,9 @@ const calculateJunctionPoint = (line1, line2) => { | |
| } | ||
|
|
||
| const isPointOnLine = (line, point) => { | ||
| if(line==undefined || point==undefined){ | ||
| throw new Error("missing data") | ||
| } | ||
| const proxyLine = new Line({ point1: line.point1, point2: point }) | ||
| proxyLine.calculateSlope() | ||
|
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. what happens when line.slope or line.n are undefined? |
||
| if (line.slope === proxyLine.slope) { | ||
|
|
@@ -40,3 +54,6 @@ module.exports = { | |
| calculateJunctionPoint, | ||
| isPointOnLine | ||
| } | ||
|
|
||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.