File tree 2 files changed +18
-5
lines changed
2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change 1
- function intToHex ( num ) {
1
+ function intToHex ( num ) {
2
2
switch ( num ) {
3
3
case 10 : return 'A'
4
4
case 11 : return 'B'
@@ -10,7 +10,7 @@ function intToHex (num) {
10
10
return num
11
11
}
12
12
13
- function decimalToHex ( num ) {
13
+ function decimalToHex ( num ) {
14
14
const hexOut = [ ]
15
15
while ( num > 15 ) {
16
16
hexOut . unshift ( intToHex ( num % 16 ) )
@@ -19,6 +19,4 @@ function decimalToHex (num) {
19
19
return intToHex ( num ) + hexOut . join ( '' )
20
20
}
21
21
22
- // test cases
23
- console . log ( decimalToHex ( 999098 ) === 'F3EBA' )
24
- console . log ( decimalToHex ( 123 ) === '7B' )
22
+ export { decimalToHex }
Original file line number Diff line number Diff line change
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
+ } )
You can’t perform that action at this time.
0 commit comments