Skip to content

Commit d3f7eb6

Browse files
author
Gonzalo Diaz
committed
[REFACTOR] [Hacker Rank] Interview Preparation Kit: String Manipulation: Alternating Characters. JSON data load for unit tests.
1 parent 7cc5f56 commit d3f7eb6

File tree

2 files changed

+61
-55
lines changed

2 files changed

+61
-55
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
[
2+
{
3+
"title": "Sample Test case 0",
4+
"tests": [
5+
{
6+
"input": "AAAA",
7+
"expected": 3
8+
},
9+
{
10+
"input": "BBBBB",
11+
"expected": 4
12+
},
13+
{
14+
"input": "ABABABAB",
15+
"expected": 0
16+
},
17+
{
18+
"input": "BABABA",
19+
"expected": 0
20+
},
21+
{
22+
"input": "AAABBB",
23+
"expected": 4
24+
}
25+
]
26+
},
27+
{
28+
"title": "Sample Test case 13",
29+
"tests": [
30+
{
31+
"input": "AAABBBAABB",
32+
"expected": 6
33+
},
34+
{
35+
"input": "AABBAABB",
36+
"expected": 4
37+
},
38+
{
39+
"input": "ABABABAA",
40+
"expected": 1
41+
}
42+
]
43+
},
44+
{
45+
"title": "Sample Test case 14",
46+
"tests": [
47+
{
48+
"input": "ABBABBAA",
49+
"expected": 3
50+
}
51+
]
52+
}
53+
]
Lines changed: 8 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,12 @@
11
import unittest
2+
from pathlib import Path
3+
4+
from ....hackerrank.lib.loader import load_test_cases
25
from .alternating_characters import alternating_characters
36

4-
TEST_CASES = [
5-
{
6-
'title': 'Sample Test case 0',
7-
'tests': [
8-
{
9-
'input': 'AAAA',
10-
'answer': 3
11-
},
12-
{
13-
'input': 'BBBBB',
14-
'answer': 4
15-
},
16-
{
17-
'input': 'ABABABAB',
18-
'answer': 0
19-
},
20-
{
21-
'input': 'BABABA',
22-
'answer': 0
23-
},
24-
{
25-
'input': 'AAABBB',
26-
'answer': 4
27-
}
28-
]
29-
},
30-
{
31-
'title': 'Sample Test case 13',
32-
'tests': [
33-
{
34-
'input': 'AAABBBAABB',
35-
'answer': 6
36-
},
37-
{
38-
'input': 'AABBAABB',
39-
'answer': 4
40-
},
41-
{
42-
'input': 'ABABABAA',
43-
'answer': 1
44-
}
45-
]
46-
},
47-
{
48-
'title': 'Sample Test case 14',
49-
'tests': [
50-
{
51-
'input': 'ABBABBAA',
52-
'answer': 3
53-
}
54-
]
55-
}
56-
]
7+
FILE_PATH = str(Path(__file__).resolve().parent)
8+
9+
TEST_CASES = load_test_cases(FILE_PATH + '/alternating_characters.testcases.json')
5710

5811

5912
class TestAlternatingCharacters(unittest.TestCase):
@@ -65,6 +18,6 @@ def test_alternating_characters(self):
6518
for _, _tt in enumerate(testset['tests']):
6619

6720
self.assertEqual(
68-
alternating_characters(_tt['input']), _tt['answer'],
21+
alternating_characters(_tt['input']), _tt['expected'],
6922
f"{_} | alternating_characters({_tt['input']}) must be "
70-
f"=> {_tt['answer']}")
23+
f"=> {_tt['expected']}")

0 commit comments

Comments
 (0)