X Tutup
Skip to content

Commit 3bc23af

Browse files
authored
Update HammingCode.test.js
Refactored tests, usage of .each for most test cases.
1 parent 002038f commit 3bc23af

File tree

1 file changed

+11
-38
lines changed

1 file changed

+11
-38
lines changed
Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,14 @@
11
import { HammingCode } from '../HammingCode'
22

3-
test('checks HammingCode of 1110101 hex converted is 5', () => {
4-
let code = HammingCode(parseInt("1110101",16))
5-
expect(code).toBe(5)
6-
})
7-
8-
test('checks HammingCode of 10043091 hex converted is 7', () => {
9-
let code = HammingCode(parseInt("10043091",16))
10-
expect(code).toBe(7)
11-
})
12-
13-
test('checks HammingCode of 889193 hex converted is 9', () => {
14-
let code = HammingCode(parseInt("889193",16))
15-
expect(code).toBe(9)
16-
})
17-
18-
test('checks HammingCode of 1110101 hex converted is 5', () => {
19-
let code = HammingCode(parseInt("1101110",2))
20-
expect(code).toBe(5)
21-
})
22-
23-
test('checks HammingCode of 1101110 is 5', () => {
24-
let code = HammingCode(1101110)
25-
expect(code).toBe(5)
26-
})
27-
28-
test('checks HammingCode of 0x10043091 is 7', () => {
29-
let code = HammingCode(0x10043091)
30-
expect(code).toBe(7)
31-
})
32-
33-
test('checks HammingCode of 0x8891930311 is NaN (above range)', () => {
34-
let code = HammingCode(0x8891930311)
35-
expect(code).toBeNaN()
36-
})
37-
38-
test('checks HammingCode of the Number 100 is 3', () => {
39-
let code = HammingCode((Number(100))
40-
expect(code).toBe(3)
3+
describe.each([
4+
{ inputVal:Number(117), expectedVal: 5 },
5+
{ inputVal:parseInt(0x9F9,16), expectedVal: 7 },
6+
{ inputVal:parseInt(0x889193,16), expectedVal: 10 },
7+
{ inputVal:10043091, expectedVal: 14},
8+
{ inputVal:parseInt("1101110",2), expectedVal: 5 },
9+
{ inputVal:parseInt(1101110,2), expectedVal: 5 }
10+
])('Resulting hamming code conversion from $inputVal', ({inputVal, expectedVal}) => {
11+
test(`returns bit count = ${expectedVal}`, () => {
12+
expect(inputVal).toBe(expectedVal)
13+
})
4114
})

0 commit comments

Comments
 (0)
X Tutup