Movatterモバイル変換


[0]ホーム

URL:


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

Commit3623e42

Browse files
authored
tests: addHexToDecimal.test.js (#1662)
1 parente2b9754 commit3623e42

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

‎Conversions/HexToDecimal.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
functionhexToInt(hexNum){
2+
if(!/^[0-9A-F]+$/.test(hexNum)){
3+
thrownewError('Invalid hex string.')
4+
}
25
constnumArr=hexNum.split('')// converts number to array
36
returnnumArr.map((item,index)=>{
47
switch(item){
@@ -29,4 +32,4 @@ function hexToDecimal(hexNum) {
2932
},0)
3033
}
3134

32-
export{hexToInt,hexToDecimal}
35+
export{hexToDecimal}

‎Conversions/test/HexToDecimal.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import{hexToDecimal}from'../HexToDecimal'
2+
3+
describe('Testing HexToDecimal',()=>{
4+
it.each([
5+
['0',0],
6+
['1',1],
7+
['A',10],
8+
['B',11],
9+
['C',12],
10+
['D',13],
11+
['E',14],
12+
['F',15],
13+
['10',16],
14+
['859',2137],
15+
['4D2',1234],
16+
['81323ABD92',554893491602]
17+
])('check with %s',(hexStr,expected)=>{
18+
expect(hexToDecimal(hexStr)).toBe(expected)
19+
})
20+
21+
it.each(['a','-1','G',''])('throws for %s',(hexStr)=>{
22+
expect(()=>hexToDecimal(hexStr)).toThrowError()
23+
})
24+
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp