Skip to content

Commit 97725ac

Browse files
author
Gonzalo Diaz
committed
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Trees: Is This a Binary Search Tree?. JSON data load for unit tests.
1 parent bfbd01e commit 97725ac

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[
2+
{
3+
"title": "Test case 0",
4+
"nodes": [4, 2, 3, 1, 7, 6],
5+
"v1": 1,
6+
"v2": 7,
7+
"expected": 4
8+
},
9+
{
10+
"title": "Test case 4",
11+
"nodes": [1, 2],
12+
"v1": 1,
13+
"v2": 2,
14+
"expected": 1
15+
}
16+
]

src/hackerrank/interview_preparation_kit/trees/binary_search_tree_lowest_common_ancestor_test.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
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 .binary_search_tree_lowest_common_ancestor import lca, find
47

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

2213

2314
class TestLastCommonAncestor(unittest.TestCase):
@@ -30,9 +21,9 @@ def test_lca(self):
3021

3122
self.assertEqual(
3223
getattr(lca(tree.root, _tt['v1'], _tt['v2']), 'info', None),
33-
_tt['answer'],
24+
_tt['expected'],
3425
f"{_} | lca({tree.root}, {_tt['v1']}, {_tt['v2']}) must be "
35-
f"=> {_tt['answer']}"
26+
f"=> {_tt['expected']}"
3627
)
3728

3829
def test_find(self):

0 commit comments

Comments
 (0)