Add NextHigherSameBitCount algorithm (#5865)

This commit is contained in:
Hardik Pawar
2024-10-26 20:01:11 +05:30
committed by GitHub
parent 9e1dd86a08
commit 94daff0895
3 changed files with 54 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
package com.thealgorithms.bitmanipulation;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
class NextHigherSameBitCountTest {
@ParameterizedTest
@CsvSource({
"5, 6", // 101 -> 110
"7, 11", // 0111 -> 1011
"3, 5", // 011 -> 101
"12, 17", // 001100 -> 010001
"15, 23" // 01111 -> 10111
})
void
testNextHigherSameBitCount(int input, int expected) {
assertEquals(expected, NextHigherSameBitCount.nextHigherSameBitCount(input));
}
}