diff --git a/Conversions/DecimalToHex.js b/Conversions/DecimalToHex.js index 5b130de9a..f13a93e09 100644 --- a/Conversions/DecimalToHex.js +++ b/Conversions/DecimalToHex.js @@ -19,6 +19,4 @@ function decimalToHex (num) { return intToHex(num) + hexOut.join('') } -// test cases -console.log(decimalToHex(999098) === 'F3EBA') -console.log(decimalToHex(123) === '7B') +export { decimalToHex } diff --git a/Conversions/test/DecimalToHex.test.js b/Conversions/test/DecimalToHex.test.js new file mode 100644 index 000000000..53cd88473 --- /dev/null +++ b/Conversions/test/DecimalToHex.test.js @@ -0,0 +1,15 @@ +import { decimalToHex } from '../DecimalToHex' + +describe('DecimalToHex', () => { + it('expects to return correct hexadecimal value', () => { + expect(decimalToHex(255)).toBe('FF') + }) + + it('expects to return correct hexadecimal value, matching (num).toString(16)', () => { + expect(decimalToHex(32768)).toBe((32768).toString(16).toUpperCase()) + }) + + it('expects to not handle negative numbers', () => { + expect(decimalToHex(-32768)).not.toBe((-32768).toString(16).toUpperCase()) + }) +})