diff --git a/src/main/java/com/thealgorithms/maths/BinaryPow.java b/src/main/java/com/thealgorithms/maths/BinaryPow.java index 64b4e34fd..d431d58b9 100644 --- a/src/main/java/com/thealgorithms/maths/BinaryPow.java +++ b/src/main/java/com/thealgorithms/maths/BinaryPow.java @@ -21,29 +21,4 @@ public class BinaryPow { } return res; } - - /** - * Function for testing binary exponentiation - * - * @param a the base - * @param p the exponent - */ - public static void test(int a, int p) { - int res = binPow(a, p); - assert res == (int) Math.pow(a, p) : "Incorrect Implementation"; - System.out.println(a + "^" + p + ": " + res); - } - - /** - * Main Function to call tests - * - * @param args System Line Arguments - */ - public static void main(String[] args) { - // prints 2^15: 32768 - test(2, 15); - - // prints 3^9: 19683 - test(3, 9); - } } diff --git a/src/test/java/com/thealgorithms/maths/BinaryPowTest.java b/src/test/java/com/thealgorithms/maths/BinaryPowTest.java new file mode 100644 index 000000000..ec4005d4e --- /dev/null +++ b/src/test/java/com/thealgorithms/maths/BinaryPowTest.java @@ -0,0 +1,16 @@ +package com.thealgorithms.maths; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +public class BinaryPowTest { + + @Test + void testBinPow() { + assertEquals(4, BinaryPow.binPow(2, 2)); + assertEquals(256, BinaryPow.binPow(4, 4)); + assertEquals(729, BinaryPow.binPow(9, 3)); + assertEquals(262144, BinaryPow.binPow(8, 6)); + } +}