From 8819cfa4a8b5ffba7afde701fd9415862420aaa3 Mon Sep 17 00:00:00 2001
From: Martin Goik <goik@hdm-stuttgart.de>
Date: Thu, 16 Jan 2025 20:50:09 +0100
Subject: [PATCH] Allowing breakpoints

---
 .../hdm_stuttgart/mi/sd1/task1/D_SumTest.java | 43 +++++++------------
 .../mi/sd1/task2/ParcelTest.java              | 24 ++++-------
 .../hdm_stuttgart/mi/sd1/task1/D_SumTest.java | 43 +++++++------------
 .../mi/sd1/task2/ParcelTest.java              | 24 ++++-------
 4 files changed, 50 insertions(+), 84 deletions(-)

diff --git a/Klausuren/Sd1/2024summer/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/task1/D_SumTest.java b/Klausuren/Sd1/2024summer/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/task1/D_SumTest.java
index f87c62b0..364c356a 100644
--- a/Klausuren/Sd1/2024summer/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/task1/D_SumTest.java
+++ b/Klausuren/Sd1/2024summer/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/task1/D_SumTest.java
@@ -10,39 +10,28 @@ import org.junit.runners.MethodSorters;
 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
 public class D_SumTest extends ExaminationTestDefaults {
 
-    static private void assertByteSum(final int expected, final int i, final int j){
-        {
-            final String errorMessage = "expected = " + expected + ", a = " + i + " , b = " + j;
-            Assert.assertTrue(errorMessage + ": a outside range",
-                    Byte.MIN_VALUE <= i & i <= Byte.MAX_VALUE);
-            Assert.assertTrue(errorMessage + ": b outside range",
-                    Byte.MIN_VALUE <= j & j <= Byte.MAX_VALUE);
-            Assert.assertTrue(errorMessage + ": expected outside range",
-                    Byte.MIN_VALUE <= expected & expected <= Byte.MAX_VALUE);
-        }
-        {
-            String errorMessage = "Expected mitigatedSum(" + i + " , " + j + ") is " + expected;
-            Assert.assertEquals(errorMessage, expected, D_Sum.mitigatedSum((byte)i, (byte) j));
+    static private void assertByteSum(final byte expected, final byte i, byte j){
+        final byte actual = D_Sum.mitigatedSum(i, j);
+        if (expected != actual) {
+            final String errorMessage = "Expected " + expected + " == mitigatedSum(" + i + " , " + j + ") rather than »"
+                    + actual + "«. Wanna set a breakpoint for debugging?";
+            Assert.assertEquals(errorMessage, D_Sum.mitigatedSum((byte)i, (byte) j)); // Yet again for debugging
         }
     }
 
     @Marking(points = 6)
     @Test
     public void test() {
-        for (int i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++) {
-
-            final byte
-                    lower = (byte) Math.max(Byte.MIN_VALUE - i, Byte.MIN_VALUE),
-                    upper = (byte) Math.min(Byte.MAX_VALUE - i, Byte.MAX_VALUE);
-
-            for (int j = Byte.MIN_VALUE; j < lower; j++) {
-                assertByteSum(Byte.MIN_VALUE, i, j);
-            }
-            for (int j = lower; j <= upper; j++) {
-                assertByteSum(i + j, i, j);
-            }
-            for (int j = Byte.MAX_VALUE ; upper < j; j--) {
-                assertByteSum(Byte.MAX_VALUE, i, j);
+        for (byte i = Byte.MIN_VALUE; i < ++i; ) { // ... i < BYTE.MAX_VALUE; i++ loops endlessly due to byte overflow
+            for (byte j = Byte.MIN_VALUE; j < j++; ) {
+                final int sum = i + j;
+                if (sum < Byte.MIN_VALUE) {
+                    assertByteSum(Byte.MIN_VALUE, i, j);
+                } else if (sum > Byte.MAX_VALUE) {
+                    assertByteSum(Byte.MAX_VALUE, i, j);
+                } else {
+                    assertByteSum((byte) sum, i, j);
+                }
             }
         }
     }
diff --git a/Klausuren/Sd1/2024summer/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/task2/ParcelTest.java b/Klausuren/Sd1/2024summer/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/task2/ParcelTest.java
index 6f015625..5a900125 100644
--- a/Klausuren/Sd1/2024summer/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/task2/ParcelTest.java
+++ b/Klausuren/Sd1/2024summer/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/task2/ParcelTest.java
@@ -14,10 +14,6 @@ import static de.hdm_stuttgart.mi.sd1.task2.Parcel.*;
 
 public class ParcelTest extends ExaminationTestDefaults {
 
-  static public final String DEBUG_TEST_HINT =
-          "\n\nTest error: Wanna set a breakpoint having a debugging run?";
-
-
   public ParcelTest() {
     super(20000);
   }
@@ -95,7 +91,6 @@ public class ParcelTest extends ExaminationTestDefaults {
 
   private void permuteDimensions(final Parcel expectedCategory,
                                  final int length1, final int length2, final int length3, final int weight) {
-
     assertCategory(expectedCategory, length1, length2, length3, weight);
     assertCategory(expectedCategory, length1, length3, length2, weight);
     assertCategory(expectedCategory, length2, length1, length3, weight);
@@ -104,17 +99,16 @@ public class ParcelTest extends ExaminationTestDefaults {
     assertCategory(expectedCategory, length3, length2, length1, weight);
   }
 
-  private void assertCategory(final Parcel expectedCategory,
+  private void assertCategory(final Parcel expected,
                               final int length1, final int length2, final int length3, final int weight) {
-    try {
-      Assert.assertEquals(expectedCategory, cheapestCategory(length1, length2, length3, weight));
-    } catch (final AssertionError e) {
-      final String message = "Expected " + expectedCategory + " for (" + length1 + "cm x " + length2 + "cm x " +
-              length3 + "cm) and weight " + weight + "g";
-
-      System.out.println(DEBUG_TEST_HINT);
-      Assert.assertEquals(message, expectedCategory,
-              cheapestCategory(length1, length2, length3, weight));
+
+    final Parcel actual = cheapestCategory(length1, length2, length3, weight);
+
+    if (expected != actual) {
+      final String message = "Expected »" + expected + "« rather than »" + actual + "« for " +
+              length1 + "cm x " + length2 + "cm x " + length3 +
+              "cm and weight " + weight + "g.  Wanna set a breakpoint for debugging?";
+      Assert.assertEquals(message, cheapestCategory(length1, length2, length3, weight));
     }
   }
 }
\ No newline at end of file
diff --git a/Klausuren/Sd1/2024summer/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/task1/D_SumTest.java b/Klausuren/Sd1/2024summer/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/task1/D_SumTest.java
index f87c62b0..269a0119 100644
--- a/Klausuren/Sd1/2024summer/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/task1/D_SumTest.java
+++ b/Klausuren/Sd1/2024summer/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/task1/D_SumTest.java
@@ -10,39 +10,28 @@ import org.junit.runners.MethodSorters;
 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
 public class D_SumTest extends ExaminationTestDefaults {
 
-    static private void assertByteSum(final int expected, final int i, final int j){
-        {
-            final String errorMessage = "expected = " + expected + ", a = " + i + " , b = " + j;
-            Assert.assertTrue(errorMessage + ": a outside range",
-                    Byte.MIN_VALUE <= i & i <= Byte.MAX_VALUE);
-            Assert.assertTrue(errorMessage + ": b outside range",
-                    Byte.MIN_VALUE <= j & j <= Byte.MAX_VALUE);
-            Assert.assertTrue(errorMessage + ": expected outside range",
-                    Byte.MIN_VALUE <= expected & expected <= Byte.MAX_VALUE);
-        }
-        {
-            String errorMessage = "Expected mitigatedSum(" + i + " , " + j + ") is " + expected;
-            Assert.assertEquals(errorMessage, expected, D_Sum.mitigatedSum((byte)i, (byte) j));
+    static private void assertByteSum(final byte expected, final byte i, byte j){
+        final byte actual = D_Sum.mitigatedSum(i, j);
+        if (expected != actual) {
+            final String errorMessage = "Expected " + expected + " == mitigatedSum(" + i + " , " + j + ") rather than »"
+                    + actual + "«. Wanna set a breakpoint for debugging?";
+            Assert.assertEquals(errorMessage, D_Sum.mitigatedSum((byte)i, (byte) j)); // Yet again for debugging
         }
     }
 
     @Marking(points = 6)
     @Test
     public void test() {
-        for (int i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++) {
-
-            final byte
-                    lower = (byte) Math.max(Byte.MIN_VALUE - i, Byte.MIN_VALUE),
-                    upper = (byte) Math.min(Byte.MAX_VALUE - i, Byte.MAX_VALUE);
-
-            for (int j = Byte.MIN_VALUE; j < lower; j++) {
-                assertByteSum(Byte.MIN_VALUE, i, j);
-            }
-            for (int j = lower; j <= upper; j++) {
-                assertByteSum(i + j, i, j);
-            }
-            for (int j = Byte.MAX_VALUE ; upper < j; j--) {
-                assertByteSum(Byte.MAX_VALUE, i, j);
+        for (byte i = Byte.MIN_VALUE; i < ++i; ) {
+            for (byte j = Byte.MIN_VALUE; j < j++; ) {
+                final int sum = i + j;
+                if (sum < Byte.MIN_VALUE) {
+                    assertByteSum(Byte.MIN_VALUE, i, j);
+                } else if (sum > Byte.MAX_VALUE) {
+                    assertByteSum(Byte.MAX_VALUE, i, j);
+                } else {
+                    assertByteSum((byte) sum, i, j);
+                }
             }
         }
     }
diff --git a/Klausuren/Sd1/2024summer/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/task2/ParcelTest.java b/Klausuren/Sd1/2024summer/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/task2/ParcelTest.java
index 6f015625..5a900125 100644
--- a/Klausuren/Sd1/2024summer/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/task2/ParcelTest.java
+++ b/Klausuren/Sd1/2024summer/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/task2/ParcelTest.java
@@ -14,10 +14,6 @@ import static de.hdm_stuttgart.mi.sd1.task2.Parcel.*;
 
 public class ParcelTest extends ExaminationTestDefaults {
 
-  static public final String DEBUG_TEST_HINT =
-          "\n\nTest error: Wanna set a breakpoint having a debugging run?";
-
-
   public ParcelTest() {
     super(20000);
   }
@@ -95,7 +91,6 @@ public class ParcelTest extends ExaminationTestDefaults {
 
   private void permuteDimensions(final Parcel expectedCategory,
                                  final int length1, final int length2, final int length3, final int weight) {
-
     assertCategory(expectedCategory, length1, length2, length3, weight);
     assertCategory(expectedCategory, length1, length3, length2, weight);
     assertCategory(expectedCategory, length2, length1, length3, weight);
@@ -104,17 +99,16 @@ public class ParcelTest extends ExaminationTestDefaults {
     assertCategory(expectedCategory, length3, length2, length1, weight);
   }
 
-  private void assertCategory(final Parcel expectedCategory,
+  private void assertCategory(final Parcel expected,
                               final int length1, final int length2, final int length3, final int weight) {
-    try {
-      Assert.assertEquals(expectedCategory, cheapestCategory(length1, length2, length3, weight));
-    } catch (final AssertionError e) {
-      final String message = "Expected " + expectedCategory + " for (" + length1 + "cm x " + length2 + "cm x " +
-              length3 + "cm) and weight " + weight + "g";
-
-      System.out.println(DEBUG_TEST_HINT);
-      Assert.assertEquals(message, expectedCategory,
-              cheapestCategory(length1, length2, length3, weight));
+
+    final Parcel actual = cheapestCategory(length1, length2, length3, weight);
+
+    if (expected != actual) {
+      final String message = "Expected »" + expected + "« rather than »" + actual + "« for " +
+              length1 + "cm x " + length2 + "cm x " + length3 +
+              "cm and weight " + weight + "g.  Wanna set a breakpoint for debugging?";
+      Assert.assertEquals(message, cheapestCategory(length1, length2, length3, weight));
     }
   }
 }
\ No newline at end of file
-- 
GitLab