Add test case for HexaDecimalToBinary (#3683)
This commit is contained in:
parent
838916d8e9
commit
2c9edc95b8
@ -5,13 +5,13 @@ public class HexaDecimalToBinary {
|
||||
|
||||
private final int LONG_BITS = 8;
|
||||
|
||||
public void convert(String numHex) {
|
||||
public String convert(String numHex) {
|
||||
// String a HexaDecimal:
|
||||
int conHex = Integer.parseInt(numHex, 16);
|
||||
// Hex a Binary:
|
||||
String binary = Integer.toBinaryString(conHex);
|
||||
// Output:
|
||||
System.out.println(numHex + " = " + completeDigits(binary));
|
||||
return completeDigits(binary);
|
||||
}
|
||||
|
||||
public String completeDigits(String binNum) {
|
||||
@ -39,7 +39,7 @@ public class HexaDecimalToBinary {
|
||||
HexaDecimalToBinary objConvert = new HexaDecimalToBinary();
|
||||
|
||||
for (String num : hexNums) {
|
||||
objConvert.convert(num);
|
||||
System.out.println(num + " = " + objConvert.convert(num));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,14 @@
|
||||
package com.thealgorithms.conversions;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class HexaDecimalToBinaryTest {
|
||||
|
||||
@Test
|
||||
public void testHexaDecimalToBinary(){
|
||||
HexaDecimalToBinary hexaDecimalToBinary = new HexaDecimalToBinary();
|
||||
assertEquals("1111111111111111111111111111111", hexaDecimalToBinary.convert("7fffffff"));
|
||||
assertEquals("101010111100110111101111", hexaDecimalToBinary.convert("abcdef"));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user