From 26c88f684ea76f2f42324e435b1c4a3a271dfaa7 Mon Sep 17 00:00:00 2001 From: record-bot Date: Wed, 22 Apr 2026 12:27:53 -0700 Subject: [PATCH 1/2] record/coverage: intro failure --- src/main/java/com/phalanx/calc/MathOps.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/com/phalanx/calc/MathOps.java b/src/main/java/com/phalanx/calc/MathOps.java index 16d072d..1f8909f 100644 --- a/src/main/java/com/phalanx/calc/MathOps.java +++ b/src/main/java/com/phalanx/calc/MathOps.java @@ -29,4 +29,22 @@ public static double divide(double a, double b) { } return a / b; } + + public static double percentage(double part, double whole) { + if (whole == 0) { + throw new ArithmeticException("cannot compute percentage of zero"); + } + return (part / whole) * 100; + } + + public static double average(double[] values) { + if (values.length == 0) { + throw new IllegalArgumentException("cannot average an empty list"); + } + double sum = 0; + for (double v : values) { + sum += v; + } + return sum / values.length; + } } From 2b010d469786f5e4ff15f361c895a5c8610899ba Mon Sep 17 00:00:00 2001 From: Phalanx Date: Wed, 22 Apr 2026 19:31:42 +0000 Subject: [PATCH 2/2] Add tests for new MathOps coverage paths The PR added percentage() and average() to MathOps, but the existing JUnit suite only exercised add/subtract/multiply/divide. JaCoCo failed mvn -B verify because bundle line coverage fell below the 0.80 gate. Add targeted tests for the new methods, including both happy paths and exception paths, so the original coverage check passes under the same verification command. --- .../java/com/phalanx/calc/MathOpsTest.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/test/java/com/phalanx/calc/MathOpsTest.java b/src/test/java/com/phalanx/calc/MathOpsTest.java index 7b7c7c1..1e48267 100644 --- a/src/test/java/com/phalanx/calc/MathOpsTest.java +++ b/src/test/java/com/phalanx/calc/MathOpsTest.java @@ -61,4 +61,48 @@ void divideFractions() { void divideByZeroThrows() { assertThrows(ArithmeticException.class, () -> MathOps.divide(1, 0)); } + + // --- percentage --- + + @Test + void percentageHalf() { + assertEquals(50.0, MathOps.percentage(1, 2)); + } + + @Test + void percentageHundred() { + assertEquals(100.0, MathOps.percentage(5, 5)); + } + + @Test + void percentageSmall() { + assertEquals(25.0, MathOps.percentage(1, 4)); + } + + @Test + void percentageOfZeroThrows() { + assertThrows(ArithmeticException.class, () -> MathOps.percentage(5, 0)); + } + + // --- average --- + + @Test + void averageSingleValue() { + assertEquals(7.0, MathOps.average(new double[]{7})); + } + + @Test + void averageMultipleValues() { + assertEquals(3.0, MathOps.average(new double[]{1, 2, 3, 4, 5})); + } + + @Test + void averageWithNegatives() { + assertEquals(0.0, MathOps.average(new double[]{-1, 0, 1})); + } + + @Test + void averageEmptyThrows() { + assertThrows(IllegalArgumentException.class, () -> MathOps.average(new double[]{})); + } }