Skip to content

Commit bfbd01e

Browse files
author
Gonzalo Diaz
committed
[REFACTOR] [Hacker Rank] Interview Preparation Kit: String Manipulation: Sherlock and the Valid String. JSON data load for unit tests.
1 parent 0b288ad commit bfbd01e

File tree

2 files changed

+55
-49
lines changed

2 files changed

+55
-49
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
[
2+
{
3+
"title": "counterexample",
4+
"input": "aabbccc",
5+
"expected": true
6+
},
7+
{
8+
"title": "counterexample",
9+
"input": "a",
10+
"expected": true
11+
},
12+
{
13+
"title": "counterexample",
14+
"input": "aaa",
15+
"expected": true
16+
},
17+
{
18+
"title": "counterexample",
19+
"input": "abbccc",
20+
"expected": false
21+
},
22+
{
23+
"title": "counterexample",
24+
"input": "bbccc",
25+
"expected": false
26+
},
27+
{
28+
"title": "Sample Test case 0",
29+
"input": "aabbcd",
30+
"expected": false
31+
},
32+
{
33+
"title": "Sample Test case 1",
34+
"input": "aabbccddeefghi",
35+
"expected": false
36+
},
37+
{
38+
"title": "Sample Test case 2",
39+
"input": "abcdefghhgfedecba",
40+
"expected": true
41+
},
42+
{
43+
"title": "Sample Test case 4",
44+
"input": "aabbc",
45+
"expected": true
46+
}
47+
]
Lines changed: 8 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,12 @@
11
import unittest
2+
from pathlib import Path
3+
4+
from ....hackerrank.lib.loader import load_test_cases
25
from .sherlock_and_valid_string import is_valid
36

4-
TEST_CASES = [
5-
{
6-
'title': 'counterexample',
7-
'input': 'aabbccc',
8-
'answer': True
9-
},
10-
{
11-
'title': 'counterexample',
12-
'input': 'a',
13-
'answer': True
14-
},
15-
{
16-
'title': 'counterexample',
17-
'input': 'aaa',
18-
'answer': True
19-
},
20-
{
21-
'title': 'counterexample',
22-
'input': 'abbccc',
23-
'answer': False
24-
},
25-
{
26-
'title': 'counterexample',
27-
'input': 'bbccc',
28-
'answer': False
29-
},
30-
{
31-
'title': 'Sample Test case 0',
32-
'input': 'aabbcd',
33-
'answer': False
34-
},
35-
{
36-
'title': 'Sample Test case 1',
37-
'input': 'aabbccddeefghi',
38-
'answer': False
39-
},
40-
{
41-
'title': 'Sample Test case 2',
42-
'input': 'abcdefghhgfedecba',
43-
'answer': True
44-
},
45-
{
46-
'title': 'Sample Test case 4',
47-
'input': 'aabbc',
48-
'answer': True
49-
}
50-
]
7+
FILE_PATH = str(Path(__file__).resolve().parent)
8+
9+
TEST_CASES = load_test_cases(FILE_PATH + '/sherlock_and_valid_string.testcases.json')
5110

5211

5312
class TestSherklockAndValidString(unittest.TestCase):
@@ -57,6 +16,6 @@ def test_is_valid(self):
5716
for _, _tt in enumerate(TEST_CASES):
5817

5918
self.assertEqual(
60-
is_valid(_tt['input']), _tt['answer'],
19+
is_valid(_tt['input']), _tt['expected'],
6120
f"{_} | is_valid({_tt['input']}) must be "
62-
f"=> {_tt['answer']}")
21+
f"=> {_tt['expected']}")

0 commit comments

Comments
 (0)