Skip to content

Commit

Permalink
algorithm class: circle (TheAlgorithms#1252)
Browse files Browse the repository at this point in the history
  • Loading branch information
Japoncio3k authored Oct 31, 2022
1 parent f1ef64c commit 7256e53
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Geometry/Circle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* This class represents a circle and can calculate it's perimeter and area
* https://en.wikipedia.org/wiki/Circle
* @constructor
* @param {number} radius - The radius of the circule.
*/
export default class Circle {
constructor (radius) {
this.radius = radius
}

perimeter = () => {
return this.radius * 2 * Math.PI
}

area = () => {
return Math.pow(this.radius, 2) * Math.PI
}
}
11 changes: 11 additions & 0 deletions Geometry/Test/Circle.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Circle from '../Circle'

const circle = new Circle(3)

test('The area of a circle with radius equal to 3', () => {
expect(parseFloat(circle.area().toFixed(2))).toEqual(28.27)
})

test('The perimeter of a circle with radius equal to 3', () => {
expect(parseFloat(circle.perimeter().toFixed(2))).toEqual(18.85)
})

0 comments on commit 7256e53

Please sign in to comment.