Skip to content

Commit aec11ac

Browse files
authored
Merge pull request #563 from sir-gon/develop
Develop
2 parents d8f3459 + 7d0849d commit aec11ac

File tree

56 files changed

+1063
-854
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1063
-854
lines changed

Makefile

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ BRUTEFORCE ?= false
2121
## (3) (4)
2222
BRUTEFORCE :=$(shell echo '${BRUTEFORCE}'| tr '[:lower:]' '[:upper:]'| tr -d '[:blank:]')
2323

24-
# DOCKER
25-
BUILDKIT_PROGRESS=plain
2624

2725
.MAIN: test
2826
.PHONY: all clean dependencies help list test
@@ -31,6 +29,9 @@ BUILDKIT_PROGRESS=plain
3129
RUNTIME_TOOL=python3
3230
PACKAGE_TOOL=pip3
3331

32+
# DOCKER
33+
BUILDKIT_PROGRESS=plain
34+
DOCKER_COMPOSE=docker compose
3435

3536
help: list
3637
@echo ""
@@ -128,34 +129,34 @@ clean:
128129
find . -path "*/__pycache__" -type d -print -exec rm -fr {} ';'
129130

130131
compose/build: env
131-
docker-compose --profile lint build
132-
docker-compose --profile testing build
133-
docker-compose --profile production build
132+
${DOCKER_COMPOSE} --profile lint build
133+
${DOCKER_COMPOSE} --profile testing build
134+
${DOCKER_COMPOSE} --profile production build
134135

135136
compose/rebuild: env
136-
docker-compose --profile lint build --no-cache
137-
docker-compose --profile testing build --no-cache
138-
docker-compose --profile production build --no-cache
137+
${DOCKER_COMPOSE} --profile lint build --no-cache
138+
${DOCKER_COMPOSE} --profile testing build --no-cache
139+
${DOCKER_COMPOSE} --profile production build --no-cache
139140

140141
compose/lint/markdown: compose/build
141-
docker-compose --profile lint run --rm algorithm-exercises-py-lint make lint/markdown
142+
${DOCKER_COMPOSE} --profile lint run --rm algorithm-exercises-py-lint make lint/markdown
142143

143144
compose/lint/yaml: compose/build
144-
docker-compose --profile lint run --rm algorithm-exercises-py-lint make lint/yaml
145+
${DOCKER_COMPOSE} --profile lint run --rm algorithm-exercises-py-lint make lint/yaml
145146

146147
compose/test/styling: compose/build
147-
docker-compose --profile lint run --rm algorithm-exercises-py-lint make test/styling
148+
${DOCKER_COMPOSE} --profile lint run --rm algorithm-exercises-py-lint make test/styling
148149

149150
compose/test/static: compose/build
150-
docker-compose --profile lint run --rm algorithm-exercises-py-lint make test/static
151+
${DOCKER_COMPOSE} --profile lint run --rm algorithm-exercises-py-lint make test/static
151152

152153
compose/lint: compose/lint/markdown compose/lint/yaml compose/test/styling compose/test/static
153154

154155
compose/test: compose/build
155-
docker-compose --profile testing run --rm algorithm-exercises-py-test make test
156+
${DOCKER_COMPOSE} --profile testing run --rm algorithm-exercises-py-test make test
156157

157158
compose/run: compose/build
158-
docker-compose --profile production run --rm algorithm-exercises-py make run
159+
${DOCKER_COMPOSE} --profile production run --rm algorithm-exercises-py make run
159160

160161
all: lint coverage
161162

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[
2+
{
3+
"title": "Sample Test Case 0",
4+
"n": 5,
5+
"queries": [[1, 2, 100],
6+
[2, 5, 100],
7+
[3, 4, 100]],
8+
"expected": 200
9+
},
10+
{
11+
"title": "Sample Test Case 1",
12+
"n": 10,
13+
"queries": [[1, 5, 3],
14+
[4, 8, 7],
15+
[6, 9, 1]],
16+
"expected": 10
17+
},
18+
{
19+
"title": "Sample Test Case 3",
20+
"n": 10,
21+
"queries": [[2, 6, 8],
22+
[3, 5, 7],
23+
[1, 8, 1],
24+
[5, 9, 15]],
25+
"expected": 31
26+
}
27+
]
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import unittest
2+
from pathlib import Path
23

4+
from ....hackerrank.lib.loader import load_test_cases
35
from .cruch_bruteforce import array_manipulation
4-
from .cruch_testcases_test import CRUCH_SMALL_TEST_CASES
6+
7+
FILE_PATH = str(Path(__file__).resolve().parent)
8+
9+
CRUCH_SMALL_TEST_CASES = load_test_cases(
10+
FILE_PATH + '/cruch.testcases.json')
511

612

713
class TestCruchBruteForce(unittest.TestCase):
@@ -11,6 +17,6 @@ def test_array_manipulation(self):
1117
for _, _tt in enumerate(CRUCH_SMALL_TEST_CASES):
1218

