Skip to content

Commit f65bda3

Browse files
committed
Improve pyramid validation messages and add tests
1 parent 2319794 commit f65bda3

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

‎src/main/java/com/thealgorithms/maths/Area.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ public static double surfaceAreaSphere(final double radius) {
7878
*/
7979
public static double surfaceAreaPyramid(final double sideLength, final double slantHeight) {
8080
if (sideLength <= 0) {
81-
throw new IllegalArgumentException("");
81+
throw new IllegalArgumentException("Must be a positive sideLength");
8282
}
8383
if (slantHeight <= 0) {
84-
throw new IllegalArgumentException("slant height must be greater than 0");
84+
throw new IllegalArgumentException("Must be a positive slantHeight");
8585
}
8686
double baseArea = sideLength * sideLength;
8787
double lateralSurfaceArea = 2 * sideLength * slantHeight;

‎src/test/java/com/thealgorithms/maths/AreaTest.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ void testSurfaceAreaCuboid() {
2121
assertEquals(214.0, Area.surfaceAreaCuboid(5, 6, 7));
2222
}
2323

24+
@Test
25+
void testSurfaceAreaPyramid() {
26+
assertEquals(40.0, Area.surfaceAreaPyramid(4, 3));
27+
}
28+
2429
@Test
2530
void testSurfaceAreaSphere() {
2631
assertEquals(12.566370614359172, Area.surfaceAreaSphere(1));
@@ -81,6 +86,10 @@ void testAllIllegalInput() {
8186
-> assertThrows(IllegalArgumentException.class, () -> Area.surfaceAreaCuboid(1, 0, 2)),
8287
()
8388
-> assertThrows(IllegalArgumentException.class, () -> Area.surfaceAreaCuboid(1, 2, 0)),
89+
()
90+
-> assertThrows(IllegalArgumentException.class, () -> Area.surfaceAreaPyramid(0, 1)),
91+
()
92+
-> assertThrows(IllegalArgumentException.class, () -> Area.surfaceAreaPyramid(1, 0)),
8493
()
8594
-> assertThrows(IllegalArgumentException.class, () -> Area.surfaceAreaSphere(0)),
8695
()

0 commit comments

Comments
 (0)