Skip to content

Commit f311f10

Browse files
author
Gonzalo Diaz
committed
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Trees: Height of a Binary Trees. JSON data load for unit tests.
1 parent b3e9e85 commit f311f10

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[
2+
{
3+
"title": "Test case 0",
4+
"nodes": [3, 5, 2, 1, 4, 6, 7],
5+
"expected": 3
6+
},
7+
{
8+
"title": "Test case 4",
9+
"nodes": [15],
10+
"expected": 0
11+
},
12+
{
13+
"title": "Test case 5",
14+
"nodes": [3, 1, 7, 5, 4],
15+
"expected": 3
16+
}
17+
]
Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,21 @@
11
import unittest
2+
from pathlib import Path
3+
4+
from ....hackerrank.lib.loader import load_test_cases
25
from ...lib.tree import BinarySearchTree
36
from .tree_height_of_a_binary_tree import height
47

5-
TEST_CASES = [
6-
{
7-
'title': 'Test case 0',
8-
'nodes': [3, 5, 2, 1, 4, 6, 7],
9-
'answer': 3
10-
},
11-
{
12-
'title': 'Test case 4',
13-
'nodes': [15],
14-
'answer': 0
15-
},
16-
{
17-
'title': 'Test case 5',
18-
'nodes': [3, 1, 7, 5, 4],
19-
'answer': 3
20-
}
21-
]
8+
FILE_PATH = str(Path(__file__).resolve().parent)
9+
10+
TEST_CASES = load_test_cases(
11+
FILE_PATH + '/tree_height_of_a_binary_tree.testcases.json')
2212

2313

2414
TEST_CASES_BORDER_CASE = [
2515
{
2616
'title': 'Test case 0',
2717
'nodes': [1, 1, 1],
28-
'answer': 0
18+
'expected': 0
2919
}
3020
]
3121

@@ -42,9 +32,9 @@ def test_height(self):
4232
tree.create(nodes)
4333

4434
self.assertEqual(
45-
height(tree.root), _tt['answer'],
35+
height(tree.root), _tt['expected'],
4636
f"{_} | height({tree.root}) must be "
47-
f"=> {_tt['answer']}")
37+
f"=> {_tt['expected']}")
4838

4939
def test_height_border_case(self):
5040

@@ -56,6 +46,6 @@ def test_height_border_case(self):
5646
tree.create(nodes)
5747

5848
self.assertEqual(
59-
height(tree.root), _tt['answer'],
49+
height(tree.root), _tt['expected'],
6050
f"{_} | height({tree.root}) must be "
61-
f"=> {_tt['answer']}")
51+
f"=> {_tt['expected']}")

0 commit comments

Comments
 (0)