Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d2ed0c7

Browse files
Merge pull request TheAlgorithms#717 from trasherdk/DecimalToHex
DecimalToHex - test
2 parents c0fa45c + 38b42cf commit d2ed0c7

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

‎Conversions/DecimalToHex.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,4 @@ function decimalToHex (num) {
1919
return intToHex(num) + hexOut.join('')
2020
}
2121

22-
// test cases
23-
console.log(decimalToHex(999098) === 'F3EBA')
24-
console.log(decimalToHex(123) === '7B')
22+
export { decimalToHex }

‎Conversions/test/DecimalToHex.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { decimalToHex } from '../DecimalToHex'
2+
3+
describe('DecimalToHex', () => {
4+
it('expects to return correct hexadecimal value', () => {
5+
expect(decimalToHex(255)).toBe('FF')
6+
})
7+
8+
it('expects to return correct hexadecimal value, matching (num).toString(16)', () => {
9+
expect(decimalToHex(32768)).toBe((32768).toString(16).toUpperCase())
10+
})
11+
12+
it('expects to not handle negative numbers', () => {
13+
expect(decimalToHex(-32768)).not.toBe((-32768).toString(16).toUpperCase())
14+
})
15+
})

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /