merge: Upgraded hexToBinary function (#910)

* feat: used js object intead of switch

* pref: optimzed the algo with regex & replace method

* feat: add hex validation with test case

* feat: add type validation

* chore: fix grammar mistake

* docs: add binLookup comments
This commit is contained in:
Fahim Faisaal
2022-03-02 10:10:07 +06:00
committed by GitHub
parent ab06131656
commit 378d4abebc
2 changed files with 44 additions and 25 deletions

View File

@@ -1,6 +1,18 @@
import hexToBinary from '../HexToBinary'
describe('hexToBinary', () => {
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()
})
it('expects to return correct hexadecimal value', () => {
expect(hexToBinary('8')).toBe('1000')
})