diff --git a/src/test/java/com/thealgorithms/bitmanipulation/ParityCheckTest.java b/src/test/java/com/thealgorithms/bitmanipulation/ParityCheckTest.java index 90147a61207b..1654c8ddfc1e 100644 --- a/src/test/java/com/thealgorithms/bitmanipulation/ParityCheckTest.java +++ b/src/test/java/com/thealgorithms/bitmanipulation/ParityCheckTest.java @@ -6,10 +6,30 @@ import org.junit.jupiter.api.Test; public class ParityCheckTest { + @Test + public void testIsEvenParity() { + assertTrue(ParityCheck.checkParity(0)); // 0 -> 0 ones + assertTrue(ParityCheck.checkParity(3)); // 11 -> 2 ones + assertTrue(ParityCheck.checkParity(5)); // 101 -> 2 ones + assertTrue(ParityCheck.checkParity(10)); // 1010 -> 2 ones + assertTrue(ParityCheck.checkParity(15)); // 1111 -> 4 ones + assertTrue(ParityCheck.checkParity(1023)); // 10 ones + } + @Test public void testIsOddParity() { - assertTrue(ParityCheck.checkParity(5)); // 101 has 2 ones (even parity) - assertFalse(ParityCheck.checkParity(7)); // 111 has 3 ones (odd parity) - assertFalse(ParityCheck.checkParity(8)); // 1000 has 1 one (odd parity) + assertFalse(ParityCheck.checkParity(1)); // 1 -> 1 one + assertFalse(ParityCheck.checkParity(2)); // 10 -> 1 one + assertFalse(ParityCheck.checkParity(7)); // 111 -> 3 ones + assertFalse(ParityCheck.checkParity(8)); // 1000 -> 1 one + assertFalse(ParityCheck.checkParity(11)); // 1011 -> 3 ones + assertFalse(ParityCheck.checkParity(31)); // 11111 -> 5 ones + } + + @Test + public void testLargeNumbers() { + assertTrue(ParityCheck.checkParity(0b10101010)); // 4 ones + assertFalse(ParityCheck.checkParity(0b100000000)); // 1 one + assertTrue(ParityCheck.checkParity(0xAAAAAAAA)); // Alternating bits, 16 ones } } 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