Skip to content

Commit 6972415

Browse files
author
Gonzalo Diaz
committed
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Search: Swap Nodes [Algo]. Big test case added.
1 parent d4bfa92 commit 6972415

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { describe, expect, it } from '@jest/globals';
2+
3+
import { Node } from '../../lib/Node';
4+
import { swapNodes, build_tree, flat_tree } from './swap_nodes_algo';
5+
import BIG_TEST_CASES from './swap_nodes_algo.big.testcases.json';
6+
7+
describe('swap_nodes_algo', () => {
8+
it('build_tree and plain test cases', () => {
9+
expect.assertions(1);
10+
11+
BIG_TEST_CASES.forEach((test) => {
12+
const t_to_test: Node<number> = build_tree(test.nodes);
13+
const t_result: number[] = flat_tree(t_to_test);
14+
15+
expect(t_result).toStrictEqual(test.flattened);
16+
});
17+
});
18+
19+
it('swapNodes test cases', () => {
20+
expect.assertions(1);
21+
22+
BIG_TEST_CASES.forEach((test) => {
23+
const t_result: number[][] = swapNodes(test.nodes, test.queries);
24+
25+
expect(t_result).toStrictEqual(test.expected);
26+
});
27+
});
28+
});

0 commit comments

Comments
 (0)