mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-27 06:23:08 +08:00
Add ParityCheck
algorithm (#5704)
This commit is contained in:
@ -0,0 +1,15 @@
|
||||
package com.thealgorithms.bitmanipulation;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ParityCheckTest {
|
||||
@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)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user