| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f1ef64c commit 7256e53
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,19 @@ | |||
| 1 | + /** | ||
| 2 | + * This class represents a circle and can calculate it's perimeter and area | ||
| 3 | + * https://en.wikipedia.org/wiki/Circle | ||
| 4 | + * @constructor | ||
| 5 | + * @param {number} radius - The radius of the circule. | ||
| 6 | + */ | ||
| 7 | + export default class Circle { | ||
| 8 | + constructor (radius) { | ||
| 9 | + this.radius = radius | ||
| 10 | + } | ||
| 11 | + | ||
| 12 | + perimeter = () => { | ||
| 13 | + return this.radius * 2 * Math.PI | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + area = () => { | ||
| 17 | + return Math.pow(this.radius, 2) * Math.PI | ||
| 18 | + } | ||
| 19 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,11 @@ | |||
| 1 | + import Circle from '../Circle' | ||
| 2 | + | ||
| 3 | + const circle = new Circle(3) | ||
| 4 | + | ||
| 5 | + test('The area of a circle with radius equal to 3', () => { | ||
| 6 | + expect(parseFloat(circle.area().toFixed(2))).toEqual(28.27) | ||
| 7 | + }) | ||
| 8 | + | ||
| 9 | + test('The perimeter of a circle with radius equal to 3', () => { | ||
| 10 | + expect(parseFloat(circle.perimeter().toFixed(2))).toEqual(18.85) | ||
| 11 | + }) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments