mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-10 04:26:27 +08:00
refactor: BinaryToHexadecimal
(#5331)
This commit is contained in:
@ -1,14 +1,22 @@
|
||||
package com.thealgorithms.conversions;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
public class BinaryToHexadecimalTest {
|
||||
|
||||
@Test
|
||||
public void testBinaryToHexadecimal() {
|
||||
assertEquals("6A", BinaryToHexadecimal.binToHex(1101010));
|
||||
assertEquals("C", BinaryToHexadecimal.binToHex(1100));
|
||||
@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));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user