Skip to content

Commit 1ce34ec

Browse files
author
Gonzalo Diaz
committed
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Strings: Making Anagrams. JSON data load for unit tests.
1 parent d3f7eb6 commit 1ce34ec

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[
2+
{
3+
"title": "Sample Test case 0",
4+
"a": "cde",
5+
"b": "abc",
6+
"expected": 4
7+
},
8+
{
9+
"title": "Sample Test case 1",
10+
"a": "fcrxzwscanmligyxyvym",
11+
"b": "jxwtrhvujlmrpdoqbisbwhmgpmeoke",
12+
"expected": 30
13+
},
14+
{
15+
"title": "Sample Test case 2",
16+
"a": "showman",
17+
"b": "woman",
18+
"expected": 2
19+
}
20+
]
Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
11
import unittest
2+
from pathlib import Path
3+
4+
from ....hackerrank.lib.loader import load_test_cases
25
from .ctci_making_anagrams import make_anagram
36

4-
TEST_CASES = [
5-
{
6-
'title': 'Sample Test case 0',
7-
'a': 'cde',
8-
'b': 'abc',
9-
'answer': 4
10-
},
11-
{
12-
'title': 'Sample Test case 1',
13-
'a': 'fcrxzwscanmligyxyvym',
14-
'b': 'jxwtrhvujlmrpdoqbisbwhmgpmeoke',
15-
'answer': 30
16-
},
17-
{
18-
'title': 'Sample Test case 2',
19-
'a': 'showman',
20-
'b': 'woman',
21-
'answer': 2
22-
}
23-
]
7+
FILE_PATH = str(Path(__file__).resolve().parent)
8+
9+
TEST_CASES = load_test_cases(FILE_PATH + '/ctci_making_anagrams.testcases.json')
2410

2511

2612
class TestMakeAnagram(unittest.TestCase):
@@ -30,6 +16,6 @@ def test_make_anagram(self):
3016
for _, _tt in enumerate(TEST_CASES):
3117

3218
self.assertEqual(
33-
make_anagram(_tt['a'], _tt['b']), _tt['answer'],
19+
make_anagram(_tt['a'], _tt['b']), _tt['expected'],
3420
f"{_} | make_anagram({_tt['a']}, {_tt['b']}) must be "
35-
f"=> {_tt['answer']}")
21+
f"=> {_tt['expected']}")

0 commit comments

Comments
 (0)