1319
self.assertEqual(
14-
array_manipulation(_tt['n'], _tt['queries']), _tt['answer'],
20+
array_manipulation(_tt['n'], _tt['queries']), _tt['expected'],
1521
f"{_} | array_manipulation({_tt['n']}, {_tt['queries']}) must be "
16-
f"=> {_tt['answer']}")
22+
f"=> {_tt['expected']}")
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import unittest
2+
from pathlib import Path
23

4+
from ....hackerrank.lib.loader import load_test_cases
35
from .cruch_optimized import array_manipulation_optimized
4-
from .cruch_testcases_test import CRUCH_SMALL_TEST_CASES
6+
7+
FILE_PATH = str(Path(__file__).resolve().parent)
8+
9+
CRUCH_SMALL_TEST_CASES = load_test_cases(
10+
FILE_PATH + '/cruch.testcases.json')
511

612

713
class TestCrush(unittest.TestCase):
@@ -11,6 +17,6 @@ def test_array_manipulation_optimized(self):
1117
for _, _tt in enumerate(CRUCH_SMALL_TEST_CASES):
1218

1319
self.assertEqual(
14-
array_manipulation_optimized(_tt['n'], _tt['queries']), _tt['answer'],
20+
array_manipulation_optimized(_tt['n'], _tt['queries']), _tt['expected'],
1521
f"{_} | array_manipulation_optimized({_tt['n']}, {_tt['queries']}) "
16-
f"must be => {_tt['answer']}")
22+
f"must be => {_tt['expected']}")

src/hackerrank/interview_preparation_kit/arrays/cruch_testcases_test.py

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{"input": [1, 2, 3, 4, 5], "expected": [2, 3, 4, 5, 1]},
3+
{"input": [2, 3, 4, 5, 1], "expected": [3, 4, 5, 1, 2]},
4+
{"input": [3, 4, 5, 1, 2], "expected": [4, 5, 1, 2, 3]},
5+
{"input": [4, 5, 1, 2, 3], "expected": [5, 1, 2, 3, 4]},
6+
{"input": [5, 1, 2, 3, 4], "expected": [1, 2, 3, 4, 5]}
7+
]
Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
11
import unittest
2+
from pathlib import Path
3+
4+
from ....hackerrank.lib.loader import load_test_cases
25
from .ctci_array_left_rotation import rot_left, rot_left_one
36

7+
FILE_PATH = str(Path(__file__).resolve().parent)
48

5-
class TestArrayLeftRotation(unittest.TestCase):
9+
TEST_CASES = load_test_cases(
10+
FILE_PATH + '/ctci_array_left_rotation.testcases.json')
611

7-
def test_rot_left_one(self):
812

9-
tests = [
10-
{'input': [1, 2, 3, 4, 5], 'answer': [2, 3, 4, 5, 1]},
11-
{'input': [2, 3, 4, 5, 1], 'answer': [3, 4, 5, 1, 2]},
12-
{'input': [3, 4, 5, 1, 2], 'answer': [4, 5, 1, 2, 3]},
13-
{'input': [4, 5, 1, 2, 3], 'answer': [5, 1, 2, 3, 4]},
14-
{'input': [5, 1, 2, 3, 4], 'answer': [1, 2, 3, 4, 5]},
15-
]
13+
class TestArrayLeftRotation(unittest.TestCase):
1614

17-
for _, _tt in enumerate(tests):
15+
def test_rot_left_one(self):
16+
for _, _tt in enumerate(TEST_CASES):
1817

1918
self.assertEqual(
20-
rot_left_one(_tt['input']), _tt['answer'],
19+
rot_left_one(_tt['input']), _tt['expected'],
2120
f"{_} | rot_left({_tt['input']}) must be "
22-
f"=> {_tt['answer']}")
21+
f"=> {_tt['expected']}")
2322

2423
def test_rot_left(self):
2524

2625
tests = [
27-
{'input': [1, 2, 3, 4, 5], 'd': 4, 'answer': [5, 1, 2, 3, 4]},
26+
{'input': [1, 2, 3, 4, 5], 'd': 4, 'expected': [5, 1, 2, 3, 4]},
2827
]
2928

3029
for _, _tt in enumerate(tests):
3130

3231
self.assertEqual(
33-
rot_left(_tt['input'], _tt['d']), _tt['answer'],
32+
rot_left(_tt['input'], _tt['d']), _tt['expected'],
3433
f"{_} | rot_left({_tt['input']}) must be "
35-
f"=> {_tt['answer']}")
34+
f"=> {_tt['expected']}")
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[
2+
{"title": "Sample input 0", "input": [4, 3, 1, 2], "expected": 3},
3+
{"title": "Sample input 1", "input": [2, 3, 4, 1, 5], "expected": 3},
4+
{"title": "Sample input 2", "input": [1, 3, 5, 2, 4, 6, 7], "expected": 3}
5+
]
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
import unittest
2+
from pathlib import Path
3+
4+
from ....hackerrank.lib.loader import load_test_cases
25
from .minimum_swaps_2 import minimum_swaps
36

