Skip to content

Commit 7033f28

Browse files
author
Gonzalo Diaz
committed
[Hacker Rank] Interview Preparation Kit: Greedy Algorithms: Minimum Absolute Difference in an Array. JSON data load for unit tests.
1 parent f8080cd commit 7033f28

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[
2+
{
3+
"title": "Sample Test case 0",
4+
"input": [3, -7, 0],
5+
"expected": 3
6+
},
7+
{
8+
"title": "Sample Test case 1",
9+
"input": [-59, -36, -13, 1, -53, -92, -2, -96, -54, 75],
10+
"expected": 1
11+
},
12+
{
13+
"title": "Sample Test case 2",
14+
"input": [1, -3, 71, 68, 17],
15+
"expected": 3
16+
}
17+
]
Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
import unittest
2+
from pathlib import Path
3+
4+
from ....hackerrank.lib.loader import load_test_cases
25
from .minimum_absolute_difference_in_an_array import minimum_absolute_difference
36

4-
TEST_CASES = [
5-
{
6-
'title': 'Sample Test case 0',
7-
'input': [3, -7, 0],
8-
'answer': 3
9-
},
10-
{
11-
'title': 'Sample Test case 1',
12-
'input': [-59, -36, -13, 1, -53, -92, -2, -96, -54, 75],
13-
'answer': 1
14-
},
15-
{
16-
'title': 'Sample Test case 2',
17-
'input': [1, -3, 71, 68, 17],
18-
'answer': 3
19-
}
20-
]
7+
FILE_PATH = str(Path(__file__).resolve().parent)
8+
9+
TEST_CASES = load_test_cases(
10+
FILE_PATH + '/minimum_absolute_difference_in_an_array.testcases.json')
2111

2212

2313
class TestMinimumAbsoluteDifference(unittest.TestCase):
@@ -27,6 +17,6 @@ def test_minimum_absolute_difference(self):
2717
for _, _tt in enumerate(TEST_CASES):
2818

2919
self.assertEqual(
30-
minimum_absolute_difference(_tt['input']), _tt['answer'],
20+
minimum_absolute_difference(_tt['input']), _tt['expected'],
3121
f"{_} | minimum_absolute_difference({_tt['input']}) must be "
32-
f"=> {_tt['answer']}")
22+
f"=> {_tt['expected']}")

0 commit comments

Comments
 (0)