-
Notifications
You must be signed in to change notification settings - Fork 41
Build test #41
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?
Build test #41
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 |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| const Line = require('./../../../modules/ecs6-class/line'); | ||
| const Point = require('./../../../modules/ecs6-class/point'); | ||
|
|
||
| describe('Line constructor', () => { | ||
| it('should set the correct point1, point2, slope, and n values when objects with specific values are passed', () => { | ||
| const point1 = new Point({ x: 1, y: 1 }); | ||
| const point2 = new Point({ x: 3, y: 3 }); | ||
| const line = new Line({ point1, point2 }); | ||
| expect(line.point1).toBe(point1); | ||
| expect(line.point2).toBe(point2); | ||
| expect(line.slope).toBe(undefined); | ||
| expect(line.n).toBe(undefined); | ||
| }); | ||
| describe('Error', () => { | ||
| it("throw new Error when type of object not instanceof point", () => { | ||
| expect(() => new Line({ point1: "string" })).toThrow("the type must to be instanceof Point") | ||
| expect(() => new Line({ point1: true })).toThrow("the type must to be instanceof Point") | ||
| expect(() => new Line({ point1: [2, 3] })).toThrow("the type must to be instanceof Point") | ||
| expect(() => new Line({ point2: () => { } })).toThrow("the type must to be instanceof Point") | ||
| expect(() => new Line({ point1: { 2: 3 } })).toThrow("the type must to be instanceof Point") | ||
| }) | ||
| }) | ||
| }); | ||
|
|
||
| describe('Line calculateSlope method', () => { | ||
| it('should correctly calculate the slope between point1 and point2', () => { | ||
| const point1 = new Point({ x: 1, y: 1 }); | ||
| const point2 = new Point({ x: 3, y: 3 }); | ||
| const line = new Line({ point1, point2 }); | ||
| line.calculateSlope(); | ||
| expect(line.slope).toBe(1); | ||
| }); | ||
| describe('Error', () => { | ||
| it("throw new Error when ", () => { | ||
| const point1 = new Point({ x: 1, y: 1 }); | ||
| const point2 = new Point({ x: 1, y: 3 }); | ||
| const line = new Line({ point1, point2 }); | ||
| expect(() => line.calculateSlope()).toThrow("A number cannot be divided by 0") | ||
| }) | ||
| }) | ||
| }); | ||
|
|
||
| describe('Line calculateNOfLineFunction method', () => { | ||
| it('should correctly calculate the n value', () => { | ||
| const point1 = new Point({ x: 1, y: 1 }); | ||
| const point2 = new Point({ x: 3, y: 3 }); | ||
| const line = new Line({ point1, point2 }); | ||
| line.calculateSlope(); | ||
| line.calculateNOfLineFunction(); | ||
| expect(line.n).toBe(0); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Line getPointOnXAsis method', () => { | ||
| it('should retrieve the correct point on the X-axis', () => { | ||
| const point1 = new Point({ x: 1, y: 1 }); | ||
| const point2 = new Point({ x: 3, y: 3 }); | ||
| const line = new Line({ point1, point2 }); | ||
| line.calculateSlope(); | ||
| line.calculateNOfLineFunction(); | ||
| const pointOnXAxis = line.getPointOnXAsis(); | ||
| expect(pointOnXAxis.x).toBeCloseTo(0); | ||
| expect(pointOnXAxis.y).toBeCloseTo(0); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Line getPointOnYAsis method', () => { | ||
| it('should retrieve the correct point on the Y-axis', () => { | ||
| const point1 = new Point({ x: 1, y: 1 }); | ||
| const point2 = new Point({ x: 3, y: 3 }); | ||
| const line = new Line({ point1, point2 }); | ||
| line.calculateSlope(); | ||
| line.calculateNOfLineFunction(); | ||
| const pointOnYAxis = line.getPointOnYAsis(); | ||
|
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. You don't use different functions in the tests to assure that you test won't fail
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. this problem is still not fixed |
||
| expect(pointOnYAxis.x).toBeCloseTo(0); | ||
| expect(pointOnYAxis.y).toBeCloseTo(0); | ||
| }); | ||
|
|
||
|
|
||
| }); | ||
|
|
||
| describe('Line getPointByX method', () => { | ||
| it('should correctly calculate the point by providing an X coordinate', () => { | ||
| const point1 = new Point({ x: 1, y: 1 }); | ||
| const point2 = new Point({ x: 3, y: 3 }); | ||
| const line = new Line({ point1, point2 }); | ||
| line.calculateSlope(); | ||
| line.calculateNOfLineFunction(); | ||
| const targetX = 4; | ||
|
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. You don't use different functions in the tests to assure that you test won't fail |
||
| const pointByX = line.getPointByX(targetX); | ||
| expect(pointByX.y).toBeCloseTo(targetX); | ||
gemtechd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
| describe('ERROR', () => { | ||
| it("throw new error when did'nt send slope and n", () => { | ||
| const line = new Line(); | ||
| expect(() => line.getPointByX(3)).toThrow("must to send slope and n") | ||
| }) | ||
| it("throw new error when did'nt send slope", () => { | ||
| const line = new Line({ n: 2 }); | ||
| expect(() => line.getPointByX(3)).toThrow("must to send slope") | ||
| }) | ||
| it("throw new error when did'nt send n", () => { | ||
| const line = new Line({ slope: 2 }); | ||
| expect(() => line.getPointByX(3)).toThrow("must to send n") | ||
| }) | ||
| it("throw new error when type of x did'nt number", () => { | ||
| const line = new Line({ slope: 2 }); | ||
| expect(() => line.getPointByX(true)).toThrow("type must be number") | ||
| expect(() => line.getPointByX(() => { })).toThrow("type must be number") | ||
| expect(() => line.getPointByX({ x: 4 })).toThrow("type must be number") | ||
| expect(() => line.getPointByX("string")).toThrow("type must be number") | ||
| expect(() => line.getPointByX([3, 2])).toThrow("type must be number") | ||
| }) | ||
| }) | ||
| }); | ||
|
|
||
| describe('Line getPointByY method', () => { | ||
| it('should correctly calculate the point by providing an Y coordinate', () => { | ||
| const point1 = new Point({ x: 1, y: 1 }); | ||
| const point2 = new Point({ x: 3, y: 3 }); | ||
| const line = new Line({ point1, point2 }); | ||
| line.calculateSlope(); | ||
| line.calculateNOfLineFunction(); | ||
| const targetY = 4; | ||
| const pointByY = line.getPointByY(targetY); | ||
| expect(pointByY.x).toBeCloseTo(targetY); | ||
| }); | ||
| describe('ERROR', () => { | ||
| it("throw new error when did'nt send slope and n", () => { | ||
| const line = new Line(); | ||
| expect(() => line.getPointByY(3)).toThrow("must to send slope and n") | ||
| }) | ||
| it("throw new error when did'nt send slope", () => { | ||
| const line = new Line({ n: 2 }); | ||
| expect(() => line.getPointByY(3)).toThrow("must to send slope") | ||
| }) | ||
| it("throw new error when did'nt send n", () => { | ||
| const line = new Line({ slope: 2 }); | ||
| expect(() => line.getPointByY(3)).toThrow("must to send n") | ||
| }) | ||
| it("throw new error when type of y did'nt number", () => { | ||
| const line = new Line({ slope: 2 }); | ||
| expect(() => line.getPointByY(true)).toThrow("type must be number") | ||
| expect(() => line.getPointByY(() => { })).toThrow("type must be number") | ||
| expect(() => line.getPointByY({ x: 4 })).toThrow("type must be number") | ||
| expect(() => line.getPointByY("string")).toThrow("type must be number") | ||
| expect(() => line.getPointByY([3, 2])).toThrow("type must be number") | ||
| }) | ||
| }) | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| const Point = require('./../../../modules/ecs6-class/point'); | ||
| const point = new Point(); | ||
| describe('Point constructor', () => { | ||
| it('should set the correct x and y values when an object with specific values is passed', () => { | ||
| const point = new Point({ x: 10, y: 20 }); | ||
| expect(point.x).toBe(10); | ||
| expect(point.y).toBe(20); | ||
| }); | ||
|
|
||
| it('should set default values to x=0 and y=0 when no parameters are provided', () => { | ||
| expect(point.x).toBe(0); | ||
| expect(point.y).toBe(0); | ||
| }); | ||
| describe('ERRORS', () => { | ||
| it('should throw error when the x is invalid', () => { | ||
| expect(() => point = new Point({ x: "string", y: 0 })).toThrow('the x is invalid') | ||
| expect(() => point = new Point({ x: { "object": 9 }, y: 0 })).toThrow('the x is invalid') | ||
| expect(() => point = new Point({ x: true, y: 0 })).toThrow('the x is invalid') | ||
| expect(() => point = new Point({ x: ["array", 9], y: 0 })).toThrow('the x is invalid') | ||
| expect(() => point = new Point({ x: function () { }, y: 0 })).toThrow('the x is invalid') | ||
| }) | ||
| it('should throw error when the y is invalid', () => { | ||
| expect(() => point = new Point({ x: 1, y: "string" })).toThrow('the y is invalid') | ||
| expect(() => point = new Point({ x: 1, y: { "object": 9 } })).toThrow('the y is invalid') | ||
| expect(() => point = new Point({ x: 1, y: true })).toThrow('the y is invalid') | ||
| expect(() => point = new Point({ x: 1, y: ["array", 9] })).toThrow('the y is invalid') | ||
| expect(() => point = new Point({ x: 1, y: function () { } })).toThrow('the y is invalid') | ||
| }) | ||
| }) | ||
|
|
||
| }); | ||
| describe('Point moveVertical method', () => { | ||
| it('should correctly move the y coordinate by the given value', () => { | ||
| point.moveVertical(5); | ||
| expect(point.y).toBe(5); | ||
| }); | ||
| describe('ERRORS', () => { | ||
| it('should throw new error when the incoming value is not a number', () => { | ||
| expect(() => point.moveVertical("string")).toThrow("the value is not type of number") | ||
| expect(() => point.moveVertical({ "object": 5 })).toThrow("the value is not type of number") | ||
| expect(() => point.moveVertical(true)).toThrow("the value is not type of number") | ||
| expect(() => point.moveVertical(function () { })).toThrow("the value is not type of number") | ||
| expect(() => point.moveVertical([9, 9])).toThrow("the value is not type of number") | ||
| expect(() => point.moveVertical()).toThrow("the value is not type of number") | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
|
|
||
| describe('Point moveHorizontal method', () => { | ||
| it('should correctly move the x coordinate by the given value', () => { | ||
| point.moveHorizontal(3); | ||
| expect(point.x).toBe(3); | ||
| }); | ||
| describe('ERRORS', () => { | ||
| it('should throw new error when the incoming value is not a number', () => { | ||
| expect(() => point.moveHorizontal("string")).toThrow("the value is not type of number") | ||
| expect(() => point.moveHorizontal({ "object": 5 })).toThrow("the value is not type of number") | ||
| expect(() => point.moveHorizontal(true)).toThrow("the value is not type of number") | ||
| expect(() => point.moveHorizontal(function () { })).toThrow("the value is not type of number") | ||
| expect(() => point.moveHorizontal([4, 9])).toThrow("the value is not type of number") | ||
| expect(() => point.moveHorizontal([4, 9])).toThrow("the value is not type of number") | ||
| }) | ||
| }) | ||
| }); |
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.
You don't use different functions in the tests to assure that you test won't fail
You have to change the code itself
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.
this problem is still not fixed