- Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathModuloPowerOfTwoTest.java
38 lines (33 loc) · 1019 Bytes
/
ModuloPowerOfTwoTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
packagecom.thealgorithms.bitmanipulation;
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
importstaticorg.junit.jupiter.api.Assertions.assertThrows;
importorg.junit.jupiter.params.ParameterizedTest;
importorg.junit.jupiter.params.provider.CsvSource;
classModuloPowerOfTwoTest {
@ParameterizedTest
@CsvSource({
"10, 3, 2",
"15, 2, 3",
"20, 4, 4",
"7, 1, 1",
"5, 1, 1",
"36, 5, 4",
})
void
testModuloPowerOfTwo(intx, intn, intexpected) {
assertEquals(expected, ModuloPowerOfTwo.moduloPowerOfTwo(x, n));
}
@ParameterizedTest
@CsvSource({
"10, 0",
"15, -2",
"20, -4",
"7, -1",
"5, -1",
})
void
testNegativeExponent(intx, intn) {
IllegalArgumentExceptionexception = assertThrows(IllegalArgumentException.class, () -> ModuloPowerOfTwo.moduloPowerOfTwo(x, n));
assertEquals("The exponent must be positive", exception.getMessage());
}
}