mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2026-03-13 15:21:15 +08:00
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:
15
Conversions/test/BinaryToDecimal.test.js
Normal file
15
Conversions/test/BinaryToDecimal.test.js
Normal 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)
|
||||
})
|
||||
})
|
||||
19
Conversions/test/HexToBinary.test.js
Normal file
19
Conversions/test/HexToBinary.test.js
Normal 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))
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user