diff --git a/Geometry/Circle.js b/Geometry/Circle.js new file mode 100644 index 0000000000..4b4f8e3b9a --- /dev/null +++ b/Geometry/Circle.js @@ -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 + } +} diff --git a/Geometry/Test/Circle.test.js b/Geometry/Test/Circle.test.js new file mode 100644 index 0000000000..b2332df43d --- /dev/null +++ b/Geometry/Test/Circle.test.js @@ -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) +})