|
1 | 1 | import unittest
|
| 2 | +from pathlib import Path |
| 3 | + |
| 4 | +from ....hackerrank.lib.loader import load_test_cases |
2 | 5 | from .swap_nodes_algo import swap_nodes, build_tree, plain_tree, swap_branch
|
3 | 6 |
|
| 7 | +FILE_PATH = str(Path(__file__).resolve().parent) |
| 8 | +TEST_CASES = load_test_cases(FILE_PATH + '/swap_nodes_algo.testcases.json') |
4 | 9 |
|
5 |
| -class TestSwapNodesAlgo(unittest.TestCase): |
6 | 10 |
|
7 |
| - tests = [ |
8 |
| - { |
9 |
| - 'title': 'Sample 0', |
10 |
| - 'nodes': [[2, 3], [-1, -1], [-1, -1]], |
11 |
| - 'queries': [1, 1], |
12 |
| - 'answer': [[3, 1, 2], [2, 1, 3]] |
13 |
| - }, |
14 |
| - { |
15 |
| - 'title': 'Sample 1', |
16 |
| - 'nodes': [[2, 3], [-1, 4], [-1, 5], [-1, -1], [-1, -1]], |
17 |
| - 'queries': [2], |
18 |
| - 'answer': [[4, 2, 1, 5, 3]] |
19 |
| - }, |
20 |
| - { |
21 |
| - 'title': 'Sample 2', |
22 |
| - 'nodes': [[2, 3], [4, -1], [5, -1], [6, -1], [7, 8], [-1, 9], |
23 |
| - [-1, -1], [10, 11], [-1, -1], [-1, -1], [-1, -1]], |
24 |
| - 'queries': [2, 4], |
25 |
| - 'answer': [[2, 9, 6, 4, 1, 3, 7, 5, 11, 8, 10], |
26 |
| - [2, 6, 9, 4, 1, 3, 7, 5, 10, 8, 11]] |
27 |
| - }, |
28 |
| - { |
29 |
| - 'title': 'Sample Test Case 1', |
30 |
| - 'nodes': [[2, 3], [4, 5], [6, -1], [-1, 7], [8, 9], [10, 11], [12, 13], |
31 |
| - [-1, 14], [-1, -1], [15, -1], [16, 17], [-1, -1], [-1, -1], |
32 |
| - [-1, -1], [-1, -1], [-1, -1], [-1, -1]], |
33 |
| - 'queries': [2, 3], |
34 |
| - 'answer': [[14, 8, 5, 9, 2, 4, 13, 7, 12, 1, 3, 10, 15, 6, 17, 11, 16], |
35 |
| - [9, 5, 14, 8, 2, 13, 7, 12, 4, 1, 3, 17, 11, 16, 6, 10, 15]] |
36 |
| - } |
37 |
| - ] |
| 11 | +class TestSwapNodesAlgo(unittest.TestCase): |
38 | 12 |
|
39 | 13 | def test_swap_nodes(self):
|
40 | 14 |
|
41 |
| - for _, _tt in enumerate(self.tests): |
| 15 | + for _, _tt in enumerate(TEST_CASES): |
42 | 16 |
|
43 | 17 | self.assertEqual(
|
44 | 18 | swap_nodes(_tt['nodes'], _tt['queries']), _tt['answer'],
|
|
0 commit comments