Skip to content

algorithm class: circle #1252

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

Merged
merged 4 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
18 changes: 18 additions & 0 deletions Geometry/Circle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* This class represents a circle and can calculate it's perimeter and area
* @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
}
}
13 changes: 13 additions & 0 deletions Geometry/Test/Circle.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Circle from '../Circle'

const circle = new Circle(3)

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

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