-
Notifications
You must be signed in to change notification settings - Fork 41
add mocks #15
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
ws783
wants to merge
5
commits into
gemtechd:main
Choose a base branch
from
ws783: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
add mocks #15
Changes from all commits
Commits
Show all changes
5 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,39 @@ | ||
| class Point { | ||
| constructor({x=0, y=0}={}) { | ||
|
|
||
| constructor({ x = 0, y = 0 } = {}) { | ||
|
|
||
| if (typeof (x) !== "number" && typeof (y) != "number") { | ||
| throw Error('x and y are not number') | ||
| } | ||
| if (typeof (x) != "number") { | ||
| throw Error('x is not number') | ||
| } | ||
| if (typeof (y) != "number") { | ||
| throw Error('y is not number') | ||
| } | ||
| this.x = x; | ||
| this.y = y; | ||
| } | ||
|
|
||
| moveVertical(value) { | ||
| if (!value) | ||
| throw Error("value is not define") | ||
| if(typeof(value)!=="number") | ||
| throw Error("value is not a number") | ||
| this.y += value; | ||
| } | ||
| moveHorizontal(value) { | ||
| if (!value) | ||
| throw Error("value is not define") | ||
| if(typeof(value)!=="number") | ||
| throw Error("value is not a number") | ||
| 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,173 @@ | ||
|
|
||
| const Line = require('../../../modules/ecs6-class/line'); | ||
| const Point = require('../../../modules/ecs6-class/point') | ||
| const mockConstructor = jest.fn(constructor); | ||
| let line | ||
| describe('CONSTRUCTORE', () => { }) | ||
|
|
||
|
|
||
| it('should initialize point2, n and slope to default values when no parameters are provided', () => { | ||
| line = new Line({ point1: mockConstructor(new Point({ x: 1, y: 5 })) }); | ||
| expect(line.point1).toStrictEqual(mockConstructor(new Point({ x: 1, y: 5 }))) | ||
| expect(line.point2).toStrictEqual(mockConstructor(new Point())) | ||
| expect(line.n).toBe(undefined) | ||
| expect(line.slope).toBe(undefined) | ||
| }) | ||
| it('should initialize point1, n and value to default values when no parameters are provided', () => { | ||
| line = new Line({ point2: mockConstructor(new Point({ x: 1, y: 5 })) }); | ||
| expect(line.point1).toStrictEqual(mockConstructor(new Point())) | ||
| expect(line.point2).toStrictEqual(mockConstructor(new Point({ x: 1, y: 5 }))) | ||
| expect(line.n).toBe(undefined) | ||
| expect(line.slope).toBe(undefined) | ||
| }) | ||
| it('should initialize point1, point2 and slope to default values when no parameters are provided', () => { | ||
| line = new Line({ n: 5 }); | ||
| expect(line.point1).toStrictEqual(mockConstructor(new Point())) | ||
| expect(line.point2).toStrictEqual(mockConstructor(new Point())) | ||
| expect(line.n).toBe(5) | ||
| expect(line.slope).toBe(undefined) | ||
| }) | ||
| it('should initialize point1, point2 and n to default values when no parameters are provided', () => { | ||
| line = new Line({ slope: 5 }); | ||
| expect(line.point1).toStrictEqual(mockConstructor(new Point())) | ||
| expect(line.point2).toStrictEqual(mockConstructor(new Point())) | ||
| expect(line.n).toBe(undefined) | ||
| expect(line.slope).toBe(5) | ||
| }) | ||
| it('should initialize to default values when no parameters are provided', () => { | ||
| line = new Line({}) | ||
| expect(line.point1).toStrictEqual(mockConstructor(new Point())) | ||
| expect(line.point2).toStrictEqual(mockConstructor(new Point())) | ||
| expect(line.n).toBe(undefined) | ||
| expect(line.slope).toBe(undefined) | ||
|
|
||
| }) | ||
| it('Checks if the parameters are of the correct type', () => { | ||
|
|
||
| expect(() => new Line({ point1: "ab", point2: new Point({ x: 5, y: 5 }), slope: 1, n: 5 })).toThrow('point1 is not point'); | ||
| expect(() => new Line({ point1: mockConstructor(new Point({ x: 5, y: 5 })), point2: "ab", slope: 1, n: 5 })).toThrow('point2 is not point'); | ||
| expect(() => new Line({ point1: new Point({ x: 5, y: 5 }), point2: mockConstructor(new Point({ x: 5, y: 5 })), slope: "d", n: 5 })).toThrow('slope is not number'); | ||
| expect(() => new Line({ point1: new Point({ x: 5, y: 5 }), point2: mockConstructor(new Point({ x: 5, y: 5 })), slope: 1, n: "d" })).toThrow('n is not number'); | ||
| }) | ||
| it('Point constructor initializes point1 and point2 and slope and n correctly', () => { | ||
| line = new Line({ point1: mockConstructor(new Point({ x: 5, y: 8 })), point2: mockConstructor(new Point({ x: 5, y: 8 })), slope: 5, n: 8 }); | ||
| expect(line.point1).toEqual(mockConstructor(new Point({ x: 5, y: 8 }))); | ||
| expect(line.point2).toEqual(mockConstructor(new Point({ x: 5, y: 8 }))); | ||
| expect(line.slope).toBe(5); | ||
| expect(line.n).toBe(8); | ||
|
|
||
| }); | ||
| describe('CALCULATE_SLOPE', () => { | ||
|
|
||
| it('should The slope is 0 as the line is vertical (point1= point2) ', () => { | ||
| line = mockConstructor(new Line(({ point1: mockConstructor(new Point({ x: 5, y: 8 })), point2: mockConstructor(new Point({ x: 5, y: 8 })), n: 8 }))) | ||
| expect(() => line.calculateSlope()).toThrow('Both points have the same values so it is not a line'); | ||
|
|
||
| }) | ||
|
|
||
| it('should The slope is undefined as the line is vertical (y1 = y2) ', () => { | ||
| line = mockConstructor(new Line(({ point1: mockConstructor(new Point({ x: 5, y: 8 })), point2: mockConstructor(new Point({ x: 3, y: 8 })), slope: 5, n: 8 }))) | ||
| line.calculateSlope() | ||
| expect(line.slope).toBeCloseTo(0); | ||
|
|
||
| }) | ||
| it('should The slope is undefined as the line is vertical (x1=x2)', () => { | ||
| line = mockConstructor(new Line({ point1: mockConstructor(new Point({ x: 5, y: 9 })), point2: mockConstructor(new Point({ x: 5, y: 8 })), n: 8 })); | ||
| expect(() => line.calculateSlope()).toThrow('The x of point1 is equal to the x of point2 so this line is not function'); | ||
| }); | ||
|
|
||
| it('should move vertically correctly', () => { | ||
| line = mockConstructor(new Line(({ point1: mockConstructor(new Point({ x: -1, y: 8 })), point2: mockConstructor(new Point({ x: 2, y: 5 })), slope: 5, n: 8 }))); | ||
| line.calculateSlope() | ||
| expect(line.slope).toBe(-1); | ||
|
|
||
| }) | ||
|
|
||
| }) | ||
| describe('CALCULATE_N_OF_LINE_FUNCTION', () => { | ||
| it(' should move vertically correctly', () => { | ||
| line = mockConstructor(new Line(({ point1: mockConstructor(new Point({ x: 5, y: 8 })), point2: mockConstructor(new Point({ x: 5, y: 5 })), slope: 1, n: 8 }))); | ||
| line.calculateNOfLineFunction() | ||
| expect(line.n).toBe(3); | ||
|
|
||
| }) | ||
|
|
||
| }) | ||
|
|
||
| describe('GET_POINT_BY_X', () => { | ||
| it('should x is not define ', () => { | ||
| const line = mockConstructor(new Line({})) | ||
| expect(() => line.getPointByX()).toThrow('x is not a defined'); | ||
| }) | ||
|
|
||
| it('should x is not number ', () => { | ||
| const line = mockConstructor(new Line({})) | ||
| expect(() => line.getPointByX("abc")).toThrow('x is not a number'); | ||
| }) | ||
|
|
||
| it(' should check that the returned value is of type point', () => { | ||
| const line = mockConstructor(new Line({})) | ||
| const point = line.getPointByX(5) | ||
| expect(point).toBeInstanceOf(Point) | ||
|
|
||
| }) | ||
| it('should checks that point is returned with correct values', () => { | ||
| const line = mockConstructor(new Line(({ point1: new Point({ x: 5, y: 8 }), point2: new Point({ x: 5, y: 5 }), slope: 1, n: 8 }))) | ||
| initialx = line.point1.x | ||
| const point = line.getPointByX(5) | ||
| expect(point.x).toBe(initialx) | ||
| expect(point.y).toBe(13) | ||
| }) | ||
| }) | ||
| describe('GET_POINT_B_Y', () => { | ||
| it('should y is not define ', () => { | ||
| const line = mockConstructor(new Line({})) | ||
| expect(() => line.getPointByY()).toThrow('y is not defined'); | ||
| }) | ||
| }) | ||
|
|
||
| it('should y is not number ', () => { | ||
| const line = mockConstructor(new Line({})) | ||
| expect(() => line.getPointByY("abc")).toThrow('y is not number'); | ||
| }) | ||
|
|
||
| it(' should check that the returned value is of type point', () => { | ||
| const line = mockConstructor(new Line({})) | ||
| const point = line.getPointByY(5) | ||
| expect(point).toBeInstanceOf(Point) | ||
|
|
||
| }) | ||
| it('should checks that point is returned with correct values', () => { | ||
| const line = mockConstructor(new Line(({ point1: mockConstructor(new Point({ x: 8, y: 6 })), point2: mockConstructor(new Point({ x: 5, y: 5 })), slope: 1, n: 3 }))) | ||
| initialy = line.point1.y | ||
| const point = line.getPointByY(6) | ||
| expect(point.x).toBe(3) | ||
| expect(point.y).toBe(initialy) | ||
| }) | ||
|
|
||
| describe('GET_POINT_ON_X_ASIS', () => { | ||
|
|
||
| it('returns the correct point on the y-axis for the given slope and n value', () => { | ||
|
|
||
| const line = mockConstructor(new Line(({ slope: 2, n: -6 }))) | ||
| const point = line.getPointOnXAsis() | ||
| expect(point.y).toBe(0) | ||
| expect(point.x).toBe(3) | ||
|
|
||
|
|
||
|
|
||
| }) | ||
| }) | ||
| describe('GET_POINT_ON_Y_ASIS', () => { | ||
| it('returns the correct point on the y-axis for the given slope and n value', () => { | ||
| const line = mockConstructor(new Line({ slope: 5, n: 5 })) | ||
| const point = line.getPointOnYAsis() | ||
| expect(point.y).toBe(5) | ||
| expect(point.x).toBe(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.
Get back to the previous import state