2021-10-24 00:46:13 +07:00
|
|
|
import hexToBinary from '../HexToBinary'
|
|
|
|
|
|
2022-03-02 10:10:07 +06:00
|
|
|
describe('Testing hexToBinary', () => {
|
|
|
|
|
it('expects throw error in invalid types', () => {
|
|
|
|
|
expect(() => hexToBinary(false)).toThrowError()
|
|
|
|
|
expect(() => hexToBinary(null)).toThrowError()
|
|
|
|
|
expect(() => hexToBinary(23464)).toThrowError()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('expects throw error in invalid hex', () => {
|
|
|
|
|
expect(() => hexToBinary('Hello i am not a valid Hex')).toThrowError()
|
|
|
|
|
expect(() => hexToBinary('Gf46f')).toThrowError()
|
|
|
|
|
expect(() => hexToBinary('M')).toThrowError()
|
|
|
|
|
})
|
|
|
|
|
|
2021-10-24 00:46:13 +07:00
|
|
|
it('expects to return correct hexadecimal value', () => {
|
|
|
|
|
expect(hexToBinary('8')).toBe('1000')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('expects to return correct binary value for more than one hex digit', () => {
|
|
|
|
|
expect(hexToBinary('EA')).toBe('11101010')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('expects to test its robustness as it should be case-insensitive', () => {
|
|
|
|
|
expect(hexToBinary('4d')).toBe('01001101')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('expects to return correct hexadecimal value, matching (num).toString(2)', () => {
|
|
|
|
|
expect(hexToBinary('F')).toBe(parseInt('F', 16).toString(2))
|
|
|
|
|
})
|
|
|
|
|
})
|