From 7fc6762eb31f59bd512853fe29d68471a3e93ec9 Mon Sep 17 00:00:00 2001 From: Artemis Git Integration Date: Wed, 10 Jun 2026 14:24:50 +0000 Subject: [PATCH 1/2] Batch update (2 files) --- app/src/main/java/control/Single.java | 7 ++++++- app/src/test/java/control/SingleTest.java | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/control/Single.java b/app/src/main/java/control/Single.java index 8fefbb8..6977cd9 100644 --- a/app/src/main/java/control/Single.java +++ b/app/src/main/java/control/Single.java @@ -42,9 +42,14 @@ public static int maxArray(int[] arr) { * This method calculates the sum of the first n natural numbers, modulo m. * * @param n The number of natural numbers to sum. - * @param m The modulus. + * @param m The non-zero modulus. + * @throws IllegalArgumentException if m is zero. */ public static int sumModulus(int n, int m) { + if (m == 0) { + throw new IllegalArgumentException("Modulus must be non-zero"); + } + Vector multiples = new Vector(); for (int i = 0; i < n; i++) { if (i % m == 0) { diff --git a/app/src/test/java/control/SingleTest.java b/app/src/test/java/control/SingleTest.java index 98f5395..976d8e8 100644 --- a/app/src/test/java/control/SingleTest.java +++ b/app/src/test/java/control/SingleTest.java @@ -1,6 +1,7 @@ package control; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import org.junit.jupiter.api.Test; @@ -33,5 +34,6 @@ public void testSumModulus() { assertEquals(20, Single.sumModulus(10, 2)); assertEquals(18, Single.sumModulus(10, 3)); assertEquals(12, Single.sumModulus(10, 4)); + assertThrows(IllegalArgumentException.class, () -> Single.sumModulus(10, 0)); } } \ No newline at end of file From c6f0bb4c06146c3574c798f59e03fb46a1526f8f Mon Sep 17 00:00:00 2001 From: Artemis Git Integration Date: Wed, 10 Jun 2026 14:27:55 +0000 Subject: [PATCH 2/2] Batch update (1 files) --- app/src/main/java/control/Single.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/control/Single.java b/app/src/main/java/control/Single.java index 6977cd9..2aa594d 100644 --- a/app/src/main/java/control/Single.java +++ b/app/src/main/java/control/Single.java @@ -46,6 +46,7 @@ public static int maxArray(int[] arr) { * @throws IllegalArgumentException if m is zero. */ public static int sumModulus(int n, int m) { + // Validate first so modulo by zero produces a clearer exception than % would. if (m == 0) { throw new IllegalArgumentException("Modulus must be non-zero"); }