Add Set Kth Bit (#4990)

This commit is contained in:
Nishant Jain
2024-01-02 23:48:01 +05:30
committed by GitHub
parent 7ece806cf5
commit a7d140a43e
2 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,23 @@
package com.thealgorithms.bitmanipulation;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class SetKthBitTest {
@Test
void testSetKthBit() {
// Test case: Setting the 0th bit in 5 (binary 101)
assertEquals(5, SetKthBit.setKthBit(5, 0));
// Test case: Setting the 2nd bit in 10 (binary 1010)
assertEquals(14, SetKthBit.setKthBit(10, 2));
// Test case: Setting the 3rd bit in 15 (binary 1111)
assertEquals(15, SetKthBit.setKthBit(15, 3));
// Test case: Setting the 1st bit in 0 (binary 0)
assertEquals(2, SetKthBit.setKthBit(0, 1));
}
}