Skip to content

Commit 2f2a32b

Browse files
testing: improve test coverage ParityCheckTest (#6389)
testing: improve test coverage ParityCheckTest Co-authored-by: Deniz Altunkapan <93663085+DenizAltunkapan@users.noreply.github.com>
1 parent 7f6e677 commit 2f2a32b

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/test/java/com/thealgorithms/bitmanipulation/ParityCheckTest.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,30 @@
66
import org.junit.jupiter.api.Test;
77

88
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+
919
@Test
1020
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
1434
}
1535
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy