merge: Add binary to decimal test file and convert function to es6 model. (#806)

* Added Hex to Binary conversion

* Add Binary to decimal test

* Fix Style
This commit is contained in:
Dhana D
2021-10-24 00:46:13 +07:00
committed by GitHub
parent 4ba2c32d78
commit d5e309b605
4 changed files with 72 additions and 7 deletions

View File

@@ -0,0 +1,15 @@
import binaryToDecimal from '../BinaryToDecimal'
describe('BinaryToDecimal', () => {
it('expects to return correct decimal value', () => {
expect(binaryToDecimal('1000')).toBe(8)
})
it('expects to return correct hexadecimal value for more than one hex digit', () => {
expect(binaryToDecimal('01101000')).toBe(104)
})
it('expects to return correct hexadecimal value for padding-required binary', () => {
expect(binaryToDecimal('1000101')).toBe(69)
})
})

View File

@@ -0,0 +1,19 @@
import hexToBinary from '../HexToBinary'
describe('hexToBinary', () => {
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))
})
})