-
Notifications
You must be signed in to change notification settings - Fork 19.7k
/
Copy pathReverseBitsTest.java
41 lines (30 loc) · 1.31 KB
/
ReverseBitsTest.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
39
40
41
package com.thealgorithms.bitmanipulation;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
class ReverseBitsTest {
@ParameterizedTest
@MethodSource("provideTestCases")
void testReverseBits(int input, int expected) {
assertEquals(expected, ReverseBits.reverseBits(input));
}
private static Stream<Arguments> provideTestCases() {
return Stream.of(
// Edge case: All bits are 0
Arguments.of(0, 0),
// Edge case: All bits are 1 (Two’s complement representation of -1)
Arguments.of(-1, -1),
// Case with random number 43261596
Arguments.of(43261596, 964176192),
// Case with maximum positive value for 32-bit integer
Arguments.of(Integer.MAX_VALUE, -2),
// Case with minimum value (all bits 1 except the sign bit)
Arguments.of(Integer.MIN_VALUE, 1),
// Case with a single bit set (2^0 = 1)
Arguments.of(1, Integer.MIN_VALUE),
// Case with alternating bits: 0b101010...10 (in binary)
Arguments.of(0xAAAAAAAA, 0x55555555));
}
}