Skip to content

Commit

Permalink
Added a square class to the Geometry folder similar to the circle
Browse files Browse the repository at this point in the history
  • Loading branch information
Yohannee13 committed Sep 17, 2024
1 parent 9010481 commit 310a652
Show file tree
Hide file tree
Showing 5 changed files with 700 additions and 53 deletions.
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

0 comments on commit 310a652

Please sign in to comment.