mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-27 06:23:08 +08:00
feat: Add ClearLeftmostSetBit new algorithm with Junit tests (#5702)
This commit is contained in:
@ -0,0 +1,16 @@
|
||||
package com.thealgorithms.bitmanipulation;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ClearLeftmostSetBitTest {
|
||||
|
||||
@Test
|
||||
public void testClearLeftmostSetBit() {
|
||||
assertEquals(10, ClearLeftmostSetBit.clearLeftmostSetBit(26)); // 11010 -> 01010
|
||||
assertEquals(0, ClearLeftmostSetBit.clearLeftmostSetBit(1)); // 1 -> 0
|
||||
assertEquals(3, ClearLeftmostSetBit.clearLeftmostSetBit(7)); // 111 -> 011
|
||||
assertEquals(2, ClearLeftmostSetBit.clearLeftmostSetBit(6)); // 0110 -> 0010
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user