Skip to content
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

Kyu6 #541

Merged
merged 17 commits into from
Nov 24, 2024
8 changes: 4 additions & 4 deletions kyu_6/scheduling/test_solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
GitHub: https://github.com/ikostan
"""

# Scheduling Queues Algorithms
# SCHEDULING QUEUES ALGORITHMS

import unittest
import allure
Expand All @@ -19,20 +19,20 @@
@allure.sub_suite("Unit Tests")
@allure.feature("Algorithms")
@allure.story('Scheduling (Shortest Job First or SJF)')
@allure.tag('Scheduling', 'Queues', 'Algorithms')
@allure.tag('SCHEDULING', 'QUEUES', 'ALGORITHMS')
@allure.link(
url='https://www.codewars.com/kata/550cc572b9e7b563be00054f',
name='Source/Kata')
# pylint: enable-msg=R0801
class SJFTestCase(unittest.TestCase):
"""
Testing 'shortest_job_first(' function
Testing 'shortest_job_first' function
"""

# pylint: disable-msg=R0801
def test_sjf(self):
"""
Testing 'shortest_job_first(' function with various test data
Testing 'shortest_job_first' function with various test data
:return:
"""
allure.dynamic.title("Testing 'shortest_job_first(' function")
Expand Down
44 changes: 44 additions & 0 deletions kyu_6/sums_of_parts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Sums of Parts

Let us consider this example (array written in general format):

```bash
ls = [0, 1, 3, 6, 10]
```

It's following parts:

```bash
ls = [0, 1, 3, 6, 10]
ls = [1, 3, 6, 10]
ls = [3, 6, 10]
ls = [6, 10]
ls = [10]
ls = []
```

The corresponding sums are (put together in a list):

```bash
[20, 20, 19, 16, 10, 0]
```

The function parts_sums (or its variants in other languages) will take as
parameter a list ls and return a list of the sums of its parts as defined above.

Other Examples:

```bash
ls = [1, 2, 3, 4, 5, 6]
parts_sums(ls) -> [21, 20, 18, 15, 11, 6, 0]

ls = [744125, 935, 407, 454, 430, 90, 144, 6710213, 889, 810, 2579358]
parts_sums(ls) -> [10037855, 9293730, 9292795, 9292388, 9291934, 9291504, 9291414, 9291270, 2581057, 2580168, 2579358, 0]
```

## Notes

- Take a look at performance: some lists have thousands of elements.
- Please ask before translating.

[Source](https://www.codewars.com/kata/5ce399e0047a45001c853c2b/python)
Empty file added kyu_6/sums_of_parts/__init__.py
Empty file.
15 changes: 15 additions & 0 deletions kyu_6/sums_of_parts/solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
Test for -> Sums of Parts
Created by Egor Kostan.
GitHub: https://github.com/ikostan
"""


def parts_sums(ls: list) -> list:

Check notice on line 8 in kyu_6/sums_of_parts/solution.py

View check run for this annotation

codefactor.io / CodeFactor

kyu_6/sums_of_parts/solution.py#L8

Unused argument 'ls' (unused-argument)
ikostan marked this conversation as resolved.
Show resolved Hide resolved
ikostan marked this conversation as resolved.
Show resolved Hide resolved
"""
The function parts_sums will take as parameter a list ls
and return a list of the sums of its parts.
:param ls:
:return:
"""
pass

Check notice on line 15 in kyu_6/sums_of_parts/solution.py

View check run for this annotation

codefactor.io / CodeFactor

kyu_6/sums_of_parts/solution.py#L15

Unnecessary pass statement (unnecessary-pass)
ikostan marked this conversation as resolved.
Show resolved Hide resolved
73 changes: 73 additions & 0 deletions kyu_6/sums_of_parts/test_solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"""
Test for -> Sums of Parts
Created by Egor Kostan.
GitHub: https://github.com/ikostan
"""

# Fundamentals Performance Algorithms

import unittest
import allure
ikostan marked this conversation as resolved.
Show resolved Hide resolved
from utils.log_func import print_log
from kyu_6.sums_of_parts.solution import parts_sums


# pylint: disable-msg=R0801
@allure.epic('6 kyu')
@allure.parent_suite('Novice')
@allure.suite("Fundamentals")
@allure.sub_suite("Unit Tests")
@allure.feature("Algorithms")
@allure.story('Sums of Parts')
@allure.tag('FUNDAMENTALS',
'PERFORMANCE',
'ALGORITHMS')
@allure.link(
url='https://www.codewars.com/kata/5ce399e0047a45001c853c2b',
name='Source/Kata')
# pylint: enable-msg=R0801
class SJFTestCase(unittest.TestCase):
"""
Testing 'parts_sums' function
"""

# pylint: disable-msg=R0801
def test_sjf(self):
"""
Testing 'parts_sums' function with various test data
:return:
"""
allure.dynamic.title("Testing 'parts_sums' function")
allure.dynamic.severity(allure.severity_level.NORMAL)
allure.dynamic.description_html(
'<h3>Codewars badge:</h3>'
'<img src="https://www.codewars.com/users/myFirstCode'
'/badges/large">'
'<h3>Test Description:</h3>'
"<p>Test a function that take as parameter a list ls and "
"return a list of the sums of its parts as defined below:<br>"
"ls = [1, 2, 3, 4, 5, 6]<br>"
"parts_sums(ls) -> [21, 20, 18, 15, 11, 6, 0]"
"</p>")
# pylint: enable-msg=R0801
test_data: tuple = (
([1, 2, 3, 4, 5, 6], [21, 20, 18, 15, 11, 6, 0]),
([0, 1, 3, 6, 10], [20, 20, 19, 16, 10, 0]),
([744125, 935, 407, 454, 430, 90, 144, 6710213, 889, 810, 2579358],
[10037855, 9293730, 9292795, 9292388, 9291934, 9291504, 9291414,
9291270, 2581057, 2580168, 2579358, 0]))

for ls, expected in test_data:
ikostan marked this conversation as resolved.
Show resolved Hide resolved
actual_result = parts_sums(ls)
ikostan marked this conversation as resolved.
Show resolved Hide resolved
# pylint: disable-msg=R0801
with allure.step(f"Enter a list ls ({ls}) and verify the "
f"expected output ({expected}) vs "
f"actual result ({actual_result})"):

print_log(ls=ls,
expected=expected,
result=actual_result)

self.assertEqual(expected,
actual_result)
# pylint: enable-msg=R0801
Loading