Skip to content

Commit a796f6d

Browse files
testing: added unit tests for the BinaryPow.binPow (#6386)
testing: added unit tests for the BinaryPow.binPow Co-authored-by: Deniz Altunkapan <[email protected]>
1 parent 440b6f5 commit a796f6d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/test/java/com/thealgorithms/maths/BinaryPowTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,34 @@ void testBinPow() {
1313
assertEquals(729, BinaryPow.binPow(9, 3));
1414
assertEquals(262144, BinaryPow.binPow(8, 6));
1515
}
16+
17+
@Test
18+
void testZeroExponent() {
19+
assertEquals(1, BinaryPow.binPow(2, 0));
20+
assertEquals(1, BinaryPow.binPow(100, 0));
21+
assertEquals(1, BinaryPow.binPow(-5, 0));
22+
}
23+
24+
@Test
25+
void testZeroBase() {
26+
assertEquals(0, BinaryPow.binPow(0, 5));
27+
assertEquals(1, BinaryPow.binPow(0, 0));
28+
}
29+
30+
@Test
31+
void testOneBase() {
32+
assertEquals(1, BinaryPow.binPow(1, 100));
33+
assertEquals(1, BinaryPow.binPow(1, 0));
34+
}
35+
36+
@Test
37+
void testNegativeBase() {
38+
assertEquals(-8, BinaryPow.binPow(-2, 3));
39+
assertEquals(16, BinaryPow.binPow(-2, 4));
40+
}
41+
42+
@Test
43+
void testLargeExponent() {
44+
assertEquals(1073741824, BinaryPow.binPow(2, 30));
45+
}
1646
}

0 commit comments

Comments
 (0)