diff --git a/src/main/java/com/thealgorithms/maths/Area.java b/src/main/java/com/thealgorithms/maths/Area.java index 84fc67159379..17411bb1d5a4 100644 --- a/src/main/java/com/thealgorithms/maths/Area.java +++ b/src/main/java/com/thealgorithms/maths/Area.java @@ -78,10 +78,10 @@ public static double surfaceAreaSphere(final double radius) { */ public static double surfaceAreaPyramid(final double sideLength, final double slantHeight) { if (sideLength <= 0) { - throw new IllegalArgumentException(""); + throw new IllegalArgumentException("Must be a positive sideLength"); } if (slantHeight <= 0) { - throw new IllegalArgumentException("slant height must be greater than 0"); + throw new IllegalArgumentException("Must be a positive slantHeight"); } double baseArea = sideLength * sideLength; double lateralSurfaceArea = 2 * sideLength * slantHeight; diff --git a/src/test/java/com/thealgorithms/maths/AreaTest.java b/src/test/java/com/thealgorithms/maths/AreaTest.java index 1c2fe53ff3f3..2cfba4399f65 100644 --- a/src/test/java/com/thealgorithms/maths/AreaTest.java +++ b/src/test/java/com/thealgorithms/maths/AreaTest.java @@ -21,6 +21,11 @@ void testSurfaceAreaCuboid() { assertEquals(214.0, Area.surfaceAreaCuboid(5, 6, 7)); } + @Test + void testSurfaceAreaPyramid() { + assertEquals(40.0, Area.surfaceAreaPyramid(4, 3)); + } + @Test void testSurfaceAreaSphere() { assertEquals(12.566370614359172, Area.surfaceAreaSphere(1)); @@ -81,6 +86,10 @@ void testAllIllegalInput() { -> assertThrows(IllegalArgumentException.class, () -> Area.surfaceAreaCuboid(1, 0, 2)), () -> assertThrows(IllegalArgumentException.class, () -> Area.surfaceAreaCuboid(1, 2, 0)), + () + -> assertThrows(IllegalArgumentException.class, () -> Area.surfaceAreaPyramid(0, 1)), + () + -> assertThrows(IllegalArgumentException.class, () -> Area.surfaceAreaPyramid(1, 0)), () -> assertThrows(IllegalArgumentException.class, () -> Area.surfaceAreaSphere(0)), ()