Skip to content

Adding a square class #1687

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Geometry/Circle.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* This class represents a circle and can calculate it's perimeter and area
* This class represents a circle and can calculate its perimeter and area
* https://en.wikipedia.org/wiki/Circle
* @constructor
* @param {number} radius - The radius of the circle.
Expand Down
19 changes: 19 additions & 0 deletions Geometry/Square.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* This class represent a square and can calculate its perimeter and its area
* https://fr.wikipedia.org/wiki/Square
* @constructor
* @param {number} side - the length of a side of the square
*/
export default class Square {
constructor(side) {
this.side = side
}

perimeter = () => {
return 4 * this.side
}

area = () => {
return Math.pow(this.side, 2)
}
}
13 changes: 13 additions & 0 deletions Geometry/Test/Square.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { expect } from 'vitest'
import Square from '../Square'

const square = new Square(4)

// Using parseFloat() in case the side is a float
test('The perimeter of a square with a side of length equal to 4', () => {
expect(parseFloat(square.perimeter().toFixed(2))).toEqual(16.0)
})

test('The area of a square with a side of length 4', () => {
expect(parseFloat(square.area().toFixed(2))).toEqual(16.0)
})
1 change: 1 addition & 0 deletions Geometry/Test/node_modules/.vitest/results.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading