From 09bb4130bfa9be803049b5b4b731e4fbd57f8831 Mon Sep 17 00:00:00 2001 From: alxkm Date: Mon, 14 Jul 2025 23:29:47 +0200 Subject: [PATCH] testing: improve test coverage ParityCheckTest --- .../bitmanipulation/ParityCheckTest.java | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) 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