File tree Expand file tree Collapse file tree 1 file changed +23
-3
lines changed
src/test/java/com/thealgorithms/bitmanipulation Expand file tree Collapse file tree 1 file changed +23
-3
lines changed Original file line number Diff line number Diff line change 6
6
import org .junit .jupiter .api .Test ;
7
7
8
8
public class ParityCheckTest {
9
+ @ Test
10
+ public void testIsEvenParity () {
11
+ assertTrue (ParityCheck .checkParity (0 )); // 0 -> 0 ones
12
+ assertTrue (ParityCheck .checkParity (3 )); // 11 -> 2 ones
13
+ assertTrue (ParityCheck .checkParity (5 )); // 101 -> 2 ones
14
+ assertTrue (ParityCheck .checkParity (10 )); // 1010 -> 2 ones
15
+ assertTrue (ParityCheck .checkParity (15 )); // 1111 -> 4 ones
16
+ assertTrue (ParityCheck .checkParity (1023 )); // 10 ones
17
+ }
18
+
9
19
@ Test
10
20
public void testIsOddParity () {
11
- assertTrue (ParityCheck .checkParity (5 )); // 101 has 2 ones (even parity)
12
- assertFalse (ParityCheck .checkParity (7 )); // 111 has 3 ones (odd parity)
13
- assertFalse (ParityCheck .checkParity (8 )); // 1000 has 1 one (odd parity)
21
+ assertFalse (ParityCheck .checkParity (1 )); // 1 -> 1 one
22
+ assertFalse (ParityCheck .checkParity (2 )); // 10 -> 1 one
23
+ assertFalse (ParityCheck .checkParity (7 )); // 111 -> 3 ones
24
+ assertFalse (ParityCheck .checkParity (8 )); // 1000 -> 1 one
25
+ assertFalse (ParityCheck .checkParity (11 )); // 1011 -> 3 ones
26
+ assertFalse (ParityCheck .checkParity (31 )); // 11111 -> 5 ones
27
+ }
28
+
29
+ @ Test
30
+ public void testLargeNumbers () {
31
+ assertTrue (ParityCheck .checkParity (0b10101010)); // 4 ones
32
+ assertFalse (ParityCheck .checkParity (0b100000000)); // 1 one
33
+ assertTrue (ParityCheck .checkParity (0xAAAAAAAA )); // Alternating bits, 16 ones
14
34
}
15
35
}
You can’t perform that action at this time.
0 commit comments