Skip to content

Develop #563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7cc97d7
[REFACTOR] [CONFIG] [DOCKER] docker-compose calls replaced by new "do…
Aug 14, 2024
9c5657c
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Arrays: Array Man…
Aug 13, 2024
730d4e0
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Arrays: Left Rota…
Aug 13, 2024
4586364
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Arrays: Minimum S…
Aug 13, 2024
5e48dcb
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Arrays: New Year …
Aug 13, 2024
6fb88b9
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Dictionaries and …
Aug 13, 2024
87f0f60
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Dictionaries and …
Aug 13, 2024
02213e0
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Dictionaries and …
Aug 13, 2024
975fd47
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Dictionaries and …
Aug 13, 2024
3addd10
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Dynamic Programmi…
Aug 13, 2024
c1b1ce1
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Graphs: Roads and…
Aug 13, 2024
ecfd412
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Greedy Algorithms…
Aug 13, 2024
b628281
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Greedy Algorithms…
Aug 13, 2024
ce5596c
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Greedy Algorithms…
Aug 13, 2024
15d018c
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Greedy Algorithms…
Aug 13, 2024
f1ade3f
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Miscellaneous: Fl…
Aug 13, 2024
0320275
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Miscellaneous: Fr…
Aug 13, 2024
6310545
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Search: Swap Node…
Aug 13, 2024
5eff716
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Sorting: Bubble S…
Aug 14, 2024
aec9b37
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Sorting: Comparat…
Aug 14, 2024
0b4dfb8
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Sorting: Mark and…
Aug 14, 2024
a62f6b6
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Stacks and Queues…
Aug 14, 2024
d275862
[REFACTOR] [Hacker Rank] Interview Preparation Kit: String Manipulati…
Aug 14, 2024
0b288ad
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Strings: Making A…
Aug 14, 2024
bfbd01e
[REFACTOR] [Hacker Rank] Interview Preparation Kit: String Manipulati…
Aug 14, 2024
97725ac
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Trees: Is This a …
Aug 14, 2024
7d0849d
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Trees: Height of …
Aug 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ BRUTEFORCE ?= false
## (3) (4)
BRUTEFORCE :=$(shell echo '${BRUTEFORCE}'| tr '[:lower:]' '[:upper:]'| tr -d '[:blank:]')

# DOCKER
BUILDKIT_PROGRESS=plain

.MAIN: test
.PHONY: all clean dependencies help list test
Expand All @@ -31,6 +29,9 @@ BUILDKIT_PROGRESS=plain
RUNTIME_TOOL=python3
PACKAGE_TOOL=pip3

# DOCKER
BUILDKIT_PROGRESS=plain
DOCKER_COMPOSE=docker compose

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

compose/build: env
docker-compose --profile lint build
docker-compose --profile testing build
docker-compose --profile production build
${DOCKER_COMPOSE} --profile lint build
${DOCKER_COMPOSE} --profile testing build
${DOCKER_COMPOSE} --profile production build

compose/rebuild: env
docker-compose --profile lint build --no-cache
docker-compose --profile testing build --no-cache
docker-compose --profile production build --no-cache
${DOCKER_COMPOSE} --profile lint build --no-cache
${DOCKER_COMPOSE} --profile testing build --no-cache
${DOCKER_COMPOSE} --profile production build --no-cache

compose/lint/markdown: compose/build
docker-compose --profile lint run --rm algorithm-exercises-py-lint make lint/markdown
${DOCKER_COMPOSE} --profile lint run --rm algorithm-exercises-py-lint make lint/markdown

compose/lint/yaml: compose/build
docker-compose --profile lint run --rm algorithm-exercises-py-lint make lint/yaml
${DOCKER_COMPOSE} --profile lint run --rm algorithm-exercises-py-lint make lint/yaml

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

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

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

compose/test: compose/build
docker-compose --profile testing run --rm algorithm-exercises-py-test make test
${DOCKER_COMPOSE} --profile testing run --rm algorithm-exercises-py-test make test

compose/run: compose/build
docker-compose --profile production run --rm algorithm-exercises-py make run
${DOCKER_COMPOSE} --profile production run --rm algorithm-exercises-py make run

