|
1 | 1 | import { describe, expect, it } from '@jest/globals';
|
2 | 2 |
|
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'; |
4 | 5 | import TESTCASES from './swap_nodes_algo.testcases.json';
|
5 | 6 |
|
6 | 7 | describe('swap_nodes_algo', () => {
|
7 | 8 | it('testbuildTree_empty', () => {
|
8 |
| - expect.assertions(2); |
| 9 | + expect.assertions(4); |
9 | 10 |
|
10 |
| - const tInput = []; |
11 |
| - const tree = new Tree(tInput); |
| 11 | + const input = []; |
| 12 | + const tree = new Tree(input); |
12 | 13 | const expected = [1];
|
13 | 14 |
|
14 | 15 | expect(tree.flatTree()).toStrictEqual(expected);
|
15 | 16 | expect(tree.getRoot()).not.toBeNull();
|
| 17 | + expect(tree.getRoot()).toBeInstanceOf(Node); |
| 18 | + expect(tree.getRoot().data).toBe(__INITIAL_LEVEL__); |
16 | 19 | });
|
17 | 20 |
|
18 | 21 | it('testbuild_malformed_tree', () => {
|
19 |
| - expect.assertions(1); |
| 22 | + expect.assertions(4); |
20 | 23 |
|
21 | 24 | const input = [[], []];
|
22 | 25 | const tree = new Tree(input);
|
23 | 26 | const tresult = tree.flatTree();
|
24 |
| - const expected = [1]; |
| 27 | + const expected = [__INITIAL_LEVEL__]; |
25 | 28 |
|
26 | 29 | expect(tresult).toStrictEqual(expected);
|
| 30 | + expect(tree.getRoot()).not.toBeNull(); |
| 31 | + expect(tree.getRoot()).toBeInstanceOf(Node); |
| 32 | + expect(tree.getRoot().data).toBe(__INITIAL_LEVEL__); |
27 | 33 | });
|
28 | 34 |
|
29 | 35 | it('build tree and flattened tree test cases', () => {
|
|
0 commit comments