Skip to content

Commit fa7f6bc

Browse files
author
Anurag
committed
Issue TheAlgorithms#5479 resolved, Algorithm Frustum of Cone and tested it
1 parent 1e8abf1 commit fa7f6bc

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/main/java/com/thealgorithms/maths/Volume.java

+5
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,9 @@ public static double volumePrism(double baseArea, double height) {
9090
public static double volumePyramid(double baseArea, double height) {
9191
return (baseArea * height) / 3;
9292
}
93+
94+
95+
public static double volumeFrustumOfCone(double r1, double r2, double height){
96+
return (Math.PI * height / 3) * (r1 * r1 + r2 * r2 + r1 * r2);
97+
}
9398
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.thealgorithms.maths;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.assertTrue;
6+
7+
public class VolumeTest {
8+
9+
@Test
10+
public void volume(){
11+
12+
// test cube
13+
assertTrue(Volume.volumeCube(7) == 343.0);
14+
assertTrue(Volume.volumeCuboid(2, 5, 7) == 70.0);
15+
assertTrue(Volume.volumeSphere(7) == 1436.7550402417319);
16+
assertTrue(Volume.volumeCylinder(3, 7) == 197.92033717615698);
17+
assertTrue(Volume.volumeHemisphere(7) == 718.3775201208659);
18+
assertTrue(Volume.volumeCone(3, 7) == 65.97344572538566);
19+
assertTrue(Volume.volumePrism(10, 2) == 20.0);
20+
assertTrue(Volume.volumePyramid(10, 3) == 10.0);
21+
assertTrue(Volume.volumeFrustumOfCone(3, 5, 7) == 359.188760060433);
22+
23+
24+
25+
}
26+
27+
}

0 commit comments

Comments
 (0)