From a796f6dc413003b14163787883c0398e0af9e0ac Mon Sep 17 00:00:00 2001 From: Oleksandr Klymenko Date: Thu, 17 Jul 2025 18:32:48 +0300 Subject: [PATCH] testing: added unit tests for the `BinaryPow.binPow` (#6386) testing: added unit tests for the BinaryPow.binPow Co-authored-by: Deniz Altunkapan <93663085+DenizAltunkapan@users.noreply.github.com> --- .../thealgorithms/maths/BinaryPowTest.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/test/java/com/thealgorithms/maths/BinaryPowTest.java b/src/test/java/com/thealgorithms/maths/BinaryPowTest.java index f9b019e8f..632dfbd1d 100644 --- a/src/test/java/com/thealgorithms/maths/BinaryPowTest.java +++ b/src/test/java/com/thealgorithms/maths/BinaryPowTest.java @@ -13,4 +13,34 @@ public class BinaryPowTest { assertEquals(729, BinaryPow.binPow(9, 3)); assertEquals(262144, BinaryPow.binPow(8, 6)); } + + @Test + void testZeroExponent() { + assertEquals(1, BinaryPow.binPow(2, 0)); + assertEquals(1, BinaryPow.binPow(100, 0)); + assertEquals(1, BinaryPow.binPow(-5, 0)); + } + + @Test + void testZeroBase() { + assertEquals(0, BinaryPow.binPow(0, 5)); + assertEquals(1, BinaryPow.binPow(0, 0)); + } + + @Test + void testOneBase() { + assertEquals(1, BinaryPow.binPow(1, 100)); + assertEquals(1, BinaryPow.binPow(1, 0)); + } + + @Test + void testNegativeBase() { + assertEquals(-8, BinaryPow.binPow(-2, 3)); + assertEquals(16, BinaryPow.binPow(-2, 4)); + } + + @Test + void testLargeExponent() { + assertEquals(1073741824, BinaryPow.binPow(2, 30)); + } }