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

Commitf1ef64c

Browse files
authored
algorithm class: cone (#1253)
1 parentc5101e3 commitf1ef64c

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

‎Geometry/Cone.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* This class represents a circular cone and can calculate its volume and surface area
3+
* https://en.wikipedia.org/wiki/Cone
4+
*@constructor
5+
*@param {number} baseRadius - The radius of the base of the cone.
6+
*@param {number} height - The height of the cone
7+
*/
8+
exportdefaultclassCone{
9+
constructor(baseRadius,height){
10+
this.baseRadius=baseRadius
11+
this.height=height
12+
}
13+
14+
baseArea=()=>{
15+
returnMath.pow(this.baseRadius,2)*Math.PI
16+
}
17+
18+
volume=()=>{
19+
returnthis.baseArea()*this.height*1/3
20+
}
21+
22+
surfaceArea=()=>{
23+
returnthis.baseArea()+Math.PI*this.baseRadius*Math.sqrt(Math.pow(this.baseRadius,2)+Math.pow(this.height,2))
24+
}
25+
}

‎Geometry/Test/Cone.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
importConefrom'../Cone'
2+
3+
constcone=newCone(3,5)
4+
5+
test('The Volume of a cone with base radius equal to 3 and height equal to 5',()=>{
6+
expect(parseFloat(cone.volume().toFixed(2))).toEqual(47.12)
7+
})
8+
9+
test('The Surface Area of a cone with base radius equal to 3 and height equal to 5',()=>{
10+
expect(parseFloat(cone.surfaceArea().toFixed(2))).toEqual(83.23)
11+
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp