-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a square class to the Geometry folder similar to the circle
- Loading branch information
1 parent
9010481
commit 310a652
Showing
5 changed files
with
700 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.