all: lint coverage

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[
{
"title": "Sample Test Case 0",
"n": 5,
"queries": [[1, 2, 100],
[2, 5, 100],
[3, 4, 100]],
"expected": 200
},
{
"title": "Sample Test Case 1",
"n": 10,
"queries": [[1, 5, 3],
[4, 8, 7],
[6, 9, 1]],
"expected": 10
},
{
"title": "Sample Test Case 3",
"n": 10,
"queries": [[2, 6, 8],
[3, 5, 7],
[1, 8, 1],
[5, 9, 15]],
"expected": 31
}
]
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import unittest
from pathlib import Path

from ....hackerrank.lib.loader import load_test_cases
from .cruch_bruteforce import array_manipulation
from .cruch_testcases_test import CRUCH_SMALL_TEST_CASES

FILE_PATH = str(Path(__file__).resolve().parent)

CRUCH_SMALL_TEST_CASES = load_test_cases(
FILE_PATH + '/cruch.testcases.json')


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

self.assertEqual(
array_manipulation(_tt['n'], _tt['queries']), _tt['answer'],
array_manipulation(_tt['n'], _tt['queries']), _tt['expected'],
f"{_} | array_manipulation({_tt['n']}, {_tt['queries']}) must be "
f"=> {_tt['answer']}")
f"=> {_tt['expected']}")
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import unittest
from pathlib import Path

from ....hackerrank.lib.loader import load_test_cases
from .cruch_optimized import array_manipulation_optimized
from .cruch_testcases_test import CRUCH_SMALL_TEST_CASES

FILE_PATH = str(Path(__file__).resolve().parent)

CRUCH_SMALL_TEST_CASES = load_test_cases(
FILE_PATH + '/cruch.testcases.json')


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

self.assertEqual(
array_manipulation_optimized(_tt['n'], _tt['queries']), _tt['answer'],
array_manipulation_optimized(_tt['n'], _tt['queries']), _tt['expected'],
f"{_} | array_manipulation_optimized({_tt['n']}, {_tt['queries']}) "
f"must be => {_tt['answer']}")
f"must be => {_tt['expected']}")

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{"input": [1, 2, 3, 4, 5], "expected": [2, 3, 4, 5, 1]},
{"input": [2, 3, 4, 5, 1], "expected": [3, 4, 5, 1, 2]},
{"input": [3, 4, 5, 1, 2], "expected": [4, 5, 1, 2, 3]},
{"input": [4, 5, 1, 2, 3], "expected": [5, 1, 2, 3, 4]},
{"input": [5, 1, 2, 3, 4], "expected": [1, 2, 3, 4, 5]}
]
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
import unittest
from pathlib import Path

from ....hackerrank.lib.loader import load_test_cases
from .ctci_array_left_rotation import rot_left, rot_left_one

FILE_PATH = str(Path(__file__).resolve().parent)

class TestArrayLeftRotation(unittest.TestCase):
TEST_CASES = load_test_cases(
FILE_PATH + '/ctci_array_left_rotation.testcases.json')

def test_rot_left_one(self):

tests = [
{'input': [1, 2, 3, 4, 5], 'answer': [2, 3, 4, 5, 1]},
{'input': [2, 3, 4, 5, 1], 'answer': [3, 4, 5, 1, 2]},
{'input': [3, 4, 5, 1, 2], 'answer': [4, 5, 1, 2, 3]},
{'input': [4, 5, 1, 2, 3], 'answer': [5, 1, 2, 3, 4]},
{'input': [5, 1, 2, 3, 4], 'answer': [1, 2, 3, 4, 5]},
]
class TestArrayLeftRotation(unittest.TestCase):

for _, _tt in enumerate(tests):
def test_rot_left_one(self):
for _, _tt in enumerate(TEST_CASES):

self.assertEqual(
rot_left_one(_tt['input']), _tt['answer'],
rot_left_one(_tt['input']), _tt['expected'],
f"{_} | rot_left({_tt['input']}) must be "
f"=> {_tt['answer']}")
f"=> {_tt['expected']}")

def test_rot_left(self):

tests = [
{'input': [1, 2, 3, 4, 5], 'd': 4, 'answer': [5, 1, 2, 3, 4]},
{'input': [1, 2, 3, 4, 5], 'd': 4, 'expected': [5, 1, 2, 3, 4]},
]

for _, _tt in enumerate(tests):

