From a4e2b7b50e3354d24fc1af7c95fc3a202d07b1c7 Mon Sep 17 00:00:00 2001 From: shoshym Date: Tue, 23 Jul 2024 14:21:03 +0300 Subject: [PATCH 1/3] test for geometry calculation --- modules/ecs6-class/line.js | 7 +- modules/ecs6-class/point.js | 11 +++- modules/geometry-calculation.js | 3 +- package.json | 3 +- tests/modules/ecs6-class/line.test.js | 65 ++++++++++++++++++ tests/modules/ecs6-class/point.test.js | 61 +++++++++++++++++ tests/modules/geometry-calculation.test.js | 77 ++++++++++++++++++++++ 7 files changed, 222 insertions(+), 5 deletions(-) create mode 100644 tests/modules/ecs6-class/line.test.js create mode 100644 tests/modules/ecs6-class/point.test.js create mode 100644 tests/modules/geometry-calculation.test.js diff --git a/modules/ecs6-class/line.js b/modules/ecs6-class/line.js index 826c675..27a9716 100644 --- a/modules/ecs6-class/line.js +++ b/modules/ecs6-class/line.js @@ -1,7 +1,7 @@ const Point = require("./point"); class Line { - constructor({ point1 = new Point(), point2 = new Point(), n = undefined, slope = undefined }) { + constructor({ point1 = new Point(), point2 = new Point(), n = undefined, slope = undefined }) { this.point1 = point1; this.point2 = point2; this.slope = slope; @@ -9,7 +9,10 @@ class Line { } calculateSlope = () => { - this.slope = (this.point1.y - this.point2.y) / (this.point1.x - this.point2.x) + if((this.point1.y - this.point2.y) !== 0) + this.slope = (this.point1.y - this.point2.y) / (this.point1.x - this.point2.x) + else + throw new Error('division by zero') } calculateNOfLineFunction = () => { diff --git a/modules/ecs6-class/point.js b/modules/ecs6-class/point.js index e81b4a4..0a7f8c1 100644 --- a/modules/ecs6-class/point.js +++ b/modules/ecs6-class/point.js @@ -1,13 +1,22 @@ class Point { constructor({x=0, y=0}={}) { + if(typeof(x) !== "number") + throw new Error('type of x is not number') + if(typeof(y) !== "number") + throw new Error('type of y is not number') this.x = x; this.y = y; } moveVertical(value) { - this.y += value; + if(typeof(value) !== "number") + throw new Error('type of number is not number') + this.y += value; } moveHorizontal(value) { + if(typeof(value) !== "number") + throw new Error('type of number is not number') this.x += value; + } } diff --git a/modules/geometry-calculation.js b/modules/geometry-calculation.js index 6e11643..039c93a 100644 --- a/modules/geometry-calculation.js +++ b/modules/geometry-calculation.js @@ -1,8 +1,9 @@ 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; + let distanceY = (point2.y - point1.y) ** 2; const distance = Math.sqrt(distanceX + distanceY); return distance; } diff --git a/package.json b/package.json index 56bf17b..7b41f03 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "practice unit tests in javascript", "main": "index.js", "scripts": { - "test": "jest" + "test": "jest", + "test:coverage":"npm run test -- --coverage" }, "dependencies": { "jest": "^29.7.0" diff --git a/tests/modules/ecs6-class/line.test.js b/tests/modules/ecs6-class/line.test.js new file mode 100644 index 0000000..afc92e7 --- /dev/null +++ b/tests/modules/ecs6-class/line.test.js @@ -0,0 +1,65 @@ +const Line = require('../../../modules/ecs6-class/line') +const Point = require('../../../modules/ecs6-class/point') + +describe('CONSTRUCTOR',() => { + it('should build an object with default values',() => { + const line = new Line({slope:5,n:4}) + expect(line.slope).toBe(5) + expect(line.n).toBe(4) + expect(line.point1.x).toBe(0) + }) +}) + + +describe('CALCULATE_SLOPE',()=>{ + it('should return the correct answer',() => { + const line = new Line({point1:new Point({x:6,y:4}),point2:new Point({x:2,y:2})}) + line.calculateSlope() + expect(line.slope).toBe(0.5) + }) + it('An error should be thrown when the counter equals 0', () => { + const line = new Line({point1:new Point({x:6,y:4}),point2:new Point({x:2,y:4})}) + expect(()=>line.calculateSlope()).toThrowError('division by zero') + }) +}) + +describe('CALCULATE_N_OF_LINE_FUNCTION',() => { + it('should return the correct answer',() => { + const line = new Line({point1:new Point({x:6,y:4}),point2:new Point({x:2,y:2})}) + line.calculateSlope() + line.calculateNOfLineFunction() + expect(line.n).toBe(1) + }) +}) + +describe('GET_POINT_ON_X_ASIS', () =>{ + it('should return the correct answer',() => { + const line = new Line({point1:new Point({x:6,y:4}),point2:new Point({x:2,y:2}),slope:2,n:-8}) + const result = line.getPointOnXAsis() + expect(result).toEqual({x:4,y:0}) + }) +}) + +describe('GET_POINT_ON_Y_ASIS', () =>{ + it('should return the correct answer',() => { + const line = new Line({point1:new Point({x:6,y:4}),point2:new Point({x:2,y:2}),slope:2,n:-8}) + const result = line.getPointOnYAsis() + expect(result).toEqual({x:0,y:-8}) + }) +}) + +describe('GET_POINT_BY_X', () =>{ + it('should return the correct answer',() => { + const line = new Line({point1:new Point({x:6,y:4}),point2:new Point({x:2,y:2}),slope:2,n:-8}) + const result = line.getPointByX(2) + expect(result).toEqual({x:2,y:-4}) + }) +}) + +describe('GET_POINT_BY_Y', () =>{ + it('should return the correct answer',() => { + const line = new Line({point1:new Point({x:6,y:4}),point2:new Point({x:2,y:2}),slope:2,n:-8}) + const result = line.getPointByY(2) + expect(result).toEqual({x:5,y:2}) + }) +}) \ No newline at end of file diff --git a/tests/modules/ecs6-class/point.test.js b/tests/modules/ecs6-class/point.test.js new file mode 100644 index 0000000..c465c7a --- /dev/null +++ b/tests/modules/ecs6-class/point.test.js @@ -0,0 +1,61 @@ +const Point = require('../../../modules/ecs6-class/point') + +describe('CONSTRUCTOR',() => { + it('should build an object with default values',()=>{ + const point = new Point() + expect(point).toEqual({x:0,y:0}) + }) + it('should build an object',()=>{ + const point = new Point({x:8,y:9}) + expect(point).toEqual({x:8,y:9}) + }) + it('should build an object',()=>{ + const point = new Point({x:-8,y:-9}) + expect(point).toEqual({x:-8,y:-9}) + }) + it('should build an object',()=>{ + const point = new Point({x:5.5}) + expect(point).toEqual({x:5.5,y:0}) + }) + it('An error should be thrown when the type of x is not number' , () => { + expect(()=> new Point({x:'l',y:9}).toThrowError('type of x is not number')) + }) + it('An error should be thrown when the type of x is not number' , () => { + expect(()=> new Point({x:[],y:9}).toThrowError('type of x is not number')) + }) + it('An error should be thrown when the type of x is not number' , () => { + expect(()=> new Point({x:4,y:[]}).toThrowError('type of x is not number')) + }) + + it('An error should be thrown when the type of y is not number' , () => { + expect(()=> new Point({x:'a',y:'a'}).toThrowError('type of y is not number')) + }) + it('An error should be thrown when the type of y is not number' , () => { + expect(()=> new Point({x:5,y:'a'}).toThrowError('type of y is not number')) + }) +}) + +describe('MOVE_VERTICAL', ()=> { + it('should return the correct answer',()=> { + const point = new Point({x:5,y:6}) + point.moveVertical(5) + expect(point.y).toBe(11) + }) + it('An error should be thrown when the type of value is not number',()=> { + const point = new Point({x:5,y:6}) + expect(()=>point.moveVertical('a').toThrowError('type of number is not number')) +}) +}) + +describe('MOVE_HORIZONTAL', ()=> { + it('should return the correct answer',()=> { + const point = new Point({x:5,y:6}) + point.moveHorizontal(5) + expect(point.x).toBe(10) + }) + + it('An error should be thrown when the type of value is not number',()=> { + const point = new Point({x:5,y:6}) + expect(()=>point.moveHorizontal('a').toThrowError('type of number is not number')) + }) + }) \ No newline at end of file diff --git a/tests/modules/geometry-calculation.test.js b/tests/modules/geometry-calculation.test.js new file mode 100644 index 0000000..66669c3 --- /dev/null +++ b/tests/modules/geometry-calculation.test.js @@ -0,0 +1,77 @@ + +const Line = require('../../modules/ecs6-class/line') +const Point = require('../../modules/ecs6-class/point') +const { calculateDistance,calculateJunctionPoint,isPointOnLine} = require('../../modules/geometry-calculation') + + + +describe('CALCULATE_DISTANCE',() => { + it('should return the correct answer', () => { + const line = new Line({point1:new Point({x:6,y:4}),point2:new Point({x:2,y:1})}) + const result = calculateDistance(line.point1,line.point2) + expect(result).toBe(5) + }) +}) +describe('CALCULATE_JUNCTION_POINT', () => { + it('should return true when the 2 lines are equal', () =>{ + const line1 = new Line({point1:new Point({x:6,y:4}),point2:new Point({x:2,y:1})}) + const line2 = new Line({point1:new Point({x:6,y:4}),point2:new Point({x:2,y:1})}) + line1.calculateSlope() + line2.calculateSlope() + line1.calculateNOfLineFunction() + line2.calculateNOfLineFunction() + const result = calculateJunctionPoint(line1,line2) + expect(result).toBeTruthy() + }) + + it('should return false when the 2 lines are parallels', () =>{ + const line1 = new Line({point1:new Point({x:6,y:4}),point2:new Point({x:2,y:1})}) + const line2 = new Line({point1:new Point({x:5,y:3}),point2:new Point({x:1,y:0})}) + line1.calculateSlope() + line2.calculateSlope() + line1.calculateNOfLineFunction() + line2.calculateNOfLineFunction() + const result = calculateJunctionPoint(line1,line2) + expect(result).toBeFalsy() + }) + + it('should return point when the 2 lines are not equal', () =>{ + const line1 = new Line({point1:new Point({x:8,y:3}),point2:new Point({x:6,y:1})}) + const line2 = new Line({point1:new Point({x:5,y:3}),point2:new Point({x:1,y:0})}) + line1.calculateSlope() + line2.calculateSlope() + line1.calculateNOfLineFunction() + line2.calculateNOfLineFunction() + const result = calculateJunctionPoint(line1,line2) + expect(result).toEqual({ x: 17, y: 12 }) + }) +}) + +describe('IS_POINT_ON_LINE',() => { + it('should return true when the point on this line',() => { + const line = new Line({point1:new Point({x:8,y:4}),point2:new Point({x:2,y:1})}) + line.calculateSlope() + line.calculateNOfLineFunction() + console.log({line}); + const point = new Point({x:6,y:3}) + const result = isPointOnLine(line,point) + expect(result).toBeTruthy() + }) + it('should return true when the point on this line',() => { + const line = new Line({point1:new Point({x:10,y:10}),point2:new Point({x:8,y:2})}) + line.calculateSlope() + line.calculateNOfLineFunction() + console.log({line}); + const point = new Point({x:6,y:-6}) + const result = isPointOnLine(line,point) + expect(result).toBeTruthy() + }) + it('should return false when the point is not on this line',() => { + const line = new Line({point1:new Point({x:8,y:3}),point2:new Point({x:6,y:1})}) + line.calculateSlope() + line.calculateNOfLineFunction() + const point = new Point({x:5,y:6}) + const result = isPointOnLine(line,point) + expect(result).toBeFalsy() + }) +}) \ No newline at end of file From dcf7a1a926bec8f11eec903ed470bae3441f9683 Mon Sep 17 00:00:00 2001 From: shoshym Date: Wed, 24 Jul 2024 10:54:29 +0300 Subject: [PATCH 2/3] finish build test fork --- .../c01c1e36-b435-4824-aee0-a5928b1cc43e.json | 1 + .../c01c1e36-b435-4824-aee0-a5928b1cc43e.json | 1 + .nyc_output/processinfo/index.json | 1 + modules/ecs6-class/line.js | 23 +- modules/ecs6-class/point.js | 6 +- modules/geometry-calculation.js | 12 + package-lock.json | 545 ++++++++++++++++++ package.json | 8 +- tests/modules/ecs6-class/line.test.js | 10 + tests/modules/ecs6-class/point.test.js | 21 +- tests/modules/geometry-calculation.test.js | 68 ++- 11 files changed, 646 insertions(+), 50 deletions(-) create mode 100644 .nyc_output/c01c1e36-b435-4824-aee0-a5928b1cc43e.json create mode 100644 .nyc_output/processinfo/c01c1e36-b435-4824-aee0-a5928b1cc43e.json create mode 100644 .nyc_output/processinfo/index.json diff --git a/.nyc_output/c01c1e36-b435-4824-aee0-a5928b1cc43e.json b/.nyc_output/c01c1e36-b435-4824-aee0-a5928b1cc43e.json new file mode 100644 index 0000000..f08ad37 --- /dev/null +++ b/.nyc_output/c01c1e36-b435-4824-aee0-a5928b1cc43e.json @@ -0,0 +1 @@ +{"C:\\task2-test\\build-tests-fork\\modules\\ecs6-class\\line.js":{"path":"C:\\task2-test\\build-tests-fork\\modules\\ecs6-class\\line.js","statementMap":{"0":{"start":{"line":1,"column":14},"end":{"line":1,"column":32}},"1":{"start":{"line":5,"column":7},"end":{"line":15,"column":58}},"2":{"start":{"line":6,"column":10},"end":{"line":13,"column":58}},"3":{"start":{"line":7,"column":12},"end":{"line":7,"column":33}},"4":{"start":{"line":8,"column":12},"end":{"line":8,"column":33}},"5":{"start":{"line":9,"column":12},"end":{"line":9,"column":31}},"6":{"start":{"line":10,"column":12},"end":{"line":10,"column":23}},"7":{"start":{"line":13,"column":8},"end":{"line":13,"column":58}},"8":{"start":{"line":15,"column":8},"end":{"line":15,"column":58}},"9":{"start":{"line":18,"column":21},"end":{"line":23,"column":5}},"10":{"start":{"line":19,"column":8},"end":{"line":22,"column":45}},"11":{"start":{"line":20,"column":10},"end":{"line":20,"column":88}},"12":{"start":{"line":22,"column":10},"end":{"line":22,"column":45}},"13":{"start":{"line":25,"column":31},"end":{"line":27,"column":5}},"14":{"start":{"line":26,"column":8},"end":{"line":26,"column":59}},"15":{"start":{"line":30,"column":8},"end":{"line":30,"column":34}},"16":{"start":{"line":34,"column":8},"end":{"line":34,"column":34}},"17":{"start":{"line":39,"column":16},"end":{"line":39,"column":39}},"18":{"start":{"line":40,"column":8},"end":{"line":40,"column":34}},"19":{"start":{"line":44,"column":16},"end":{"line":44,"column":41}},"20":{"start":{"line":45,"column":8},"end":{"line":45,"column":34}},"21":{"start":{"line":49,"column":0},"end":{"line":49,"column":21}}},"fnMap":{"0":{"name":"(anonymous_0)","decl":{"start":{"line":4,"column":4},"end":{"line":4,"column":5}},"loc":{"start":{"line":4,"column":98},"end":{"line":16,"column":5}},"line":4},"1":{"name":"(anonymous_1)","decl":{"start":{"line":18,"column":21},"end":{"line":18,"column":22}},"loc":{"start":{"line":18,"column":27},"end":{"line":23,"column":5}},"line":18},"2":{"name":"(anonymous_2)","decl":{"start":{"line":25,"column":31},"end":{"line":25,"column":32}},"loc":{"start":{"line":25,"column":37},"end":{"line":27,"column":5}},"line":25},"3":{"name":"(anonymous_3)","decl":{"start":{"line":29,"column":4},"end":{"line":29,"column":5}},"loc":{"start":{"line":29,"column":22},"end":{"line":31,"column":5}},"line":29},"4":{"name":"(anonymous_4)","decl":{"start":{"line":33,"column":4},"end":{"line":33,"column":5}},"loc":{"start":{"line":33,"column":22},"end":{"line":35,"column":5}},"line":33},"5":{"name":"(anonymous_5)","decl":{"start":{"line":38,"column":4},"end":{"line":38,"column":5}},"loc":{"start":{"line":38,"column":19},"end":{"line":41,"column":5}},"line":38},"6":{"name":"(anonymous_6)","decl":{"start":{"line":43,"column":4},"end":{"line":43,"column":5}},"loc":{"start":{"line":43,"column":19},"end":{"line":46,"column":5}},"line":43}},"branchMap":{"0":{"loc":{"start":{"line":4,"column":18},"end":{"line":4,"column":38}},"type":"default-arg","locations":[{"start":{"line":4,"column":27},"end":{"line":4,"column":38}}],"line":4},"1":{"loc":{"start":{"line":4,"column":40},"end":{"line":4,"column":60}},"type":"default-arg","locations":[{"start":{"line":4,"column":49},"end":{"line":4,"column":60}}],"line":4},"2":{"loc":{"start":{"line":4,"column":62},"end":{"line":4,"column":75}},"type":"default-arg","locations":[{"start":{"line":4,"column":66},"end":{"line":4,"column":75}}],"line":4},"3":{"loc":{"start":{"line":4,"column":77},"end":{"line":4,"column":94}},"type":"default-arg","locations":[{"start":{"line":4,"column":85},"end":{"line":4,"column":94}}],"line":4},"4":{"loc":{"start":{"line":5,"column":7},"end":{"line":15,"column":58}},"type":"if","locations":[{"start":{"line":5,"column":7},"end":{"line":15,"column":58}},{"start":{"line":15,"column":8},"end":{"line":15,"column":58}}],"line":5},"5":{"loc":{"start":{"line":6,"column":10},"end":{"line":13,"column":58}},"type":"if","locations":[{"start":{"line":6,"column":10},"end":{"line":13,"column":58}},{"start":{"line":13,"column":8},"end":{"line":13,"column":58}}],"line":6},"6":{"loc":{"start":{"line":19,"column":8},"end":{"line":22,"column":45}},"type":"if","locations":[{"start":{"line":19,"column":8},"end":{"line":22,"column":45}},{"start":{"line":22,"column":10},"end":{"line":22,"column":45}}],"line":19}},"s":{"0":1,"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":1},"f":{"0":0,"1":0,"2":0,"3":0,"4":0,"5":0,"6":0},"b":{"0":[0],"1":[0],"2":[0],"3":[0],"4":[0,0],"5":[0,0],"6":[0,0]},"_coverageSchema":"1a1c01bbd47fc00a2c39e90264f33305004495a9","hash":"b5a728190e78626a4c269463d2ae8a826a4cdc78","contentHash":"ca9346dbfcf8b7ccffa3ad6e5100f7af0d3e93021b43ca2c7dd270176fb686b8"},"C:\\task2-test\\build-tests-fork\\modules\\ecs6-class\\point.js":{"path":"C:\\task2-test\\build-tests-fork\\modules\\ecs6-class\\point.js","statementMap":{"0":{"start":{"line":3,"column":8},"end":{"line":4,"column":54}},"1":{"start":{"line":4,"column":12},"end":{"line":4,"column":54}},"2":{"start":{"line":5,"column":8},"end":{"line":6,"column":54}},"3":{"start":{"line":6,"column":12},"end":{"line":6,"column":54}},"4":{"start":{"line":7,"column":8},"end":{"line":7,"column":19}},"5":{"start":{"line":8,"column":8},"end":{"line":8,"column":19}},"6":{"start":{"line":11,"column":8},"end":{"line":12,"column":69}},"7":{"start":{"line":12,"column":12},"end":{"line":12,"column":69}},"8":{"start":{"line":13,"column":11},"end":{"line":13,"column":27}},"9":{"start":{"line":16,"column":8},"end":{"line":17,"column":69}},"10":{"start":{"line":17,"column":12},"end":{"line":17,"column":69}},"11":{"start":{"line":18,"column":8},"end":{"line":18,"column":24}},"12":{"start":{"line":23,"column":0},"end":{"line":23,"column":22}}},"fnMap":{"0":{"name":"(anonymous_0)","decl":{"start":{"line":2,"column":4},"end":{"line":2,"column":5}},"loc":{"start":{"line":2,"column":31},"end":{"line":9,"column":5}},"line":2},"1":{"name":"(anonymous_1)","decl":{"start":{"line":10,"column":4},"end":{"line":10,"column":5}},"loc":{"start":{"line":10,"column":24},"end":{"line":14,"column":5}},"line":10},"2":{"name":"(anonymous_2)","decl":{"start":{"line":15,"column":4},"end":{"line":15,"column":5}},"loc":{"start":{"line":15,"column":26},"end":{"line":20,"column":5}},"line":15}},"branchMap":{"0":{"loc":{"start":{"line":2,"column":16},"end":{"line":2,"column":29}},"type":"default-arg","locations":[{"start":{"line":2,"column":27},"end":{"line":2,"column":29}}],"line":2},"1":{"loc":{"start":{"line":2,"column":17},"end":{"line":2,"column":20}},"type":"default-arg","locations":[{"start":{"line":2,"column":19},"end":{"line":2,"column":20}}],"line":2},"2":{"loc":{"start":{"line":2,"column":22},"end":{"line":2,"column":25}},"type":"default-arg","locations":[{"start":{"line":2,"column":24},"end":{"line":2,"column":25}}],"line":2},"3":{"loc":{"start":{"line":3,"column":8},"end":{"line":4,"column":54}},"type":"if","locations":[{"start":{"line":3,"column":8},"end":{"line":4,"column":54}},{"start":{},"end":{}}],"line":3},"4":{"loc":{"start":{"line":5,"column":8},"end":{"line":6,"column":54}},"type":"if","locations":[{"start":{"line":5,"column":8},"end":{"line":6,"column":54}},{"start":{},"end":{}}],"line":5},"5":{"loc":{"start":{"line":11,"column":8},"end":{"line":12,"column":69}},"type":"if","locations":[{"start":{"line":11,"column":8},"end":{"line":12,"column":69}},{"start":{},"end":{}}],"line":11},"6":{"loc":{"start":{"line":16,"column":8},"end":{"line":17,"column":69}},"type":"if","locations":[{"start":{"line":16,"column":8},"end":{"line":17,"column":69}},{"start":{},"end":{}}],"line":16}},"s":{"0":0,"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":1},"f":{"0":0,"1":0,"2":0},"b":{"0":[0],"1":[0],"2":[0],"3":[0,0],"4":[0,0],"5":[0,0],"6":[0,0]},"_coverageSchema":"1a1c01bbd47fc00a2c39e90264f33305004495a9","hash":"955ad9827827a9c506bf5fdd096831c58cb64bc6","contentHash":"357d106cec673c00fb289c32dbf25c2f00f77d3a7d83e2e3882eafe8740edd68"}} \ No newline at end of file diff --git a/.nyc_output/processinfo/c01c1e36-b435-4824-aee0-a5928b1cc43e.json b/.nyc_output/processinfo/c01c1e36-b435-4824-aee0-a5928b1cc43e.json new file mode 100644 index 0000000..f65fe27 --- /dev/null +++ b/.nyc_output/processinfo/c01c1e36-b435-4824-aee0-a5928b1cc43e.json @@ -0,0 +1 @@ +{"parent":null,"pid":5056,"argv":["C:\\Program Files\\nodejs\\node.exe","C:\\task2-test\\build-tests-fork\\tests\\modules\\ecs6-class\\line.test.js"],"execArgv":[],"cwd":"C:\\task2-test\\build-tests-fork\\tests\\modules\\ecs6-class","time":1721803202735,"ppid":10832,"coverageFilename":"C:\\task2-test\\build-tests-fork\\.nyc_output\\c01c1e36-b435-4824-aee0-a5928b1cc43e.json","externalId":"","uuid":"c01c1e36-b435-4824-aee0-a5928b1cc43e","files":["C:\\task2-test\\build-tests-fork\\modules\\ecs6-class\\line.js","C:\\task2-test\\build-tests-fork\\modules\\ecs6-class\\point.js"]} \ No newline at end of file diff --git a/.nyc_output/processinfo/index.json b/.nyc_output/processinfo/index.json new file mode 100644 index 0000000..ed5b2b2 --- /dev/null +++ b/.nyc_output/processinfo/index.json @@ -0,0 +1 @@ +{"processes":{"c01c1e36-b435-4824-aee0-a5928b1cc43e":{"parent":null,"children":[]}},"files":{"C:\\task2-test\\build-tests-fork\\modules\\ecs6-class\\line.js":["c01c1e36-b435-4824-aee0-a5928b1cc43e"],"C:\\task2-test\\build-tests-fork\\modules\\ecs6-class\\point.js":["c01c1e36-b435-4824-aee0-a5928b1cc43e"]},"externalIds":{}} \ No newline at end of file diff --git a/modules/ecs6-class/line.js b/modules/ecs6-class/line.js index 27a9716..7f55083 100644 --- a/modules/ecs6-class/line.js +++ b/modules/ecs6-class/line.js @@ -2,10 +2,17 @@ const Point = require("./point"); class Line { constructor({ point1 = new Point(), point2 = new Point(), n = undefined, slope = undefined }) { - this.point1 = point1; - this.point2 = point2; - this.slope = slope; - this.n = n; + if((point1 instanceof Point) ) + if((point2 instanceof Point)){ + this.point1 = point1; + this.point2 = point2; + this.slope = slope; + this.n = n; + } + else{ + throw new Error('the type of point2 is not Point')} + else + throw new Error('the type of point1 is not Point') } calculateSlope = () => { @@ -34,8 +41,12 @@ class Line { } getPointByY(y) { - let x = (y - this.n) / this.slope; - return new Point({ x, y }) + if(this.slope !== 0){ + let x = (y - this.n) / this.slope; + return new Point({ x, y }) + } + else + throw new Error('division by zero') } } diff --git a/modules/ecs6-class/point.js b/modules/ecs6-class/point.js index 0a7f8c1..91541e8 100644 --- a/modules/ecs6-class/point.js +++ b/modules/ecs6-class/point.js @@ -1,6 +1,6 @@ class Point { constructor({x=0, y=0}={}) { - if(typeof(x) !== "number") + if(typeof x !== "number") throw new Error('type of x is not number') if(typeof(y) !== "number") throw new Error('type of y is not number') @@ -9,12 +9,12 @@ class Point { } moveVertical(value) { if(typeof(value) !== "number") - throw new Error('type of number is not number') + throw new Error('the type of the value is not correctly') this.y += value; } moveHorizontal(value) { if(typeof(value) !== "number") - throw new Error('type of number is not number') + throw new Error('the type of the value is not correctly') this.x += value; } diff --git a/modules/geometry-calculation.js b/modules/geometry-calculation.js index 039c93a..2975a52 100644 --- a/modules/geometry-calculation.js +++ b/modules/geometry-calculation.js @@ -2,6 +2,10 @@ const Line = require('./ecs6-class/line') const Point = require('./ecs6-class/point') const calculateDistance = (point1, point2) => { + if(!(point1 instanceof Point)) + throw new Error('the type of point1 is not Point') + if(!(point2 instanceof Point)) + throw new Error('the type of point2 is not Point') let distanceX = (point2.x - point1.x) ** 2; let distanceY = (point2.y - point1.y) ** 2; const distance = Math.sqrt(distanceX + distanceY); @@ -9,6 +13,10 @@ const calculateDistance = (point1, point2) => { } const calculateJunctionPoint = (line1, line2) => { + if(!(line1 instanceof Line)) + throw new Error('the type of line1 is not Line') + if(!(line2 instanceof Line)) + throw new Error('the type of line2 is not Line') if (line1.slope === line2.slope) { if (line1.n === line2.n) { return true @@ -25,6 +33,10 @@ const calculateJunctionPoint = (line1, line2) => { } const isPointOnLine = (line, point) => { + if(!(line instanceof Line)) + throw new Error('the type of line is not Line') + if(!(point instanceof Point)) + throw new Error('the type of point is not Point') const proxyLine = new Line({ point1: line.point1, point2: point }) proxyLine.calculateSlope() if (line.slope === proxyLine.slope) { diff --git a/package-lock.json b/package-lock.json index 61f4a09..faca934 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,9 @@ "license": "ISC", "dependencies": { "jest": "^29.7.0" + }, + "devDependencies": { + "nyc": "^17.0.0" } }, "node_modules/@ampproject/remapping": { @@ -894,6 +897,19 @@ "version": "21.0.3", "license": "MIT" }, + "node_modules/aggregate-error": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-3.1.0.tgz", + "integrity": "sha512-4I7Td01quW/RpocfNayFdFVk1qSuoh0E7JrbRJ16nH01HhKFQ88INq9Sd+nd72zqRySlr9BmDA8xlEJ6vJMrYA==", + "dev": true, + "dependencies": { + "clean-stack": "^2.0.0", + "indent-string": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/ansi-escapes": { "version": "4.3.2", "license": "MIT", @@ -938,6 +954,24 @@ "node": ">= 8" } }, + "node_modules/append-transform": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/append-transform/-/append-transform-2.0.0.tgz", + "integrity": "sha512-7yeyCEurROLQJFv5Xj4lEGTy0borxepjFv1g22oAdqFu//SrAlDl1O1Nxx15SH1RoliUml6p8dwJW9jvZughhg==", + "dev": true, + "dependencies": { + "default-require-extensions": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/archy": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/archy/-/archy-1.0.0.tgz", + "integrity": "sha512-Xg+9RwCg/0p32teKdGMPTPnVXKD0w3DfHnFTficozsAgsvq2XenPJq/MYpzzQ/v8zrOyJn6Ds39VA4JIDwFfqw==", + "dev": true + }, "node_modules/argparse": { "version": "1.0.10", "license": "MIT", @@ -1103,6 +1137,48 @@ "version": "1.1.2", "license": "MIT" }, + "node_modules/caching-transform": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/caching-transform/-/caching-transform-4.0.0.tgz", + "integrity": "sha512-kpqOvwXnjjN44D89K5ccQC+RUrsy7jB/XLlRrx0D7/2HNcTPqzsb6XgYoErwko6QsV184CA2YgS1fxDiiDZMWA==", + "dev": true, + "dependencies": { + "hasha": "^5.0.0", + "make-dir": "^3.0.0", + "package-hash": "^4.0.0", + "write-file-atomic": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/caching-transform/node_modules/make-dir": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", + "integrity": "sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==", + "dev": true, + "dependencies": { + "semver": "^6.0.0" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/caching-transform/node_modules/write-file-atomic": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-3.0.3.tgz", + "integrity": "sha512-AvHcyZ5JnSfq3ioSyjrBkH9yW4m7Ayk8/9My/DD9onKeu/94fwrMocemO2QAJFAlnnDN+ZDS+ZjAR5ua1/PV/Q==", + "dev": true, + "dependencies": { + "imurmurhash": "^0.1.4", + "is-typedarray": "^1.0.0", + "signal-exit": "^3.0.2", + "typedarray-to-buffer": "^3.1.5" + } + }, "node_modules/callsites": { "version": "3.1.0", "license": "MIT", @@ -1173,6 +1249,15 @@ "version": "1.2.3", "license": "MIT" }, + "node_modules/clean-stack": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/clean-stack/-/clean-stack-2.2.0.tgz", + "integrity": "sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==", + "dev": true, + "engines": { + "node": ">=6" + } + }, "node_modules/cliui": { "version": "8.0.1", "license": "ISC", @@ -1211,6 +1296,12 @@ "version": "1.1.4", "license": "MIT" }, + "node_modules/commondir": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", + "integrity": "sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==", + "dev": true + }, "node_modules/concat-map": { "version": "0.0.1", "license": "MIT" @@ -1265,6 +1356,15 @@ } } }, + "node_modules/decamelize": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", + "integrity": "sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/dedent": { "version": "1.5.1", "license": "MIT", @@ -1284,6 +1384,21 @@ "node": ">=0.10.0" } }, + "node_modules/default-require-extensions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/default-require-extensions/-/default-require-extensions-3.0.1.tgz", + "integrity": "sha512-eXTJmRbm2TIt9MgWTsOH1wEuhew6XGZcMeGKCtLedIg/NCsg1iBePXkceTdK4Fii7pzmN9tGsZhKzZ4h7O/fxw==", + "dev": true, + "dependencies": { + "strip-bom": "^4.0.0" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/detect-newline": { "version": "3.1.0", "license": "MIT", @@ -1323,6 +1438,12 @@ "is-arrayish": "^0.2.1" } }, + "node_modules/es6-error": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/es6-error/-/es6-error-4.1.1.tgz", + "integrity": "sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==", + "dev": true + }, "node_modules/escalade": { "version": "3.1.2", "license": "MIT", @@ -1410,6 +1531,38 @@ "node": ">=8" } }, + "node_modules/find-cache-dir": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-3.3.2.tgz", + "integrity": "sha512-wXZV5emFEjrridIgED11OoUKLxiYjAcqot/NJdAkOhlJ+vGzwhOAfcG5OX1jP+S0PcjEn8bdMJv+g2jwQ3Onig==", + "dev": true, + "dependencies": { + "commondir": "^1.0.1", + "make-dir": "^3.0.2", + "pkg-dir": "^4.1.0" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/avajs/find-cache-dir?sponsor=1" + } + }, + "node_modules/find-cache-dir/node_modules/make-dir": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", + "integrity": "sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==", + "dev": true, + "dependencies": { + "semver": "^6.0.0" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/find-up": { "version": "4.1.0", "license": "MIT", @@ -1421,6 +1574,39 @@ "node": ">=8" } }, + "node_modules/foreground-child": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-2.0.0.tgz", + "integrity": "sha512-dCIq9FpEcyQyXKCkyzmlPTFNgrCzPudOe+mhvJU5zAtlBnGVy2yKxtfsxK2tQBThwq225jcvBjpw1Gr40uzZCA==", + "dev": true, + "dependencies": { + "cross-spawn": "^7.0.0", + "signal-exit": "^3.0.2" + }, + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/fromentries": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/fromentries/-/fromentries-1.3.2.tgz", + "integrity": "sha512-cHEpEQHUg0f8XdtZCc2ZAhrHzKzT0MrFUTcvx+hfxYu7rGMDc5SKoXFh+n4YigxsHXRzc6OrCshdR1bWH6HHyg==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, "node_modules/fs.realpath": { "version": "1.0.0", "license": "ISC" @@ -1499,6 +1685,31 @@ "node": ">=8" } }, + "node_modules/hasha": { + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/hasha/-/hasha-5.2.2.tgz", + "integrity": "sha512-Hrp5vIK/xr5SkeN2onO32H0MgNZ0f17HRNH39WfL0SYUNOTZ5Lz1TJ8Pajo/87dYGEFlLMm7mIc/k/s6Bvz9HQ==", + "dev": true, + "dependencies": { + "is-stream": "^2.0.0", + "type-fest": "^0.8.0" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/hasha/node_modules/type-fest": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz", + "integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==", + "dev": true, + "engines": { + "node": ">=8" + } + }, "node_modules/hasown": { "version": "2.0.2", "license": "MIT", @@ -1544,6 +1755,15 @@ "node": ">=0.8.19" } }, + "node_modules/indent-string": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-4.0.0.tgz", + "integrity": "sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg==", + "dev": true, + "engines": { + "node": ">=8" + } + }, "node_modules/inflight": { "version": "1.0.6", "license": "ISC", @@ -1601,6 +1821,21 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/is-typedarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", + "integrity": "sha512-cyA56iCMHAh5CdzjJIa4aohJyeO1YbwLi3Jc35MmRU6poroFjIGZzUzupGiRPOjgHg9TLu43xbpwXk523fMxKA==", + "dev": true + }, + "node_modules/is-windows": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-windows/-/is-windows-1.0.2.tgz", + "integrity": "sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/isexe": { "version": "2.0.0", "license": "ISC" @@ -1612,6 +1847,18 @@ "node": ">=8" } }, + "node_modules/istanbul-lib-hook": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/istanbul-lib-hook/-/istanbul-lib-hook-3.0.0.tgz", + "integrity": "sha512-Pt/uge1Q9s+5VAZ+pCo16TYMWPBIl+oaNIjgLQxcX0itS6ueeaA+pEfThZpH8WxhFgCiEb8sAJY6MdUKgiIWaQ==", + "dev": true, + "dependencies": { + "append-transform": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/istanbul-lib-instrument": { "version": "6.0.2", "license": "BSD-3-Clause", @@ -1653,6 +1900,23 @@ "version": "4.0.0", "license": "ISC" }, + "node_modules/istanbul-lib-processinfo": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/istanbul-lib-processinfo/-/istanbul-lib-processinfo-2.0.3.tgz", + "integrity": "sha512-NkwHbo3E00oybX6NGJi6ar0B29vxyvNwoC7eJ4G4Yq28UfY758Hgn/heV8VRFhevPED4LXfFz0DQ8z/0kw9zMg==", + "dev": true, + "dependencies": { + "archy": "^1.0.0", + "cross-spawn": "^7.0.3", + "istanbul-lib-coverage": "^3.2.0", + "p-map": "^3.0.0", + "rimraf": "^3.0.0", + "uuid": "^8.3.2" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/istanbul-lib-report": { "version": "3.0.1", "license": "BSD-3-Clause", @@ -2282,6 +2546,12 @@ "node": ">=8" } }, + "node_modules/lodash.flattendeep": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz", + "integrity": "sha512-uHaJFihxmJcEX3kT4I23ABqKKalJ/zDrDg0lsFtc1h+3uw49SIJ5beyhx5ExVRti3AvKoOJngIj7xz3oylPdWQ==", + "dev": true + }, "node_modules/lru-cache": { "version": "5.1.1", "license": "ISC", @@ -2380,6 +2650,18 @@ "version": "0.4.0", "license": "MIT" }, + "node_modules/node-preload": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/node-preload/-/node-preload-0.2.1.tgz", + "integrity": "sha512-RM5oyBy45cLEoHqCeh+MNuFAxO0vTFBLskvQbOKnEE7YTTSN4tbN8QWDIPQ6L+WvKsB/qLEGpYe2ZZ9d4W9OIQ==", + "dev": true, + "dependencies": { + "process-on-spawn": "^1.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/node-releases": { "version": "2.0.14", "license": "MIT" @@ -2401,6 +2683,134 @@ "node": ">=8" } }, + "node_modules/nyc": { + "version": "17.0.0", + "resolved": "https://registry.npmjs.org/nyc/-/nyc-17.0.0.tgz", + "integrity": "sha512-ISp44nqNCaPugLLGGfknzQwSwt10SSS5IMoPR7GLoMAyS18Iw5js8U7ga2VF9lYuMZ42gOHr3UddZw4WZltxKg==", + "dev": true, + "dependencies": { + "@istanbuljs/load-nyc-config": "^1.0.0", + "@istanbuljs/schema": "^0.1.2", + "caching-transform": "^4.0.0", + "convert-source-map": "^1.7.0", + "decamelize": "^1.2.0", + "find-cache-dir": "^3.2.0", + "find-up": "^4.1.0", + "foreground-child": "^2.0.0", + "get-package-type": "^0.1.0", + "glob": "^7.1.6", + "istanbul-lib-coverage": "^3.0.0", + "istanbul-lib-hook": "^3.0.0", + "istanbul-lib-instrument": "^6.0.2", + "istanbul-lib-processinfo": "^2.0.2", + "istanbul-lib-report": "^3.0.0", + "istanbul-lib-source-maps": "^4.0.0", + "istanbul-reports": "^3.0.2", + "make-dir": "^3.0.0", + "node-preload": "^0.2.1", + "p-map": "^3.0.0", + "process-on-spawn": "^1.0.0", + "resolve-from": "^5.0.0", + "rimraf": "^3.0.0", + "signal-exit": "^3.0.2", + "spawn-wrap": "^2.0.0", + "test-exclude": "^6.0.0", + "yargs": "^15.0.2" + }, + "bin": { + "nyc": "bin/nyc.js" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/nyc/node_modules/cliui": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-6.0.0.tgz", + "integrity": "sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==", + "dev": true, + "dependencies": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.0", + "wrap-ansi": "^6.2.0" + } + }, + "node_modules/nyc/node_modules/convert-source-map": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.9.0.tgz", + "integrity": "sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==", + "dev": true + }, + "node_modules/nyc/node_modules/make-dir": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", + "integrity": "sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==", + "dev": true, + "dependencies": { + "semver": "^6.0.0" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/nyc/node_modules/wrap-ansi": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", + "integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/nyc/node_modules/y18n": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz", + "integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==", + "dev": true + }, + "node_modules/nyc/node_modules/yargs": { + "version": "15.4.1", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-15.4.1.tgz", + "integrity": "sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==", + "dev": true, + "dependencies": { + "cliui": "^6.0.0", + "decamelize": "^1.2.0", + "find-up": "^4.1.0", + "get-caller-file": "^2.0.1", + "require-directory": "^2.1.1", + "require-main-filename": "^2.0.0", + "set-blocking": "^2.0.0", + "string-width": "^4.2.0", + "which-module": "^2.0.0", + "y18n": "^4.0.0", + "yargs-parser": "^18.1.2" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/nyc/node_modules/yargs-parser": { + "version": "18.1.3", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.3.tgz", + "integrity": "sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==", + "dev": true, + "dependencies": { + "camelcase": "^5.0.0", + "decamelize": "^1.2.0" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/once": { "version": "1.4.0", "license": "ISC", @@ -2457,6 +2867,18 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/p-map": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/p-map/-/p-map-3.0.0.tgz", + "integrity": "sha512-d3qXVTF/s+W+CdJ5A29wywV2n8CQQYahlgz2bFiA+4eVNJbHJodPZ+/gXwPGh0bOqA+j8S+6+ckmvLGPk1QpxQ==", + "dev": true, + "dependencies": { + "aggregate-error": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/p-try": { "version": "2.2.0", "license": "MIT", @@ -2464,6 +2886,21 @@ "node": ">=6" } }, + "node_modules/package-hash": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/package-hash/-/package-hash-4.0.0.tgz", + "integrity": "sha512-whdkPIooSu/bASggZ96BWVvZTRMOFxnyUG5PnTSGKoJE2gd5mbVNmR2Nj20QFzxYYgAXpoqC+AiXzl+UMRh7zQ==", + "dev": true, + "dependencies": { + "graceful-fs": "^4.1.15", + "hasha": "^5.0.0", + "lodash.flattendeep": "^4.4.0", + "release-zalgo": "^1.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/parse-json": { "version": "5.2.0", "license": "MIT", @@ -2558,6 +2995,18 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, + "node_modules/process-on-spawn": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/process-on-spawn/-/process-on-spawn-1.0.0.tgz", + "integrity": "sha512-1WsPDsUSMmZH5LeMLegqkPDrsGgsWwk1Exipy2hvB0o/F0ASzbpIctSCcZIK1ykJvtTJULEH+20WOFjMvGnCTg==", + "dev": true, + "dependencies": { + "fromentries": "^1.2.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/prompts": { "version": "2.4.2", "license": "MIT", @@ -2587,6 +3036,18 @@ "version": "18.2.0", "license": "MIT" }, + "node_modules/release-zalgo": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/release-zalgo/-/release-zalgo-1.0.0.tgz", + "integrity": "sha512-gUAyHVHPPC5wdqX/LG4LWtRYtgjxyX78oanFNTMMyFEfOqdC54s3eE82imuWKbOeqYht2CrNf64Qb8vgmmtZGA==", + "dev": true, + "dependencies": { + "es6-error": "^4.0.1" + }, + "engines": { + "node": ">=4" + } + }, "node_modules/require-directory": { "version": "2.1.1", "license": "MIT", @@ -2594,6 +3055,12 @@ "node": ">=0.10.0" } }, + "node_modules/require-main-filename": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", + "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==", + "dev": true + }, "node_modules/resolve": { "version": "1.22.8", "license": "MIT", @@ -2633,6 +3100,22 @@ "node": ">=10" } }, + "node_modules/rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "deprecated": "Rimraf versions prior to v4 are no longer supported", + "dev": true, + "dependencies": { + "glob": "^7.1.3" + }, + "bin": { + "rimraf": "bin.js" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/semver": { "version": "6.3.1", "license": "ISC", @@ -2640,6 +3123,12 @@ "semver": "bin/semver.js" } }, + "node_modules/set-blocking": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", + "integrity": "sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==", + "dev": true + }, "node_modules/shebang-command": { "version": "2.0.0", "license": "MIT", @@ -2687,6 +3176,38 @@ "source-map": "^0.6.0" } }, + "node_modules/spawn-wrap": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/spawn-wrap/-/spawn-wrap-2.0.0.tgz", + "integrity": "sha512-EeajNjfN9zMnULLwhZZQU3GWBoFNkbngTUPfaawT4RkMiviTxcX0qfhVbGey39mfctfDHkWtuecgQ8NJcyQWHg==", + "dev": true, + "dependencies": { + "foreground-child": "^2.0.0", + "is-windows": "^1.0.2", + "make-dir": "^3.0.0", + "rimraf": "^3.0.0", + "signal-exit": "^3.0.2", + "which": "^2.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/spawn-wrap/node_modules/make-dir": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", + "integrity": "sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==", + "dev": true, + "dependencies": { + "semver": "^6.0.0" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/sprintf-js": { "version": "1.0.3", "license": "BSD-3-Clause" @@ -2828,6 +3349,15 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/typedarray-to-buffer": { + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz", + "integrity": "sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==", + "dev": true, + "dependencies": { + "is-typedarray": "^1.0.0" + } + }, "node_modules/undici-types": { "version": "5.26.5", "license": "MIT" @@ -2860,6 +3390,15 @@ "browserslist": ">= 4.21.0" } }, + "node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "dev": true, + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/v8-to-istanbul": { "version": "9.2.0", "license": "ISC", @@ -2892,6 +3431,12 @@ "node": ">= 8" } }, + "node_modules/which-module": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.1.tgz", + "integrity": "sha512-iBdZ57RDvnOR9AGBhML2vFZf7h8vmBjhoaZqODJBFWHVtKkDmKuHai3cx5PgVMrX5YDNp27AofYbAwctSS+vhQ==", + "dev": true + }, "node_modules/wrap-ansi": { "version": "7.0.0", "license": "MIT", diff --git a/package.json b/package.json index 7b41f03..9a8b6e4 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "scripts": { "test": "jest", - "test:coverage":"npm run test -- --coverage" + "test:coverage": "npm run test -- --coverage" }, "dependencies": { "jest": "^29.7.0" @@ -19,6 +19,8 @@ }, "homepage": "https://github.com/gemtechd/build-tests#readme", "author": "gemtechd", - "license": "ISC" - + "license": "ISC", + "devDependencies": { + "nyc": "^17.0.0" + } } diff --git a/tests/modules/ecs6-class/line.test.js b/tests/modules/ecs6-class/line.test.js index afc92e7..4387096 100644 --- a/tests/modules/ecs6-class/line.test.js +++ b/tests/modules/ecs6-class/line.test.js @@ -8,6 +8,12 @@ describe('CONSTRUCTOR',() => { expect(line.n).toBe(4) expect(line.point1.x).toBe(0) }) + it('should build an object with default values',() => { + expect(()=> new Line({point1:[],point2:new Point({x:2,y:2})})).toThrowError('the type of point1 is not Point') + }) + it('should build an object with default values',() => { + expect(()=> new Line({point1:new Point({x:2,y:2}),point2:[]})).toThrowError('the type of point2 is not Point') + }) }) @@ -62,4 +68,8 @@ describe('GET_POINT_BY_Y', () =>{ const result = line.getPointByY(2) expect(result).toEqual({x:5,y:2}) }) + it('An error should be thrown when the slope equals 0', () => { + const line = new Line({point1:new Point({x:2,y:6}),point2:new Point({x:1,y:6}),n:6,slope:0}) + expect(()=>line.getPointByY(11)).toThrowError('division by zero') + }) }) \ No newline at end of file diff --git a/tests/modules/ecs6-class/point.test.js b/tests/modules/ecs6-class/point.test.js index c465c7a..732b7f0 100644 --- a/tests/modules/ecs6-class/point.test.js +++ b/tests/modules/ecs6-class/point.test.js @@ -17,21 +17,18 @@ describe('CONSTRUCTOR',() => { const point = new Point({x:5.5}) expect(point).toEqual({x:5.5,y:0}) }) + it('An error should be thrown when the type of x is not number' , () => { - expect(()=> new Point({x:'l',y:9}).toThrowError('type of x is not number')) + expect(() => new Point({x:'l',y:9})).toThrowError('type of x is not number') }) - it('An error should be thrown when the type of x is not number' , () => { - expect(()=> new Point({x:[],y:9}).toThrowError('type of x is not number')) + it('An error should be thrown when the type of x is not number' , () => { + expect(() => new Point({x:[9,0],y:9})).toThrowError('type of x is not number') }) it('An error should be thrown when the type of x is not number' , () => { - expect(()=> new Point({x:4,y:[]}).toThrowError('type of x is not number')) - }) - - it('An error should be thrown when the type of y is not number' , () => { - expect(()=> new Point({x:'a',y:'a'}).toThrowError('type of y is not number')) - }) + expect(() => new Point({x:4,y:[]})).toThrowError('type of y is not number') + }) it('An error should be thrown when the type of y is not number' , () => { - expect(()=> new Point({x:5,y:'a'}).toThrowError('type of y is not number')) + expect(() => new Point({x:5,y:'a'})).toThrowError('type of y is not number') }) }) @@ -43,7 +40,7 @@ describe('MOVE_VERTICAL', ()=> { }) it('An error should be thrown when the type of value is not number',()=> { const point = new Point({x:5,y:6}) - expect(()=>point.moveVertical('a').toThrowError('type of number is not number')) + expect(() => point.moveVertical('a')).toThrowError('the type of the value is not correctly') }) }) @@ -56,6 +53,6 @@ describe('MOVE_HORIZONTAL', ()=> { it('An error should be thrown when the type of value is not number',()=> { const point = new Point({x:5,y:6}) - expect(()=>point.moveHorizontal('a').toThrowError('type of number is not number')) + expect(()=>point.moveHorizontal('a')).toThrowError('the type of the value is not correctly') }) }) \ No newline at end of file diff --git a/tests/modules/geometry-calculation.test.js b/tests/modules/geometry-calculation.test.js index 66669c3..e44c9ae 100644 --- a/tests/modules/geometry-calculation.test.js +++ b/tests/modules/geometry-calculation.test.js @@ -4,74 +4,90 @@ const Point = require('../../modules/ecs6-class/point') const { calculateDistance,calculateJunctionPoint,isPointOnLine} = require('../../modules/geometry-calculation') - describe('CALCULATE_DISTANCE',() => { it('should return the correct answer', () => { const line = new Line({point1:new Point({x:6,y:4}),point2:new Point({x:2,y:1})}) const result = calculateDistance(line.point1,line.point2) expect(result).toBe(5) }) + it('An error should be thrown when point1 is not of type Point', () => { + expect(()=>calculateDistance('k',new Point({x:6,y:4}))).toThrowError('the type of point1 is not Point') + }) + it('An error should be thrown when point2 is not of type Point', () => { + expect(()=>calculateDistance(new Point({x:6,y:4}),'k')).toThrowError('the type of point2 is not Point') + }) }) describe('CALCULATE_JUNCTION_POINT', () => { it('should return true when the 2 lines are equal', () =>{ - const line1 = new Line({point1:new Point({x:6,y:4}),point2:new Point({x:2,y:1})}) - const line2 = new Line({point1:new Point({x:6,y:4}),point2:new Point({x:2,y:1})}) - line1.calculateSlope() - line2.calculateSlope() - line1.calculateNOfLineFunction() - line2.calculateNOfLineFunction() + const line1 = new Line({point1:new Point({x:6,y:4}),point2:new Point({x:2,y:1}),n:-0.5,slope:0.75}) + const line2 = new Line({point1:new Point({x:6,y:4}),point2:new Point({x:2,y:1}),n:-0.5,slope:0.75}) const result = calculateJunctionPoint(line1,line2) expect(result).toBeTruthy() }) it('should return false when the 2 lines are parallels', () =>{ - const line1 = new Line({point1:new Point({x:6,y:4}),point2:new Point({x:2,y:1})}) - const line2 = new Line({point1:new Point({x:5,y:3}),point2:new Point({x:1,y:0})}) - line1.calculateSlope() - line2.calculateSlope() - line1.calculateNOfLineFunction() - line2.calculateNOfLineFunction() + const line1 = new Line({point1:new Point({x:6,y:4}),point2:new Point({x:2,y:1}),n:-0.5,slope:0.75}) + const line2 = new Line({point1:new Point({x:5,y:3}),point2:new Point({x:1,y:0}),n:-0.75,slope:0.75}) const result = calculateJunctionPoint(line1,line2) expect(result).toBeFalsy() }) it('should return point when the 2 lines are not equal', () =>{ - const line1 = new Line({point1:new Point({x:8,y:3}),point2:new Point({x:6,y:1})}) - const line2 = new Line({point1:new Point({x:5,y:3}),point2:new Point({x:1,y:0})}) - line1.calculateSlope() - line2.calculateSlope() + const line1 = new Line({point1:new Point({x:8,y:3}),point2:new Point({x:6,y:1}),slope:1}) + const line2 = new Line({point1:new Point({x:5,y:3}),point2:new Point({x:1,y:0}),slope:0.75}) line1.calculateNOfLineFunction() line2.calculateNOfLineFunction() const result = calculateJunctionPoint(line1,line2) expect(result).toEqual({ x: 17, y: 12 }) }) + it('An error should be thrown when line2 is not of type Line', () =>{ + const line1 = new Line({point1:new Point({x:8,y:3}),point2:new Point({x:6,y:1}),slope:1}) + line1.calculateNOfLineFunction() + expect(()=>calculateJunctionPoint(line1,[])).toThrowError('the type of line2 is not Line') + }) + it('An error should be thrown when line1 is not of type Line', () =>{ + const line2 = new Line({point1:new Point({x:8,y:3}),point2:new Point({x:6,y:1}),slope:1}) + line2.calculateNOfLineFunction() + expect(()=>calculateJunctionPoint('g',line2)).toThrowError('the type of line1 is not Line') + }) }) + describe('IS_POINT_ON_LINE',() => { it('should return true when the point on this line',() => { - const line = new Line({point1:new Point({x:8,y:4}),point2:new Point({x:2,y:1})}) - line.calculateSlope() - line.calculateNOfLineFunction() - console.log({line}); + const line = new Line({point1:new Point({x:8,y:4}),point2:new Point({x:2,y:1}),slope:0.5}) + line.calculateNOfLineFunction() const point = new Point({x:6,y:3}) const result = isPointOnLine(line,point) expect(result).toBeTruthy() }) + it('Should return true if the point on the line', () => { + const line = new Line({ point1: new Point({ 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 true when the point on this line',() => { - const line = new Line({point1:new Point({x:10,y:10}),point2:new Point({x:8,y:2})}) - line.calculateSlope() + const line = new Line({point1:new Point({x:10,y:10}),point2:new Point({x:8,y:2}),slope:4}) line.calculateNOfLineFunction() - console.log({line}); const point = new Point({x:6,y:-6}) const result = isPointOnLine(line,point) expect(result).toBeTruthy() }) it('should return false when the point is not on this line',() => { - const line = new Line({point1:new Point({x:8,y:3}),point2:new Point({x:6,y:1})}) - line.calculateSlope() + const line = new Line({point1:new Point({x:8,y:3}),point2:new Point({x:6,y:1}),slope:1}) line.calculateNOfLineFunction() const point = new Point({x:5,y:6}) const result = isPointOnLine(line,point) expect(result).toBeFalsy() }) + it('An error should be thrown when the point is not of type Point', () =>{ + const line = new Line({point1:new Point({x:8,y:3}),point2:new Point({x:6,y:1}),slope:1}) + line.calculateNOfLineFunction() + expect(()=>isPointOnLine(line,'k')).toThrowError('the type of point is not Point') + }) + it('An error should be thrown when point2 is not of type Point', () => { + const point = new Point({x:6,y:4}) + expect(()=>isPointOnLine('k',point)).toThrowError('the type of line is not Line') + }) }) \ No newline at end of file From 5240ab0ef3751471009cf54288f2c33c039bdef8 Mon Sep 17 00:00:00 2001 From: shoshym Date: Sun, 28 Jul 2024 09:07:04 +0300 Subject: [PATCH 3/3] finish the task for now withou mock --- .../c01c1e36-b435-4824-aee0-a5928b1cc43e.json | 1 - .../c01c1e36-b435-4824-aee0-a5928b1cc43e.json | 1 - .nyc_output/processinfo/index.json | 1 - modules/ecs6-class/line.js | 14 +++++++--- modules/geometry-calculation.js | 19 +++++++++---- tests/modules/ecs6-class/line.test.js | 22 +++++++++++++-- tests/modules/geometry-calculation.test.js | 27 +++++++++++-------- 7 files changed, 60 insertions(+), 25 deletions(-) delete mode 100644 .nyc_output/c01c1e36-b435-4824-aee0-a5928b1cc43e.json delete mode 100644 .nyc_output/processinfo/c01c1e36-b435-4824-aee0-a5928b1cc43e.json delete mode 100644 .nyc_output/processinfo/index.json diff --git a/.nyc_output/c01c1e36-b435-4824-aee0-a5928b1cc43e.json b/.nyc_output/c01c1e36-b435-4824-aee0-a5928b1cc43e.json deleted file mode 100644 index f08ad37..0000000 --- a/.nyc_output/c01c1e36-b435-4824-aee0-a5928b1cc43e.json +++ /dev/null @@ -1 +0,0 @@ -{"C:\\task2-test\\build-tests-fork\\modules\\ecs6-class\\line.js":{"path":"C:\\task2-test\\build-tests-fork\\modules\\ecs6-class\\line.js","statementMap":{"0":{"start":{"line":1,"column":14},"end":{"line":1,"column":32}},"1":{"start":{"line":5,"column":7},"end":{"line":15,"column":58}},"2":{"start":{"line":6,"column":10},"end":{"line":13,"column":58}},"3":{"start":{"line":7,"column":12},"end":{"line":7,"column":33}},"4":{"start":{"line":8,"column":12},"end":{"line":8,"column":33}},"5":{"start":{"line":9,"column":12},"end":{"line":9,"column":31}},"6":{"start":{"line":10,"column":12},"end":{"line":10,"column":23}},"7":{"start":{"line":13,"column":8},"end":{"line":13,"column":58}},"8":{"start":{"line":15,"column":8},"end":{"line":15,"column":58}},"9":{"start":{"line":18,"column":21},"end":{"line":23,"column":5}},"10":{"start":{"line":19,"column":8},"end":{"line":22,"column":45}},"11":{"start":{"line":20,"column":10},"end":{"line":20,"column":88}},"12":{"start":{"line":22,"column":10},"end":{"line":22,"column":45}},"13":{"start":{"line":25,"column":31},"end":{"line":27,"column":5}},"14":{"start":{"line":26,"column":8},"end":{"line":26,"column":59}},"15":{"start":{"line":30,"column":8},"end":{"line":30,"column":34}},"16":{"start":{"line":34,"column":8},"end":{"line":34,"column":34}},"17":{"start":{"line":39,"column":16},"end":{"line":39,"column":39}},"18":{"start":{"line":40,"column":8},"end":{"line":40,"column":34}},"19":{"start":{"line":44,"column":16},"end":{"line":44,"column":41}},"20":{"start":{"line":45,"column":8},"end":{"line":45,"column":34}},"21":{"start":{"line":49,"column":0},"end":{"line":49,"column":21}}},"fnMap":{"0":{"name":"(anonymous_0)","decl":{"start":{"line":4,"column":4},"end":{"line":4,"column":5}},"loc":{"start":{"line":4,"column":98},"end":{"line":16,"column":5}},"line":4},"1":{"name":"(anonymous_1)","decl":{"start":{"line":18,"column":21},"end":{"line":18,"column":22}},"loc":{"start":{"line":18,"column":27},"end":{"line":23,"column":5}},"line":18},"2":{"name":"(anonymous_2)","decl":{"start":{"line":25,"column":31},"end":{"line":25,"column":32}},"loc":{"start":{"line":25,"column":37},"end":{"line":27,"column":5}},"line":25},"3":{"name":"(anonymous_3)","decl":{"start":{"line":29,"column":4},"end":{"line":29,"column":5}},"loc":{"start":{"line":29,"column":22},"end":{"line":31,"column":5}},"line":29},"4":{"name":"(anonymous_4)","decl":{"start":{"line":33,"column":4},"end":{"line":33,"column":5}},"loc":{"start":{"line":33,"column":22},"end":{"line":35,"column":5}},"line":33},"5":{"name":"(anonymous_5)","decl":{"start":{"line":38,"column":4},"end":{"line":38,"column":5}},"loc":{"start":{"line":38,"column":19},"end":{"line":41,"column":5}},"line":38},"6":{"name":"(anonymous_6)","decl":{"start":{"line":43,"column":4},"end":{"line":43,"column":5}},"loc":{"start":{"line":43,"column":19},"end":{"line":46,"column":5}},"line":43}},"branchMap":{"0":{"loc":{"start":{"line":4,"column":18},"end":{"line":4,"column":38}},"type":"default-arg","locations":[{"start":{"line":4,"column":27},"end":{"line":4,"column":38}}],"line":4},"1":{"loc":{"start":{"line":4,"column":40},"end":{"line":4,"column":60}},"type":"default-arg","locations":[{"start":{"line":4,"column":49},"end":{"line":4,"column":60}}],"line":4},"2":{"loc":{"start":{"line":4,"column":62},"end":{"line":4,"column":75}},"type":"default-arg","locations":[{"start":{"line":4,"column":66},"end":{"line":4,"column":75}}],"line":4},"3":{"loc":{"start":{"line":4,"column":77},"end":{"line":4,"column":94}},"type":"default-arg","locations":[{"start":{"line":4,"column":85},"end":{"line":4,"column":94}}],"line":4},"4":{"loc":{"start":{"line":5,"column":7},"end":{"line":15,"column":58}},"type":"if","locations":[{"start":{"line":5,"column":7},"end":{"line":15,"column":58}},{"start":{"line":15,"column":8},"end":{"line":15,"column":58}}],"line":5},"5":{"loc":{"start":{"line":6,"column":10},"end":{"line":13,"column":58}},"type":"if","locations":[{"start":{"line":6,"column":10},"end":{"line":13,"column":58}},{"start":{"line":13,"column":8},"end":{"line":13,"column":58}}],"line":6},"6":{"loc":{"start":{"line":19,"column":8},"end":{"line":22,"column":45}},"type":"if","locations":[{"start":{"line":19,"column":8},"end":{"line":22,"column":45}},{"start":{"line":22,"column":10},"end":{"line":22,"column":45}}],"line":19}},"s":{"0":1,"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":1},"f":{"0":0,"1":0,"2":0,"3":0,"4":0,"5":0,"6":0},"b":{"0":[0],"1":[0],"2":[0],"3":[0],"4":[0,0],"5":[0,0],"6":[0,0]},"_coverageSchema":"1a1c01bbd47fc00a2c39e90264f33305004495a9","hash":"b5a728190e78626a4c269463d2ae8a826a4cdc78","contentHash":"ca9346dbfcf8b7ccffa3ad6e5100f7af0d3e93021b43ca2c7dd270176fb686b8"},"C:\\task2-test\\build-tests-fork\\modules\\ecs6-class\\point.js":{"path":"C:\\task2-test\\build-tests-fork\\modules\\ecs6-class\\point.js","statementMap":{"0":{"start":{"line":3,"column":8},"end":{"line":4,"column":54}},"1":{"start":{"line":4,"column":12},"end":{"line":4,"column":54}},"2":{"start":{"line":5,"column":8},"end":{"line":6,"column":54}},"3":{"start":{"line":6,"column":12},"end":{"line":6,"column":54}},"4":{"start":{"line":7,"column":8},"end":{"line":7,"column":19}},"5":{"start":{"line":8,"column":8},"end":{"line":8,"column":19}},"6":{"start":{"line":11,"column":8},"end":{"line":12,"column":69}},"7":{"start":{"line":12,"column":12},"end":{"line":12,"column":69}},"8":{"start":{"line":13,"column":11},"end":{"line":13,"column":27}},"9":{"start":{"line":16,"column":8},"end":{"line":17,"column":69}},"10":{"start":{"line":17,"column":12},"end":{"line":17,"column":69}},"11":{"start":{"line":18,"column":8},"end":{"line":18,"column":24}},"12":{"start":{"line":23,"column":0},"end":{"line":23,"column":22}}},"fnMap":{"0":{"name":"(anonymous_0)","decl":{"start":{"line":2,"column":4},"end":{"line":2,"column":5}},"loc":{"start":{"line":2,"column":31},"end":{"line":9,"column":5}},"line":2},"1":{"name":"(anonymous_1)","decl":{"start":{"line":10,"column":4},"end":{"line":10,"column":5}},"loc":{"start":{"line":10,"column":24},"end":{"line":14,"column":5}},"line":10},"2":{"name":"(anonymous_2)","decl":{"start":{"line":15,"column":4},"end":{"line":15,"column":5}},"loc":{"start":{"line":15,"column":26},"end":{"line":20,"column":5}},"line":15}},"branchMap":{"0":{"loc":{"start":{"line":2,"column":16},"end":{"line":2,"column":29}},"type":"default-arg","locations":[{"start":{"line":2,"column":27},"end":{"line":2,"column":29}}],"line":2},"1":{"loc":{"start":{"line":2,"column":17},"end":{"line":2,"column":20}},"type":"default-arg","locations":[{"start":{"line":2,"column":19},"end":{"line":2,"column":20}}],"line":2},"2":{"loc":{"start":{"line":2,"column":22},"end":{"line":2,"column":25}},"type":"default-arg","locations":[{"start":{"line":2,"column":24},"end":{"line":2,"column":25}}],"line":2},"3":{"loc":{"start":{"line":3,"column":8},"end":{"line":4,"column":54}},"type":"if","locations":[{"start":{"line":3,"column":8},"end":{"line":4,"column":54}},{"start":{},"end":{}}],"line":3},"4":{"loc":{"start":{"line":5,"column":8},"end":{"line":6,"column":54}},"type":"if","locations":[{"start":{"line":5,"column":8},"end":{"line":6,"column":54}},{"start":{},"end":{}}],"line":5},"5":{"loc":{"start":{"line":11,"column":8},"end":{"line":12,"column":69}},"type":"if","locations":[{"start":{"line":11,"column":8},"end":{"line":12,"column":69}},{"start":{},"end":{}}],"line":11},"6":{"loc":{"start":{"line":16,"column":8},"end":{"line":17,"column":69}},"type":"if","locations":[{"start":{"line":16,"column":8},"end":{"line":17,"column":69}},{"start":{},"end":{}}],"line":16}},"s":{"0":0,"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":1},"f":{"0":0,"1":0,"2":0},"b":{"0":[0],"1":[0],"2":[0],"3":[0,0],"4":[0,0],"5":[0,0],"6":[0,0]},"_coverageSchema":"1a1c01bbd47fc00a2c39e90264f33305004495a9","hash":"955ad9827827a9c506bf5fdd096831c58cb64bc6","contentHash":"357d106cec673c00fb289c32dbf25c2f00f77d3a7d83e2e3882eafe8740edd68"}} \ No newline at end of file diff --git a/.nyc_output/processinfo/c01c1e36-b435-4824-aee0-a5928b1cc43e.json b/.nyc_output/processinfo/c01c1e36-b435-4824-aee0-a5928b1cc43e.json deleted file mode 100644 index f65fe27..0000000 --- a/.nyc_output/processinfo/c01c1e36-b435-4824-aee0-a5928b1cc43e.json +++ /dev/null @@ -1 +0,0 @@ -{"parent":null,"pid":5056,"argv":["C:\\Program Files\\nodejs\\node.exe","C:\\task2-test\\build-tests-fork\\tests\\modules\\ecs6-class\\line.test.js"],"execArgv":[],"cwd":"C:\\task2-test\\build-tests-fork\\tests\\modules\\ecs6-class","time":1721803202735,"ppid":10832,"coverageFilename":"C:\\task2-test\\build-tests-fork\\.nyc_output\\c01c1e36-b435-4824-aee0-a5928b1cc43e.json","externalId":"","uuid":"c01c1e36-b435-4824-aee0-a5928b1cc43e","files":["C:\\task2-test\\build-tests-fork\\modules\\ecs6-class\\line.js","C:\\task2-test\\build-tests-fork\\modules\\ecs6-class\\point.js"]} \ No newline at end of file diff --git a/.nyc_output/processinfo/index.json b/.nyc_output/processinfo/index.json deleted file mode 100644 index ed5b2b2..0000000 --- a/.nyc_output/processinfo/index.json +++ /dev/null @@ -1 +0,0 @@ -{"processes":{"c01c1e36-b435-4824-aee0-a5928b1cc43e":{"parent":null,"children":[]}},"files":{"C:\\task2-test\\build-tests-fork\\modules\\ecs6-class\\line.js":["c01c1e36-b435-4824-aee0-a5928b1cc43e"],"C:\\task2-test\\build-tests-fork\\modules\\ecs6-class\\point.js":["c01c1e36-b435-4824-aee0-a5928b1cc43e"]},"externalIds":{}} \ No newline at end of file diff --git a/modules/ecs6-class/line.js b/modules/ecs6-class/line.js index 7f55083..9b132e3 100644 --- a/modules/ecs6-class/line.js +++ b/modules/ecs6-class/line.js @@ -6,11 +6,17 @@ class Line { if((point2 instanceof Point)){ this.point1 = point1; this.point2 = point2; - this.slope = slope; - this.n = n; + if(typeof slope === 'number' || typeof slope === 'undefined') + this.slope = slope; + else + throw new Error('the type of slope is not number'); + if(typeof n === 'number' || typeof n === 'undefined') + this.n = n; + else + throw new Error('the type of n is not number'); } - else{ - throw new Error('the type of point2 is not Point')} + else + throw new Error('the type of point2 is not Point') else throw new Error('the type of point1 is not Point') } diff --git a/modules/geometry-calculation.js b/modules/geometry-calculation.js index 2975a52..614e89f 100644 --- a/modules/geometry-calculation.js +++ b/modules/geometry-calculation.js @@ -17,6 +17,14 @@ const calculateJunctionPoint = (line1, line2) => { throw new Error('the type of line1 is not Line') if(!(line2 instanceof Line)) throw new Error('the type of line2 is not Line') + if(line1.slope === undefined) + line1.calculateSlope() + if(line2.slope === undefined) + line2.calculateSlope() + if(line1.n === undefined) + line1.calculateNOfLineFunction() + if(line2.n === undefined) + line2.calculateNOfLineFunction() if (line1.slope === line2.slope) { if (line1.n === line2.n) { return true @@ -39,13 +47,14 @@ const isPointOnLine = (line, point) => { throw new Error('the type of point is not Point') const proxyLine = new Line({ point1: line.point1, point2: point }) proxyLine.calculateSlope() - if (line.slope === proxyLine.slope) { - proxyLine.calculateNOfLineFunction() - if (line.n === proxyLine.n) { - return true + if (line.slope === proxyLine.slope) { + proxyLine.calculateNOfLineFunction() + if (line.n === proxyLine.n) { + return true + } } - } return false + } module.exports = { diff --git a/tests/modules/ecs6-class/line.test.js b/tests/modules/ecs6-class/line.test.js index 4387096..8487ebf 100644 --- a/tests/modules/ecs6-class/line.test.js +++ b/tests/modules/ecs6-class/line.test.js @@ -1,6 +1,16 @@ const Line = require('../../../modules/ecs6-class/line') const Point = require('../../../modules/ecs6-class/point') +let mockCalculatSlope = jest.fn() + +// jest.mock('../../modules/ecs6-class/line',()=>{ +// return{ +// calculateSlope:mockCalculatSlope +// } +// }) + +// mockCalculatSlope.mockImplementation() + describe('CONSTRUCTOR',() => { it('should build an object with default values',() => { const line = new Line({slope:5,n:4}) @@ -8,12 +18,20 @@ describe('CONSTRUCTOR',() => { expect(line.n).toBe(4) expect(line.point1.x).toBe(0) }) - it('should build an object with default values',() => { + it('An error should be thrown when the point1 is not of type Point',() => { expect(()=> new Line({point1:[],point2:new Point({x:2,y:2})})).toThrowError('the type of point1 is not Point') }) - it('should build an object with default values',() => { + + it('An error should be thrown when the point2 is not of type Point',() => { expect(()=> new Line({point1:new Point({x:2,y:2}),point2:[]})).toThrowError('the type of point2 is not Point') }) + + it('An error should be thrown when the slope is not of type number',() => { + expect(()=> new Line({point1:new Point({x:2,y:2,}),point2:new Point({x:2,y:2}),slope:'a'})).toThrowError('the type of slope is not number') + }) + it('An error should be thrown when the n is not of type number',() => { + expect(()=> new Line({point1:new Point({x:2,y:2}),point2:new Point({x:2,y:2}),n:'a'})).toThrowError('the type of n is not number') + }) }) diff --git a/tests/modules/geometry-calculation.test.js b/tests/modules/geometry-calculation.test.js index e44c9ae..96ca348 100644 --- a/tests/modules/geometry-calculation.test.js +++ b/tests/modules/geometry-calculation.test.js @@ -17,6 +17,7 @@ describe('CALCULATE_DISTANCE',() => { expect(()=>calculateDistance(new Point({x:6,y:4}),'k')).toThrowError('the type of point2 is not Point') }) }) + describe('CALCULATE_JUNCTION_POINT', () => { it('should return true when the 2 lines are equal', () =>{ const line1 = new Line({point1:new Point({x:6,y:4}),point2:new Point({x:2,y:1}),n:-0.5,slope:0.75}) @@ -24,14 +25,18 @@ describe('CALCULATE_JUNCTION_POINT', () => { const result = calculateJunctionPoint(line1,line2) expect(result).toBeTruthy() }) - it('should return false when the 2 lines are parallels', () =>{ const line1 = new Line({point1:new Point({x:6,y:4}),point2:new Point({x:2,y:1}),n:-0.5,slope:0.75}) const line2 = new Line({point1:new Point({x:5,y:3}),point2:new Point({x:1,y:0}),n:-0.75,slope:0.75}) const result = calculateJunctionPoint(line1,line2) expect(result).toBeFalsy() }) - + it('should return false when the 2 lines are parallels', () =>{ + const line1 = new Line({point1:new Point({x:6,y:4}),point2:new Point({x:2,y:1})}) + const line2 = new Line({point1:new Point({x:5,y:3}),point2:new Point({x:1,y:0})}) + const result = calculateJunctionPoint(line1,line2) + expect(result).toBeFalsy() + }) it('should return point when the 2 lines are not equal', () =>{ const line1 = new Line({point1:new Point({x:8,y:3}),point2:new Point({x:6,y:1}),slope:1}) const line2 = new Line({point1:new Point({x:5,y:3}),point2:new Point({x:1,y:0}),slope:0.75}) @@ -47,7 +52,7 @@ describe('CALCULATE_JUNCTION_POINT', () => { }) it('An error should be thrown when line1 is not of type Line', () =>{ const line2 = new Line({point1:new Point({x:8,y:3}),point2:new Point({x:6,y:1}),slope:1}) - line2.calculateNOfLineFunction() + line2.calculateNOfLineFunction() expect(()=>calculateJunctionPoint('g',line2)).toThrowError('the type of line1 is not Line') }) }) @@ -56,17 +61,12 @@ describe('CALCULATE_JUNCTION_POINT', () => { describe('IS_POINT_ON_LINE',() => { it('should return true when the point on this line',() => { const line = new Line({point1:new Point({x:8,y:4}),point2:new Point({x:2,y:1}),slope:0.5}) - line.calculateNOfLineFunction() + line.calculateNOfLineFunction() const point = new Point({x:6,y:3}) const result = isPointOnLine(line,point) expect(result).toBeTruthy() }) - it('Should return true if the point on the line', () => { - const line = new Line({ point1: new Point({ 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 true when the point on this line',() => { const line = new Line({point1:new Point({x:10,y:10}),point2:new Point({x:8,y:2}),slope:4}) line.calculateNOfLineFunction() @@ -86,8 +86,13 @@ describe('IS_POINT_ON_LINE',() => { line.calculateNOfLineFunction() expect(()=>isPointOnLine(line,'k')).toThrowError('the type of point is not Point') }) - it('An error should be thrown when point2 is not of type Point', () => { + it('An error should be thrown when line is not of type Line', () => { const point = new Point({x:6,y:4}) expect(()=>isPointOnLine('k',point)).toThrowError('the type of line is not Line') }) + it('An error should be thrown when the slope is undefined', () => { + const line = new Line({point1:new Point({x:8,y:4}),point2:new Point({x:6,y:1})}) + const point = new Point({x:6,y:4}) + expect(() => isPointOnLine(line,point)).toThrowError('division by zero') + }) }) \ No newline at end of file