Skip to content

test for geometry calculation#25

Open
shoshym wants to merge 3 commits into
gemtechd:mainfrom
shoshym:main
Open

test for geometry calculation#25
shoshym wants to merge 3 commits into
gemtechd:mainfrom
shoshym:main

Conversation

@shoshym

@shoshym shoshym commented Jul 23, 2024

Copy link
Copy Markdown

No description provided.

@shoshym

shoshym commented Jul 23, 2024

Copy link
Copy Markdown
Author

I was not able to cover all the lines even though I did tests that went over those lines.

@gemtechd gemtechd left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have to change much more code in themodules
and use good mocks in the tests

Comment thread modules/ecs6-class/line.js Outdated
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;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have to add more checks in the function
what happens when point is an array, what happens when n is a string etc...

Comment thread modules/ecs6-class/line.js
Comment thread modules/geometry-calculation.js
Comment thread package.json
"test:coverage":"npm run test -- --coverage"
},
"dependencies": {
"jest": "^29.7.0"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jest cannot be in the dependency section

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why didn't you change the code?

Comment thread tests/modules/ecs6-class/line.test.js
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()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here you don't call this function, you test a different function

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing the errors
and the coverage for this module is under 70

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't call functions inside the tests beside the function that you test
You have to see that other functions will be getting called inside the tested function

use mocks for a function that is being called inside an other one

@shoshym

shoshym commented Jul 24, 2024

Copy link
Copy Markdown
Author

I want to move on to the next task.

@shoshym shoshym closed this Jul 24, 2024
@shoshym shoshym reopened this Jul 24, 2024

@gemtechd gemtechd left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the comments

Comment thread modules/ecs6-class/line.js Outdated
this.point1 = point1;
this.point2 = point2;
this.slope = slope;
this.n = n;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if n is not undefined but is also not a number
if slope is not undefined but also not a number???

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i fixed it .

Comment thread modules/geometry-calculation.js
Comment thread modules/geometry-calculation.js Outdated
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) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who said that the line's slope is already calculated?

Comment thread package.json
"test:coverage":"npm run test -- --coverage"
},
"dependencies": {
"jest": "^29.7.0"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why didn't you change the code?

Comment thread package.json

"license": "ISC",
"devDependencies": {
"nyc": "^17.0.0"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this module?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I installed it when I didn't manage with the tests, but in the end I managed.

Comment thread package.json

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are the mocks??

@gemtechd

Copy link
Copy Markdown
Owner

Did you change code?
push up that I will see the changes

@gemtechd gemtechd added the bb label Jul 28, 2024

@gemtechd gemtechd left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Continue working on this task

else{
throw new Error('the type of point2 is not Point')}
else
throw new Error('the type of point2 is not Point')

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throw directly an error, like this, you don't mix up checks and codes

// })

// mockCalculatSlope.mockImplementation()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the remarks and console before pushing the commit

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()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't execute a different function in a unittest

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()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this line from the test

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are the mocks in the tests?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants