File tree 2 files changed +30
-0
lines changed
2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change
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
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
+ } )
You can’t perform that action at this time.
0 commit comments