mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-12-19 06:58:15 +08:00
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:
@@ -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')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user