-
Notifications
You must be signed in to change notification settings - Fork 41
tests with mock #10
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
LeaG588
wants to merge
3
commits into
gemtechd:main
Choose a base branch
from
LeaG588: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 with mock #10
Changes from all commits
Commits
Show all changes
3 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
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,14 +1,20 @@ | ||
| class Point { | ||
| constructor({x=0, y=0}={}) { | ||
| constructor({ x = 0, y = 0 } = {}) { | ||
| if (!(typeof (x) === "number") || !(typeof (y) === "number")) | ||
| throw new Error('x and y must be of the number type') | ||
| this.x = x; | ||
| this.y = y; | ||
| } | ||
| moveVertical(value) { | ||
| if (!(typeof (value) === "number")) | ||
| throw new Error('value must be of the number type') | ||
| this.y += value; | ||
| } | ||
| moveHorizontal(value) { | ||
| if (!(typeof (value) === "number")) | ||
| throw new Error('value must be of the number type') | ||
| this.x += value; | ||
| } | ||
| } | ||
|
|
||
| module.exports = Point | ||
| module.exports = Point |
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,82 @@ | ||
| const Line = require('../../../modules/ecs6-class/line') | ||
| const Point = require('../../../modules/ecs6-class/point') | ||
|
|
||
| describe('LINE', () => { | ||
| describe('CONSTRUCTOR', () => { | ||
| it('should instantiate the class with the correct values', () => { | ||
| const l = new Line({ slope: 3, n: 7 }); | ||
| expect(l.slope).toBe(3); | ||
| expect(l.n).toBe(7); | ||
| }); | ||
| }), | ||
| describe('CALCULATE_N_Of_LINE_FUNCTION', () => { | ||
|
|
||
| it('calculateNOfLineFunction calculates the correct value of n', () => { | ||
| const line = new Line({ point1: { x: 0, y: 0 }, point2: { x: 2, y: 2 } }); | ||
| line.calculateSlope(); | ||
| line.calculateNOfLineFunction(); | ||
| expect(line.n).toBe(0); | ||
| }); | ||
| }), | ||
| describe('CALCULATE_SLOPE', () => { | ||
| it('should return error if the point1.x - point2.x =0', () => { | ||
| const point1 = new Point({ x: 5, y: 9 }) | ||
| const point2 = new Point({ x: 5, y: 2 }) | ||
| const line = new Line({ point1: point1, point2: point2 }) | ||
| expect(() => line.calculateSlope()).toThrowError("don't divide by 0") | ||
| }) | ||
| it('should return if the function calculate slope between two points', () => { | ||
| const point1 = new Point({ x: 1, y: 2 }); | ||
| const point2 = new Point({ x: 3, y: 4 }); | ||
| const line = new Line({ point1, point2 }); | ||
| line.calculateSlope(); | ||
| expect(line.slope).toBe(1); | ||
| }); | ||
| }), | ||
| describe('GET_POINT_ON_Y_AXIS', () => { | ||
| it('Get Point on Y axis', () => { | ||
| const line = new Line({ slope: 1, n: 0 }); | ||
| const point = line.getPointOnYAsis(); | ||
| expect(point.x).toBe(0); | ||
| expect(point.y).toBe(0); | ||
| }); | ||
| }), | ||
| describe('GET_POINT_BY_Y', () => { | ||
| it('Get Point by Y', () => { | ||
| const line = new Line({ slope: 2, n: 3 }); | ||
| const expectedPoint = new Point({ x: 1, y: 5 }); | ||
| const point = line.getPointByY(5); | ||
| expect(point.x).toBe(expectedPoint.x); | ||
| expect(point.y).toBe(expectedPoint.y); | ||
| }); | ||
| it('should return error.message if the slope = 0', () => { | ||
| const line = new Line({ n: 1, slope: 0 }) | ||
| expect(() => line.getPointByY(5)).toThrowError("don't divide by 0") | ||
| }); | ||
| }), | ||
| describe('GET_POINT_BY_X', () => { | ||
| it('get point by x', () => { | ||
| const line = new Line({ slope: 1, n: 1 }) | ||
| const point = line.getPointByX(2) | ||
| expect(point.x).toBe(2) | ||
| expect(point.y).toBe(3) | ||
| }); | ||
| }), | ||
|
|
||
| describe('GET_POINT_ON_X_AXIS', () => { | ||
| it('Get Point on X Axis', () => { | ||
| const line = new Line({ slope: 2, n: 3 }); | ||
| const expectedPoint = line.getPointByY(0); | ||
| const point = line.getPointOnXAsis(); | ||
| expect(point.x).toBe(expectedPoint.x); | ||
| expect(point.y).toBe(expectedPoint.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,56 @@ | ||
| const Point = require('../../../modules/ecs6-class/point') | ||
|
|
||
| describe('POINT', () => { | ||
| describe('CONSTRUCTOR', () => { | ||
| it('Check if a point is created with default values', () => { | ||
| const point = new Point(); | ||
| expect(point.x).toBe(0); | ||
| expect(point.y).toBe(0); | ||
| }); | ||
| it('should return x=5 and y=6', () => { | ||
| const point = new Point({ x: 5, y: 6 }) | ||
| expect(point.x).toBe(5) | ||
| expect(point.y).toBe(6) | ||
| }) | ||
| it('should return error.message if the values is not number type', () => { | ||
| const invalidX = 'hello'; | ||
| const invalidY = true; | ||
| expect(() => new Point({ x: invalidX, y: invalidY })).toThrowError('x and y must be of the number type'); | ||
| }) | ||
| it('should return error.message if the values is not number type', () => { | ||
| const invalidX = 'hello'; | ||
| const invalidY = 5; | ||
| expect(() => new Point({ x: invalidX, y: invalidY })).toThrowError('x and y must be of the number type'); | ||
| }) | ||
| it('should return error.message if the values is not number type', () => { | ||
| const invalidX = 5; | ||
| const invalidY = 'hello'; | ||
| expect(() => new Point({ x: invalidX, y: invalidY })).toThrowError('x and y must be of the number type'); | ||
| }) | ||
| }), | ||
| describe('MOVE_VETRCAL', () => { | ||
| it('should return error.meaasge if the value is not number type', () => { | ||
| const point = new Point({ x: 1, y: 2 }); | ||
| const value = "3"; | ||
| expect(() => point.moveVertical(value)).toThrowError('value must be of the number type'); | ||
| }) | ||
| it('Move Point Vertically', () => { | ||
| const point = new Point({ x: 1, y: 2 }); | ||
| point.moveVertical(3); | ||
| expect(point.y).toBe(5); | ||
| }); | ||
| }), | ||
| describe('HORIZONTA', () => { | ||
| it('should return error.meaasge if the value is not number', () => { | ||
| const point = new Point({ x: 1, y: 2 }); | ||
| const value = "3"; | ||
| expect(() => point.moveHorizontal(value)).toThrowError('value must be of the number type'); | ||
| }) | ||
| it('Move Point Horizontally', () => { | ||
| const point = new Point({ x: 2, y: 3 }); | ||
| point.moveHorizontal(-1); | ||
| expect(point.x).toBe(1); | ||
| }); | ||
|
|
||
| }) | ||
| }) |
|
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. Where are the mocks for the inner function? |
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,75 @@ | ||
| const Point = require('../../modules/ecs6-class/point') | ||
| const Line = require('../../modules/ecs6-class/line') | ||
| const { calculateDistance, isPointOnLine, calculateJunctionPoint } = require('../../modules/geometry-calculation') | ||
| describe('GEOMETRY_CALCULATION', () => { | ||
| describe('CALCULATE_DISTANCE', () => { | ||
| it('should return error.message', () => { | ||
| const point1 = new Point({ x: 2, y: 3 }); | ||
| const point2 = new Line({ x: 5, y: 7 }); | ||
| expect(() => calculateDistance(point1, point2)).toThrowError('Invalid input. Expected objects of type point.'); | ||
| }); | ||
| it('should calculate the correct distance between two points', () => { | ||
| const result = calculateDistance(point1 = new Point({ x: 6, y: 8 }), point2 = new Point({ x: 2, y: 5 })); | ||
| expect(result).toBe(5) | ||
| }); | ||
| }), | ||
| describe('IS_POINT_ON_LINE', () => { | ||
| it('should return error if the objects are not Line or Point types', function () { | ||
| const line = new Line({ point1: new Point({ x: 2, y: 3 }), point2: new Point({ x: 4, y: 6 }) }); | ||
| const point = new Line({ point1: new Point({ x: 0, y: 0 }) }); | ||
| expect(() => isPointOnLine(line, point)).toThrowError("The objects should be of the Line and Point types"); | ||
| }); | ||
| it('should return true if the point lies on the line', () => { | ||
| const line = new Line({ point1: { x: 2, y: 5 }, slope: 2, n: 1 }); | ||
| const point = new Point({ x: 3, y: 7 }); | ||
| const result = isPointOnLine(line, point); | ||
| expect(result).toBe(true); | ||
| }); | ||
| it('should return false if the point does not lie on the line', () => { | ||
| const line = new Line({ slope: 2, n: 1 }); | ||
| const point = new Point({ x: 1, y: 3 }); | ||
| const result = isPointOnLine(line, point); | ||
| expect(result).toBe(false); | ||
| }); | ||
| it('should return false if the point is parallels', () => { | ||
| const line = new Line({ point1: { x: 6, y: 13 }, slope: 2, n: 1 }); | ||
| const point = new Point({ x: 1, y: 5 }); | ||
| const result = isPointOnLine(line, point); | ||
| expect(result).toBe(false); | ||
| }) | ||
| it('should return false if the point does not lie on the line', () => { | ||
| const line = new Line({ slope: 4, n: -1 }); | ||
| const point = new Point({ x: 1, y: 4 }); | ||
| const result = isPointOnLine(line, point); | ||
| expect(result).toBe(false); | ||
| }); | ||
| }), | ||
| describe('CALCULATE_JUNCTION_POINT', () => { | ||
| it('should return error if it is not of the Line type', () => { | ||
| const line1 = new Line({ slope: 2, n: 4 }); | ||
| const line2 = new Point({ x: 3, y: 5 }); | ||
| expect(() => calculateJunctionPoint(line1, line2)).toThrowError('Must be of the Line type'); | ||
|
|
||
| }); | ||
| it('should return true if slopes and intercepts are equal', () => { | ||
| const line1 = new Line({ slope: 2, n: 1 }); | ||
| const line2 = new Line({ slope: 2, n: 1 }); | ||
| const result = calculateJunctionPoint(line1, line2); | ||
| expect(result).toBe(true); | ||
| }); | ||
| it('should return false if slopes are equal but intercepts are different', () => { | ||
| const line1 = new Line({ slope: 2, n: 1 }); | ||
| const line2 = new Line({ slope: 2, n: 5 }); | ||
| const result = calculateJunctionPoint(line1, line2); | ||
| expect(result).toBe(false); | ||
| }); | ||
| it('should calculate the junction point correctly for two lines with different slopes', () => { | ||
| const line1 = new Line({ slope: 2, n: 1, getPointByX: function (x) { return { x: x, y: 2 * x + 1 } } }); | ||
| const line2 = new Line({ slope: -1, n: 7, getPointByX: function (x) { return { x: x, y: -x + 7 } } }); | ||
| const result = calculateJunctionPoint(line1, line2); | ||
| expect(result).toEqual({ x: 2, y: 5 }); | ||
| }); | ||
| }); | ||
| }) | ||
|
|
||
|
|
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.
Uh oh!
There was an error while loading. Please reload this page.