From 8d0bc7aafced3238453f73bd35b59e568e63c679 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 25 May 2026 18:15:33 +0000 Subject: [PATCH 1/4] Add degenerate calibration guards to Calibration transform - Add checks in `Calibration` constructor for `scale == 0` or non-finite inputs - Throw `IllegalArgumentException` on degenerate cases - Add tests in `CalibrationTest` to verify degenerate case behavior Co-authored-by: Unluckyathecking <111193970+Unluckyathecking@users.noreply.github.com> --- .../tracker/calibration/Calibration.java | 12 ++++++++++ .../tracker/calibration/CalibrationTest.java | 22 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/main/java/org/opensourcephysics/cabrillo/tracker/calibration/Calibration.java b/src/main/java/org/opensourcephysics/cabrillo/tracker/calibration/Calibration.java index bae5177a..ea98fe9c 100644 --- a/src/main/java/org/opensourcephysics/cabrillo/tracker/calibration/Calibration.java +++ b/src/main/java/org/opensourcephysics/cabrillo/tracker/calibration/Calibration.java @@ -24,6 +24,18 @@ public Calibration(double scale, double originX, double originY) { } public Calibration(double scale, double originX, double originY, double angle) { + if (!Double.isFinite(scale) || scale == 0.0) { + throw new IllegalArgumentException("Invalid scale: " + scale); + } + if (!Double.isFinite(originX)) { + throw new IllegalArgumentException("Invalid originX: " + originX); + } + if (!Double.isFinite(originY)) { + throw new IllegalArgumentException("Invalid originY: " + originY); + } + if (!Double.isFinite(angle)) { + throw new IllegalArgumentException("Invalid angle: " + angle); + } this.scale = scale; this.originX = originX; this.originY = originY; diff --git a/src/test/java/org/opensourcephysics/cabrillo/tracker/calibration/CalibrationTest.java b/src/test/java/org/opensourcephysics/cabrillo/tracker/calibration/CalibrationTest.java index 21e75f84..d5d985bf 100644 --- a/src/test/java/org/opensourcephysics/cabrillo/tracker/calibration/CalibrationTest.java +++ b/src/test/java/org/opensourcephysics/cabrillo/tracker/calibration/CalibrationTest.java @@ -82,4 +82,26 @@ public void testRotatedRoundTrip() { assertEquals(412.5, p.x(), 1e-9); assertEquals(173.25, p.y(), 1e-9); } + + +// add tests for invalid cases + + @Test + public void testDegenerateScale() { + assertThrows(IllegalArgumentException.class, () -> new Calibration(0.0, 0, 0, 0)); + assertThrows(IllegalArgumentException.class, () -> new Calibration(Double.NaN, 0, 0, 0)); + assertThrows(IllegalArgumentException.class, () -> new Calibration(Double.POSITIVE_INFINITY, 0, 0, 0)); + } + + @Test + public void testDegenerateOrigin() { + assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, Double.NaN, 0, 0)); + assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, Double.NaN, 0)); + assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, Double.POSITIVE_INFINITY, 0, 0)); + } + + @Test + public void testDegenerateAngle() { + assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, 0, Double.NaN)); + } } From 8ef2103722c742459f75c1f8a4d2385d593229fe Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 25 May 2026 18:21:34 +0000 Subject: [PATCH 2/4] Add degenerate calibration guards to Calibration transform - Add checks in `Calibration` constructor for `scale == 0` or non-finite inputs - Throw `IllegalArgumentException` on degenerate cases - Add tests in `CalibrationTest` to verify degenerate case behavior Co-authored-by: Unluckyathecking <111193970+Unluckyathecking@users.noreply.github.com> --- fix.patch | 34 ++++++++++++++ .../tracker/calibration/CalibrationTest.java | 8 +++- update_tests.py | 47 +++++++++++++++++++ 3 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 fix.patch create mode 100644 update_tests.py diff --git a/fix.patch b/fix.patch new file mode 100644 index 00000000..2f93f100 --- /dev/null +++ b/fix.patch @@ -0,0 +1,34 @@ +--- src/test/java/org/opensourcephysics/cabrillo/tracker/calibration/CalibrationTest.java ++++ src/test/java/org/opensourcephysics/cabrillo/tracker/calibration/CalibrationTest.java +@@ -82,21 +82,24 @@ + assertEquals(173.25, p.y(), 1e-9); + } + +- +-// add tests for invalid cases +- + @Test + public void testDegenerateScale() { + assertThrows(IllegalArgumentException.class, () -> new Calibration(0.0, 0, 0, 0)); + assertThrows(IllegalArgumentException.class, () -> new Calibration(Double.NaN, 0, 0, 0)); + assertThrows(IllegalArgumentException.class, () -> new Calibration(Double.POSITIVE_INFINITY, 0, 0, 0)); ++ assertThrows(IllegalArgumentException.class, () -> new Calibration(Double.NEGATIVE_INFINITY, 0, 0, 0)); + } + + @Test + public void testDegenerateOrigin() { + assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, Double.NaN, 0, 0)); + assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, Double.NaN, 0)); + assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, Double.POSITIVE_INFINITY, 0, 0)); ++ assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, Double.NEGATIVE_INFINITY, 0, 0)); ++ assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, Double.POSITIVE_INFINITY, 0)); ++ assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, Double.NEGATIVE_INFINITY, 0)); + } + + @Test + public void testDegenerateAngle() { + assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, 0, Double.NaN)); ++ assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, 0, Double.POSITIVE_INFINITY)); ++ assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, 0, Double.NEGATIVE_INFINITY)); + } + } diff --git a/src/test/java/org/opensourcephysics/cabrillo/tracker/calibration/CalibrationTest.java b/src/test/java/org/opensourcephysics/cabrillo/tracker/calibration/CalibrationTest.java index d5d985bf..382c34f8 100644 --- a/src/test/java/org/opensourcephysics/cabrillo/tracker/calibration/CalibrationTest.java +++ b/src/test/java/org/opensourcephysics/cabrillo/tracker/calibration/CalibrationTest.java @@ -84,13 +84,14 @@ public void testRotatedRoundTrip() { } -// add tests for invalid cases + @Test public void testDegenerateScale() { assertThrows(IllegalArgumentException.class, () -> new Calibration(0.0, 0, 0, 0)); assertThrows(IllegalArgumentException.class, () -> new Calibration(Double.NaN, 0, 0, 0)); assertThrows(IllegalArgumentException.class, () -> new Calibration(Double.POSITIVE_INFINITY, 0, 0, 0)); + assertThrows(IllegalArgumentException.class, () -> new Calibration(Double.NEGATIVE_INFINITY, 0, 0, 0)); } @Test @@ -98,10 +99,15 @@ public void testDegenerateOrigin() { assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, Double.NaN, 0, 0)); assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, Double.NaN, 0)); assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, Double.POSITIVE_INFINITY, 0, 0)); + assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, Double.NEGATIVE_INFINITY, 0, 0)); + assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, Double.POSITIVE_INFINITY, 0)); + assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, Double.NEGATIVE_INFINITY, 0)); } @Test public void testDegenerateAngle() { assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, 0, Double.NaN)); + assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, 0, Double.POSITIVE_INFINITY)); + assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, 0, Double.NEGATIVE_INFINITY)); } } diff --git a/update_tests.py b/update_tests.py new file mode 100644 index 00000000..e8f81a27 --- /dev/null +++ b/update_tests.py @@ -0,0 +1,47 @@ +import sys + +file_path = "src/test/java/org/opensourcephysics/cabrillo/tracker/calibration/CalibrationTest.java" + +with open(file_path, "r") as f: + content = f.read() + +content = content.replace(""" @Test + public void testDegenerateScale() { + assertThrows(IllegalArgumentException.class, () -> new Calibration(0.0, 0, 0, 0)); + assertThrows(IllegalArgumentException.class, () -> new Calibration(Double.NaN, 0, 0, 0)); + assertThrows(IllegalArgumentException.class, () -> new Calibration(Double.POSITIVE_INFINITY, 0, 0, 0)); + }""", """ @Test + public void testDegenerateScale() { + assertThrows(IllegalArgumentException.class, () -> new Calibration(0.0, 0, 0, 0)); + assertThrows(IllegalArgumentException.class, () -> new Calibration(Double.NaN, 0, 0, 0)); + assertThrows(IllegalArgumentException.class, () -> new Calibration(Double.POSITIVE_INFINITY, 0, 0, 0)); + assertThrows(IllegalArgumentException.class, () -> new Calibration(Double.NEGATIVE_INFINITY, 0, 0, 0)); + }""") + +content = content.replace(""" @Test + public void testDegenerateOrigin() { + assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, Double.NaN, 0, 0)); + assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, Double.NaN, 0)); + assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, Double.POSITIVE_INFINITY, 0, 0)); + }""", """ @Test + public void testDegenerateOrigin() { + assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, Double.NaN, 0, 0)); + assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, Double.NaN, 0)); + assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, Double.POSITIVE_INFINITY, 0, 0)); + assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, Double.NEGATIVE_INFINITY, 0, 0)); + assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, Double.POSITIVE_INFINITY, 0)); + assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, Double.NEGATIVE_INFINITY, 0)); + }""") + +content = content.replace(""" @Test + public void testDegenerateAngle() { + assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, 0, Double.NaN)); + }""", """ @Test + public void testDegenerateAngle() { + assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, 0, Double.NaN)); + assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, 0, Double.POSITIVE_INFINITY)); + assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, 0, Double.NEGATIVE_INFINITY)); + }""") + +with open(file_path, "w") as f: + f.write(content) From 7a45d81aab170185b47d46435f71a711f9b28f2a Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 25 May 2026 18:26:04 +0000 Subject: [PATCH 3/4] Add degenerate calibration guards to Calibration transform - Add checks in `Calibration` constructor for `scale == 0` or non-finite inputs - Throw `IllegalArgumentException` on degenerate cases - Add tests in `CalibrationTest` to verify degenerate case behavior Co-authored-by: Unluckyathecking <111193970+Unluckyathecking@users.noreply.github.com> --- fix.patch | 34 ---------------------------------- update_tests.py | 47 ----------------------------------------------- 2 files changed, 81 deletions(-) delete mode 100644 fix.patch delete mode 100644 update_tests.py diff --git a/fix.patch b/fix.patch deleted file mode 100644 index 2f93f100..00000000 --- a/fix.patch +++ /dev/null @@ -1,34 +0,0 @@ ---- src/test/java/org/opensourcephysics/cabrillo/tracker/calibration/CalibrationTest.java -+++ src/test/java/org/opensourcephysics/cabrillo/tracker/calibration/CalibrationTest.java -@@ -82,21 +82,24 @@ - assertEquals(173.25, p.y(), 1e-9); - } - -- --// add tests for invalid cases -- - @Test - public void testDegenerateScale() { - assertThrows(IllegalArgumentException.class, () -> new Calibration(0.0, 0, 0, 0)); - assertThrows(IllegalArgumentException.class, () -> new Calibration(Double.NaN, 0, 0, 0)); - assertThrows(IllegalArgumentException.class, () -> new Calibration(Double.POSITIVE_INFINITY, 0, 0, 0)); -+ assertThrows(IllegalArgumentException.class, () -> new Calibration(Double.NEGATIVE_INFINITY, 0, 0, 0)); - } - - @Test - public void testDegenerateOrigin() { - assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, Double.NaN, 0, 0)); - assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, Double.NaN, 0)); - assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, Double.POSITIVE_INFINITY, 0, 0)); -+ assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, Double.NEGATIVE_INFINITY, 0, 0)); -+ assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, Double.POSITIVE_INFINITY, 0)); -+ assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, Double.NEGATIVE_INFINITY, 0)); - } - - @Test - public void testDegenerateAngle() { - assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, 0, Double.NaN)); -+ assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, 0, Double.POSITIVE_INFINITY)); -+ assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, 0, Double.NEGATIVE_INFINITY)); - } - } diff --git a/update_tests.py b/update_tests.py deleted file mode 100644 index e8f81a27..00000000 --- a/update_tests.py +++ /dev/null @@ -1,47 +0,0 @@ -import sys - -file_path = "src/test/java/org/opensourcephysics/cabrillo/tracker/calibration/CalibrationTest.java" - -with open(file_path, "r") as f: - content = f.read() - -content = content.replace(""" @Test - public void testDegenerateScale() { - assertThrows(IllegalArgumentException.class, () -> new Calibration(0.0, 0, 0, 0)); - assertThrows(IllegalArgumentException.class, () -> new Calibration(Double.NaN, 0, 0, 0)); - assertThrows(IllegalArgumentException.class, () -> new Calibration(Double.POSITIVE_INFINITY, 0, 0, 0)); - }""", """ @Test - public void testDegenerateScale() { - assertThrows(IllegalArgumentException.class, () -> new Calibration(0.0, 0, 0, 0)); - assertThrows(IllegalArgumentException.class, () -> new Calibration(Double.NaN, 0, 0, 0)); - assertThrows(IllegalArgumentException.class, () -> new Calibration(Double.POSITIVE_INFINITY, 0, 0, 0)); - assertThrows(IllegalArgumentException.class, () -> new Calibration(Double.NEGATIVE_INFINITY, 0, 0, 0)); - }""") - -content = content.replace(""" @Test - public void testDegenerateOrigin() { - assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, Double.NaN, 0, 0)); - assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, Double.NaN, 0)); - assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, Double.POSITIVE_INFINITY, 0, 0)); - }""", """ @Test - public void testDegenerateOrigin() { - assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, Double.NaN, 0, 0)); - assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, Double.NaN, 0)); - assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, Double.POSITIVE_INFINITY, 0, 0)); - assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, Double.NEGATIVE_INFINITY, 0, 0)); - assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, Double.POSITIVE_INFINITY, 0)); - assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, Double.NEGATIVE_INFINITY, 0)); - }""") - -content = content.replace(""" @Test - public void testDegenerateAngle() { - assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, 0, Double.NaN)); - }""", """ @Test - public void testDegenerateAngle() { - assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, 0, Double.NaN)); - assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, 0, Double.POSITIVE_INFINITY)); - assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, 0, Double.NEGATIVE_INFINITY)); - }""") - -with open(file_path, "w") as f: - f.write(content) From b59948a2bca78c67f5a3fb09bd434d1362780aba Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 25 May 2026 18:30:14 +0000 Subject: [PATCH 4/4] Add degenerate calibration guards to Calibration transform - Add checks in `Calibration` constructor for `scale == 0` or non-finite inputs - Throw `IllegalArgumentException` on degenerate cases - Add tests in `CalibrationTest` to verify degenerate case behavior Co-authored-by: Unluckyathecking <111193970+Unluckyathecking@users.noreply.github.com> --- .../tracker/calibration/CalibrationTest.java | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/src/test/java/org/opensourcephysics/cabrillo/tracker/calibration/CalibrationTest.java b/src/test/java/org/opensourcephysics/cabrillo/tracker/calibration/CalibrationTest.java index 382c34f8..e8df64a5 100644 --- a/src/test/java/org/opensourcephysics/cabrillo/tracker/calibration/CalibrationTest.java +++ b/src/test/java/org/opensourcephysics/cabrillo/tracker/calibration/CalibrationTest.java @@ -88,26 +88,39 @@ public void testRotatedRoundTrip() { @Test public void testDegenerateScale() { - assertThrows(IllegalArgumentException.class, () -> new Calibration(0.0, 0, 0, 0)); - assertThrows(IllegalArgumentException.class, () -> new Calibration(Double.NaN, 0, 0, 0)); - assertThrows(IllegalArgumentException.class, () -> new Calibration(Double.POSITIVE_INFINITY, 0, 0, 0)); - assertThrows(IllegalArgumentException.class, () -> new Calibration(Double.NEGATIVE_INFINITY, 0, 0, 0)); + IllegalArgumentException ex1 = assertThrows(IllegalArgumentException.class, () -> new Calibration(0.0, 0, 0, 0)); + assertTrue(ex1.getMessage().contains("scale")); + IllegalArgumentException ex2 = assertThrows(IllegalArgumentException.class, () -> new Calibration(Double.NaN, 0, 0, 0)); + assertTrue(ex2.getMessage().contains("scale")); + IllegalArgumentException ex3 = assertThrows(IllegalArgumentException.class, () -> new Calibration(Double.POSITIVE_INFINITY, 0, 0, 0)); + assertTrue(ex3.getMessage().contains("scale")); + IllegalArgumentException ex4 = assertThrows(IllegalArgumentException.class, () -> new Calibration(Double.NEGATIVE_INFINITY, 0, 0, 0)); + assertTrue(ex4.getMessage().contains("scale")); } @Test public void testDegenerateOrigin() { - assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, Double.NaN, 0, 0)); - assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, Double.NaN, 0)); - assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, Double.POSITIVE_INFINITY, 0, 0)); - assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, Double.NEGATIVE_INFINITY, 0, 0)); - assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, Double.POSITIVE_INFINITY, 0)); - assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, Double.NEGATIVE_INFINITY, 0)); + IllegalArgumentException ex1 = assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, Double.NaN, 0, 0)); + assertTrue(ex1.getMessage().contains("originX")); + IllegalArgumentException ex2 = assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, Double.NaN, 0)); + assertTrue(ex2.getMessage().contains("originY")); + IllegalArgumentException ex3 = assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, Double.POSITIVE_INFINITY, 0, 0)); + assertTrue(ex3.getMessage().contains("originX")); + IllegalArgumentException ex4 = assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, Double.NEGATIVE_INFINITY, 0, 0)); + assertTrue(ex4.getMessage().contains("originX")); + IllegalArgumentException ex5 = assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, Double.POSITIVE_INFINITY, 0)); + assertTrue(ex5.getMessage().contains("originY")); + IllegalArgumentException ex6 = assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, Double.NEGATIVE_INFINITY, 0)); + assertTrue(ex6.getMessage().contains("originY")); } @Test public void testDegenerateAngle() { - assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, 0, Double.NaN)); - assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, 0, Double.POSITIVE_INFINITY)); - assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, 0, Double.NEGATIVE_INFINITY)); + IllegalArgumentException ex1 = assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, 0, Double.NaN)); + assertTrue(ex1.getMessage().contains("angle")); + IllegalArgumentException ex2 = assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, 0, Double.POSITIVE_INFINITY)); + assertTrue(ex2.getMessage().contains("angle")); + IllegalArgumentException ex3 = assertThrows(IllegalArgumentException.class, () -> new Calibration(1.0, 0, 0, Double.NEGATIVE_INFINITY)); + assertTrue(ex3.getMessage().contains("angle")); } }