self.assertEqual(
rot_left(_tt['input'], _tt['d']), _tt['answer'],
rot_left(_tt['input'], _tt['d']), _tt['expected'],
f"{_} | rot_left({_tt['input']}) must be "
f"=> {_tt['answer']}")
f"=> {_tt['expected']}")
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
{"title": "Sample input 0", "input": [4, 3, 1, 2], "expected": 3},
{"title": "Sample input 1", "input": [2, 3, 4, 1, 5], "expected": 3},
{"title": "Sample input 2", "input": [1, 3, 5, 2, 4, 6, 7], "expected": 3}
]
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import unittest
from pathlib import Path

from ....hackerrank.lib.loader import load_test_cases
from .minimum_swaps_2 import minimum_swaps

FILE_PATH = str(Path(__file__).resolve().parent)

TEST_CASES = load_test_cases(
FILE_PATH + '/minimum_swaps_2.testcases.json')


class TestMinimumSwaps(unittest.TestCase):

def test_minimum_swaps(self):

tests = [
{'title': 'Sample input 0', 'input': [4, 3, 1, 2], 'answer': 3},
{'title': 'Sample input 1', 'input': [2, 3, 4, 1, 5], 'answer': 3},
{'title': 'Sample input 2', 'input': [1, 3, 5, 2, 4, 6, 7], 'answer': 3},
]

for _, _tt in enumerate(tests):
for _, _tt in enumerate(TEST_CASES):

self.assertEqual(
minimum_swaps(_tt['input']), _tt['answer'],
minimum_swaps(_tt['input']), _tt['expected'],
f"{_} | minimum_swaps({_tt['input']}) must be "
f"=> {_tt['answer']}")
f"=> {_tt['expected']}")
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[
{
"title": "Test Case 0-0",
"input": [2, 1, 5, 3, 4],
"expected": 3
},
{
"title": "Test Case 0-1",
"input": [2, 5, 1, 3, 4],
"expected": "Too chaotic"
},
{
"title": "Test Case 1-1",
"input": [5, 1, 2, 3, 7, 8, 6, 4],
"expected": "Too chaotic"
},
{
"title": "Test Case 1-2",
"input": [1, 2, 5, 3, 7, 8, 6, 4],
"expected": 7
},
{
"title": "Test Case 2",
"input": [1, 2, 5, 3, 4, 7, 8, 6],
"expected": 4
}
]
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
import unittest
from .new_year_chaos import minimum_bribes_transform, TOO_CHAOTIC_ERROR
from pathlib import Path

from ....hackerrank.lib.loader import load_test_cases
from .new_year_chaos import minimum_bribes_transform

FILE_PATH = str(Path(__file__).resolve().parent)

TEST_CASES = load_test_cases(
FILE_PATH + '/new_year_chaos.testcases.json')


class TestMinimumBribes(unittest.TestCase):

def test_minimum_bribes(self):

tests = [
{'title': "Test Case 0-0",
'input': [2, 1, 5, 3, 4], 'answer': 3},
{'title': "Test Case 0-1",
'input': [2, 5, 1, 3, 4], 'answer': TOO_CHAOTIC_ERROR},
{'title': "Test Case 1-1",
'input': [5, 1, 2, 3, 7, 8, 6, 4], 'answer': TOO_CHAOTIC_ERROR},
{'title': "Test Case 1-2",
'input': [1, 2, 5, 3, 7, 8, 6, 4], 'answer': 7},
{'title': "Test Case 2",
'input': [1, 2, 5, 3, 4, 7, 8, 6], 'answer': 4},
]

for _, _tt in enumerate(tests):
for _, _tt in enumerate(TEST_CASES):

self.assertEqual(
minimum_bribes_transform(_tt['input']), _tt['answer'],
minimum_bribes_transform(_tt['input']), _tt['expected'],
f"{_} | minimum_bribes_transform({_tt['input']}) must be "
f"=> {_tt['answer']}")
f"=> {_tt['expected']}")
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"title": "Sample Test Case 2",
"input": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
"r": 1,
"expected": 161700
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[
{
"title": "Sample Test Case 0",
"input": [1, 2, 2, 4],
"r": 2,
"expected": 2
},
{
"title": "Sample Test Case 1",
"input": [1, 3, 9, 9, 27, 81],
"r": 3,
"expected": 6
},
{
"title": "Sample Test Case 1 (unsorted)",
"input": [9, 3, 1, 81, 9, 27],
"r": 3,
"expected": 1
},
{
"title": "Sample Test Case 12",
"input": [1, 5, 5, 25, 125],
"r": 5,
"expected": 4
}
]
Loading
Loading