mirror of
https://github.com/TheAlgorithms/Java.git
synced 2026-03-13 08:40:43 +08:00
* Added volume of a torus Added function calculation the volume of a torus according to the formula: V = 2 * pi^2 * R * r^2 where R is the major radius and r is the minor radius of the torus. * Added test for torus volume
46 lines
1.2 KiB
Java
46 lines
1.2 KiB
Java
package com.thealgorithms.maths;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
public class VolumeTest {
|
|
|
|
@Test
|
|
public void volume() {
|
|
|
|
/* test cube */
|
|
assertEquals(343.0, Volume.volumeCube(7));
|
|
|
|
/* test cuboid */
|
|
assertEquals(70.0, Volume.volumeCuboid(2, 5, 7));
|
|
|
|
/* test sphere */
|
|
assertEquals(1436.7550402417319, Volume.volumeSphere(7));
|
|
|
|
/* test cylinder */
|
|
assertEquals(197.92033717615698, Volume.volumeCylinder(3, 7));
|
|
|
|
/* test hemisphere */
|
|
assertEquals(718.3775201208659, Volume.volumeHemisphere(7));
|
|
|
|
/* test cone */
|
|
assertEquals(65.97344572538566, Volume.volumeCone(3, 7));
|
|
|
|
/* test prism */
|
|
assertEquals(20.0, Volume.volumePrism(10, 2));
|
|
|
|
/* test pyramid */
|
|
assertEquals(10.0, Volume.volumePyramid(10, 3));
|
|
|
|
/* test frustum */
|
|
assertEquals(359.188760060433, Volume.volumeFrustumOfCone(3, 5, 7));
|
|
|
|
/* test pyramid frustum */
|
|
assertEquals(140.0, Volume.volumeFrustumOfPyramid(6, 24, 10));
|
|
|
|
/* test torus */
|
|
assertEquals(39.47841760435743, Volume.volumeTorus(2, 1));
|
|
}
|
|
}
|