mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-05 08:17:33 +08:00
23 lines
759 B
Java
23 lines
759 B
Java
package com.thealgorithms.conversions;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
|
|
import org.junit.jupiter.params.ParameterizedTest;
|
|
import org.junit.jupiter.params.provider.CsvSource;
|
|
|
|
public class BinaryToHexadecimalTest {
|
|
|
|
@ParameterizedTest
|
|
@CsvSource({"0, 0", "1, 1", "10, 2", "1111, F", "1101010, 6A", "1100, C"})
|
|
void testBinToHex(int binary, String expectedHex) {
|
|
assertEquals(expectedHex, BinaryToHexadecimal.binToHex(binary));
|
|
}
|
|
|
|
@ParameterizedTest
|
|
@CsvSource({"2", "1234", "11112"})
|
|
void testInvalidBinaryInput(int binary) {
|
|
assertThrows(IllegalArgumentException.class, () -> BinaryToHexadecimal.binToHex(binary));
|
|
}
|
|
}
|