From 9823ea17df3f642531d1761a0a5af15bf7aec1b4 Mon Sep 17 00:00:00 2001 From: JulianGStudium Date: Tue, 30 Jun 2026 21:47:27 +0200 Subject: [PATCH 1/2] Add unit tests for SquareRootWithBabylonianMethod Adds JUnit 5 unit tests for `SquareRootWithBabylonianMethod`, which previously had no test coverage. Tests cover perfect squares, non-perfect squares, and a range of values from 1 to 1000, comparing the result against Math.sqrt with a small delta. #HSFDPMUW --- .../SquareRootWithBabylonianMethodTest.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/test/java/com/thealgorithms/maths/SquareRootWithBabylonianMethodTest.java diff --git a/src/test/java/com/thealgorithms/maths/SquareRootWithBabylonianMethodTest.java b/src/test/java/com/thealgorithms/maths/SquareRootWithBabylonianMethodTest.java new file mode 100644 index 000000000000..beb0a4a39956 --- /dev/null +++ b/src/test/java/com/thealgorithms/maths/SquareRootWithBabylonianMethodTest.java @@ -0,0 +1,33 @@ +package com.thealgorithms.maths; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +public class SquareRootWithBabylonianMethodTest { + + private static final float DELTA = 1e-3f; + + @Test + void testPerfectSquares() { + assertEquals(1.0f, SquareRootWithBabylonianMethod.squareRoot(1.0f), DELTA); + assertEquals(2.0f, SquareRootWithBabylonianMethod.squareRoot(4.0f), DELTA); + assertEquals(3.0f, SquareRootWithBabylonianMethod.squareRoot(9.0f), DELTA); + assertEquals(5.0f, SquareRootWithBabylonianMethod.squareRoot(25.0f), DELTA); + assertEquals(12.0f, SquareRootWithBabylonianMethod.squareRoot(144.0f), DELTA); + } + + @Test + void testNonPerfectSquares() { + assertEquals((float) Math.sqrt(2.0), SquareRootWithBabylonianMethod.squareRoot(2.0f), DELTA); + assertEquals((float) Math.sqrt(50.0), SquareRootWithBabylonianMethod.squareRoot(50.0f), DELTA); + assertEquals((float) Math.sqrt(99.0), SquareRootWithBabylonianMethod.squareRoot(99.0f), DELTA); + } + + @Test + void testMatchesMathSqrtForRangeOfValues() { + for (float num = 1.0f; num <= 1000.0f; num += 1.0f) { + assertEquals((float) Math.sqrt(num), SquareRootWithBabylonianMethod.squareRoot(num), DELTA); + } + } +} From 634b36a1f8b002c3ab012491bf977669ba0da0ce Mon Sep 17 00:00:00 2001 From: JulianGStudium Date: Wed, 1 Jul 2026 22:04:23 +0200 Subject: [PATCH 2/2] Add Javadoc comment for SquareRootWithBabylonianMethodTest --- .../maths/SquareRootWithBabylonianMethodTest.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/test/java/com/thealgorithms/maths/SquareRootWithBabylonianMethodTest.java b/src/test/java/com/thealgorithms/maths/SquareRootWithBabylonianMethodTest.java index beb0a4a39956..ad34c1787f91 100644 --- a/src/test/java/com/thealgorithms/maths/SquareRootWithBabylonianMethodTest.java +++ b/src/test/java/com/thealgorithms/maths/SquareRootWithBabylonianMethodTest.java @@ -4,6 +4,10 @@ import org.junit.jupiter.api.Test; +/** + * Unit tests for {@link SquareRootWithBabylonianMethod}. + */ + public class SquareRootWithBabylonianMethodTest { private static final float DELTA = 1e-3f;