Skip to content

Commit 310a652

Browse files
committed
Added a square class to the Geometry folder similar to the circle
1 parent 9010481 commit 310a652

File tree

5 files changed

+700
-53
lines changed

5 files changed

+700
-53
lines changed

Geometry/Circle.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* This class represents a circle and can calculate it's perimeter and area
2+
* This class represents a circle and can calculate its perimeter and area
33
* https://en.wikipedia.org/wiki/Circle
44
* @constructor
55
* @param {number} radius - The radius of the circle.

Geometry/Square.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* This class represent a square and can calculate its perimeter and its area
3+
* https://fr.wikipedia.org/wiki/Square
4+
* @constructor
5+
* @param {number} side - the length of a side of the square
6+
*/
7+
export default class Square {
8+
constructor(side) {
9+
this.side = side
10+
}
11+
12+
perimeter = () => {
13+
return 4 * this.side
14+
}
15+
16+
area = () => {
17+
return Math.pow(this.side, 2)
18+
}
19+
}

Geometry/Test/Square.test.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { expect } from 'vitest'
2+
import Square from '../Square'
3+
4+
const square = new Square(4)
5+
6+
// Using parseFloat() in case the side is a float
7+
test('The perimeter of a square with a side of length equal to 4', () => {
8+
expect(parseFloat(square.perimeter().toFixed(2))).toEqual(16.0)
9+
})
10+
11+
test('The area of a square with a side of length 4', () => {
12+
expect(parseFloat(square.area().toFixed(2))).toEqual(16.0)
13+
})

Geometry/Test/node_modules/.vitest/results.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)