Skip to content

Commit b46a1b4

Browse files
added parameterized tests
1 parent def7a0b commit b46a1b4

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/test/java/com/thealgorithms/bitmanipulation/SwapAdjacentBitsTest.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
44

5-
import org.junit.jupiter.api.Test;
5+
import org.junit.jupiter.params.ParameterizedTest;
6+
import org.junit.jupiter.params.provider.CsvSource;
67

78
class SwapAdjacentBitsTest {
89

9-
@Test
10-
void testSwapAdjacentBits() {
11-
assertEquals(1, SwapAdjacentBits.swapAdjacentBits(2));
12-
13-
assertEquals(23, SwapAdjacentBits.swapAdjacentBits(43));
14-
15-
assertEquals(102, SwapAdjacentBits.swapAdjacentBits(153));
16-
17-
assertEquals(15, SwapAdjacentBits.swapAdjacentBits(15));
18-
19-
assertEquals(0, SwapAdjacentBits.swapAdjacentBits(0));
10+
@ParameterizedTest
11+
@CsvSource({
12+
"2, 1", // 2 (10 in binary) should become 1 (01 in binary)
13+
"43, 23", // 43 should become 23
14+
"153, 102", // 153 should become 102
15+
"15, 15", // 15 (1111) remains 15 (1111)
16+
"0, 0" // 0 (0000) remains 0 (0000)
17+
})
18+
void testSwapAdjacentBits(int input, int expected) {
19+
assertEquals(expected, SwapAdjacentBits.swapAdjacentBits(input));
2020
}
2121
}

0 commit comments

Comments
 (0)