7+
FILE_PATH = str(Path(__file__).resolve().parent)
8+
9+
TEST_CASES = load_test_cases(
10+
FILE_PATH + '/minimum_swaps_2.testcases.json')
11+
412

513
class TestMinimumSwaps(unittest.TestCase):
614

715
def test_minimum_swaps(self):
816

9-
tests = [
10-
{'title': 'Sample input 0', 'input': [4, 3, 1, 2], 'answer': 3},
11-
{'title': 'Sample input 1', 'input': [2, 3, 4, 1, 5], 'answer': 3},
12-
{'title': 'Sample input 2', 'input': [1, 3, 5, 2, 4, 6, 7], 'answer': 3},
13-
]
14-
15-
for _, _tt in enumerate(tests):
17+
for _, _tt in enumerate(TEST_CASES):
1618

1719
self.assertEqual(
18-
minimum_swaps(_tt['input']), _tt['answer'],
20+
minimum_swaps(_tt['input']), _tt['expected'],
1921
f"{_} | minimum_swaps({_tt['input']}) must be "
20-
f"=> {_tt['answer']}")
22+
f"=> {_tt['expected']}")
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[
2+
{
3+
"title": "Test Case 0-0",
4+
"input": [2, 1, 5, 3, 4],
5+
"expected": 3
6+
},
7+
{
8+
"title": "Test Case 0-1",
9+
"input": [2, 5, 1, 3, 4],
10+
"expected": "Too chaotic"
11+
},
12+
{
13+
"title": "Test Case 1-1",
14+
"input": [5, 1, 2, 3, 7, 8, 6, 4],
15+
"expected": "Too chaotic"
16+
},
17+
{
18+
"title": "Test Case 1-2",
19+
"input": [1, 2, 5, 3, 7, 8, 6, 4],
20+
"expected": 7
21+
},
22+
{
23+
"title": "Test Case 2",
24+
"input": [1, 2, 5, 3, 4, 7, 8, 6],
25+
"expected": 4
26+
}
27+
]
Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
11
import unittest
2-
from .new_year_chaos import minimum_bribes_transform, TOO_CHAOTIC_ERROR
2+
from pathlib import Path
3+
4+
from ....hackerrank.lib.loader import load_test_cases
5+
from .new_year_chaos import minimum_bribes_transform
6+
7+
FILE_PATH = str(Path(__file__).resolve().parent)
8+
9+
TEST_CASES = load_test_cases(
10+
FILE_PATH + '/new_year_chaos.testcases.json')
311

412

513
class TestMinimumBribes(unittest.TestCase):
614

715
def test_minimum_bribes(self):
816

9-
tests = [
10-
{'title': "Test Case 0-0",
11-
'input': [2, 1, 5, 3, 4], 'answer': 3},
12-
{'title': "Test Case 0-1",
13-
'input': [2, 5, 1, 3, 4], 'answer': TOO_CHAOTIC_ERROR},
14-
{'title': "Test Case 1-1",
15-
'input': [5, 1, 2, 3, 7, 8, 6, 4], 'answer': TOO_CHAOTIC_ERROR},
16-
{'title': "Test Case 1-2",
17-
'input': [1, 2, 5, 3, 7, 8, 6, 4], 'answer': 7},
18-
{'title': "Test Case 2",
19-
'input': [1, 2, 5, 3, 4, 7, 8, 6], 'answer': 4},
20-
]
21-
22-
for _, _tt in enumerate(tests):
17+
for _, _tt in enumerate(TEST_CASES):
2318

2419
self.assertEqual(
25-
minimum_bribes_transform(_tt['input']), _tt['answer'],
20+
minimum_bribes_transform(_tt['input']), _tt['expected'],
2621
f"{_} | minimum_bribes_transform({_tt['input']}) must be "
27-
f"=> {_tt['answer']}")
22+
f"=> {_tt['expected']}")
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{
3+
"title": "Sample Test Case 2",
4+
"input": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
5+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
6+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
7+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
8+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
9+
"r": 1,
10+
"expected": 161700
11+
}
12+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[
2+
{
3+
"title": "Sample Test Case 0",
4+
"input": [1, 2, 2, 4],
5+
"r": 2,
6+
"expected": 2
7+
},
8+
{
9+
"title": "Sample Test Case 1",
10+
"input": [1, 3, 9, 9, 27, 81],
11+
"r": 3,
12+
"expected": 6
13+
},
14+
{
15+
"title": "Sample Test Case 1 (unsorted)",
16+
"input": [9, 3, 1, 81, 9, 27],
17+
"r": 3,
18+
"expected": 1
19+
},
20+
{
21+
"title": "Sample Test Case 12",
22+
"input": [1, 5, 5, 25, 125],
23+
"r": 5,
24+
"expected": 4
25+
}
26+
]

0 commit comments

Comments
 (0)