Skip to content

Commit 7374111

Browse files
authored
Make test use describe / each, use binary literals
1 parent f0982bd commit 7374111

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import { generateGrayCodes } from '../GrayCodes.js'
1+
import { generateGrayCodes } from '../GrayCodes.js'
22

3-
/**
4-
* Test cases for the generateGrayCodes function.
5-
*/
6-
const testCases = [
7-
{ n: 0, expected: [0] },
8-
{ n: 1, expected: [0, 1] },
9-
{ n: 2, expected: [0, 1, 3, 2] },
10-
{ n: 3, expected: [0, 1, 3, 2, 6, 7, 5, 4] },
11-
{ n: 4, expected: [0, 1, 3, 2, 6, 7, 5, 4, 12, 13, 15, 14, 10, 11, 9, 8] },
12-
];
13-
14-
testCases.forEach(({ n, expected }) => {
15-
test(`Generate Gray codes for n=${n}`, () => {
16-
const grayCodes = generateGrayCodes(n);
17-
expect(grayCodes).toEqual(expected);
18-
});
19-
});
3+
describe('Gray codes', () => {
4+
test.each([
5+
[0, [0b0]],
6+
[1, [0b0, 0b1]],
7+
[2, [0b00, 0b01, 0b11, 0b10]],
8+
[3, [0b000, 0b001, 0b011, 0b010, 0b110, 0b111, 0b101, 0b100]],
9+
[
10+
4,
11+
[
12+
0b0000, 0b0001, 0b0011, 0b0010, 0b0110, 0b0111, 0b0101, 0b0100, 0b1100,
13+
0b1101, 0b1111, 0b1110, 0b1010, 0b1011, 0b1001, 0b1000
14+
]
15+
]
16+
])('n = %i -> %j', (n, expected) => {
17+
expect(generateGrayCodes(n)).toEqual(expected)
18+
})
19+
})

0 commit comments

Comments
 (0)