Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7256e53

Browse files
authored
algorithm class: circle (#1252)
1 parentf1ef64c commit7256e53

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

‎Geometry/Circle.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
exportdefaultclassCircle{
8+
constructor(radius){
9+
this.radius=radius
10+
}
11+
12+
perimeter=()=>{
13+
returnthis.radius*2*Math.PI
14+
}
15+
16+
area=()=>{
17+
returnMath.pow(this.radius,2)*Math.PI
18+
}
19+
}

‎Geometry/Test/Circle.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
importCirclefrom'../Circle'
2+
3+
constcircle=newCircle(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+
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp