Skip to content

Commit 1cb7cf4

Browse files
author
Gonzalo Diaz
committed
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Search: Swap Nodes [Algo]. New tests added.
1 parent 8586556 commit 1cb7cf4

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/hackerrank/interview_preparation_kit/search/swap_nodes_algo.test.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
11
import { describe, expect, it } from '@jest/globals';
22

3-
import { Tree, swapNodes } from './swap_nodes_algo.js';
3+
import { Node } from '../../lib/Node.js';
4+
import { Tree, swapNodes, __INITIAL_LEVEL__ } from './swap_nodes_algo.js';
45
import TESTCASES from './swap_nodes_algo.testcases.json';
56

67
describe('swap_nodes_algo', () => {
78
it('testbuildTree_empty', () => {
8-
expect.assertions(2);
9+
expect.assertions(4);
910

10-
const tInput = [];
11-
const tree = new Tree(tInput);
11+
const input = [];
12+
const tree = new Tree(input);
1213
const expected = [1];
1314

1415
expect(tree.flatTree()).toStrictEqual(expected);
1516
expect(tree.getRoot()).not.toBeNull();
17+
expect(tree.getRoot()).toBeInstanceOf(Node);
18+
expect(tree.getRoot().data).toBe(__INITIAL_LEVEL__);
1619
});
1720

1821
it('testbuild_malformed_tree', () => {
19-
expect.assertions(1);
22+
expect.assertions(4);
2023

2124
const input = [[], []];
2225
const tree = new Tree(input);
2326
const tresult = tree.flatTree();
24-
const expected = [1];
27+
const expected = [__INITIAL_LEVEL__];
2528

2629
expect(tresult).toStrictEqual(expected);
30+
expect(tree.getRoot()).not.toBeNull();
31+
expect(tree.getRoot()).toBeInstanceOf(Node);
32+
expect(tree.getRoot().data).toBe(__INITIAL_LEVEL__);
2733
});
2834

2935
it('build tree and flattened tree test cases', () => {

0 commit comments

Comments
 (0)