Skip to content

Commit fd8d4ba

Browse files
committed
test: improve coverage for DiscreteLogarithmBSGS
1 parent cf027be commit fd8d4ba

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,18 @@ public void testLargeMod() {
2525
long x = DiscreteLogarithmBSGS.discreteLog(5, 5, 1000003);
2626
assertEquals(1, x);
2727
}
28+
29+
@Test
30+
public void testImmediateReturnCase() {
31+
// because a^0 ≡ 1 (mod m)
32+
assertEquals(0, DiscreteLogarithmBSGS.discreteLog(7, 1, 13));
33+
}
34+
35+
@Test
36+
public void testModPowBranchCoverage() {
37+
assertEquals(1, DiscreteLogarithmBSGS.modPow(10, 0, 17)); // exp=0 branch
38+
assertEquals(10 % 17, DiscreteLogarithmBSGS.modPow(10, 1, 17)); // odd exp branch
39+
assertEquals(100 % 17, DiscreteLogarithmBSGS.modPow(10, 2, 17)); // even exp branch
40+
}
41+
2842
}

0 commit comments

Comments
 (0)