refactor: BinaryToHexadecimal (#5331)

This commit is contained in:
Alex Klymenko
2024-08-16 16:43:54 +02:00
committed by GitHub
parent ec30592fcb
commit c20375ae0f
2 changed files with 50 additions and 39 deletions

View File

@ -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));
}
}