Skip to content

Commit e798afc

Browse files
authored
Added more test cases in GrayCode.test.js
1 parent 75d7649 commit e798afc

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed
Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,43 @@
1-
import { generateGrayCodes } from '../GrayCodes.js' // Import the function
1+
import { generateGrayCodes } from '../GrayCodes.js'
2+
3+
/**
4+
* Test cases for the generateGrayCodes function.
5+
*/
26

37
test('Generate Gray codes for n=3', () => {
48
const n = 3
59
const expectedGrayCodes = [0, 1, 3, 2, 6, 7, 5, 4]
610
const grayCodes = generateGrayCodes(n)
711
expect(grayCodes).toEqual(expectedGrayCodes)
812
})
13+
test('Generate Gray codes for n=0', () => {
14+
const n = 0;
15+
const expectedGrayCodes = [0];
16+
const grayCodes = generateGrayCodes(n);
17+
expect(grayCodes).toEqual(expectedGrayCodes);
18+
});
19+
20+
test('Generate Gray codes for n=1', () => {
21+
const n = 1;
22+
const expectedGrayCodes = [0, 1];
23+
const grayCodes = generateGrayCodes(n);
24+
expect(grayCodes).toEqual(expectedGrayCodes);
25+
});
26+
27+
test('Generate Gray codes for n=4', () => {
28+
const n = 4;
29+
const expectedGrayCodes = [
30+
0, 1, 3, 2, 6, 7, 5, 4, 12, 13, 15, 14, 10, 11, 9, 8
31+
];
32+
const grayCodes = generateGrayCodes(n);
33+
expect(grayCodes).toEqual(expectedGrayCodes);
34+
});
35+
36+
test('Generate Gray codes for n=5', () => {
37+
const n = 5;
38+
const expectedGrayCodes = [
39+
0, 1, 3, 2, 6, 7, 5, 4, 12, 13, 15, 14, 10, 11, 9, 8, 24, 25, 27, 26, 30, 31, 29, 28, 20, 21, 23, 22, 18, 19, 17, 16
40+
];
41+
const grayCodes = generateGrayCodes(n);
42+
expect(grayCodes).toEqual(expectedGrayCodes);
43+
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy