File tree 2 files changed +32
-0
lines changed
2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * This class represents a rectangle and can calculate its perimeter and area
3
+ * https://en.wikipedia.org/wiki/Rectangle
4
+ * @constructor
5
+ * @param {number } length - The length of the rectangle.
6
+ * @param {number } breadth - The breadth of the rectangle.
7
+ */
8
+ export default class Rectangle {
9
+ constructor ( length , breadth ) {
10
+ this . length = length
11
+ this . breadth = breadth
12
+ }
13
+
14
+ perimeter = ( ) => {
15
+ return 2 * ( this . length + this . breadth )
16
+ }
17
+
18
+ area = ( ) => {
19
+ return this . length * this . breadth
20
+ }
21
+ }
Original file line number Diff line number Diff line change
1
+ import Rectangle from '../Rectangle'
2
+
3
+ const rectangle = new Rectangle ( 3 , 4 )
4
+
5
+ test ( 'The perimeter of rectangle with length equal to 3 and breadth equal to 4' , ( ) => {
6
+ expect ( parseFloat ( rectangle . perimeter ( ) . toFixed ( 2 ) ) ) . toEqual ( 14.0 )
7
+ } )
8
+
9
+ test ( 'The area of rectangle with length equal to 3 and breadth equal to 4' , ( ) => {
10
+ expect ( parseFloat ( rectangle . area ( ) . toFixed ( 2 ) ) ) . toEqual ( 12.0 )
11
+ } )
You can’t perform that action at this time.
0 commit comments