Skip to content

Commit

Permalink
# Sort Out The Men From Boys
Browse files Browse the repository at this point in the history
  • Loading branch information
ikostan committed Dec 20, 2024
1 parent 916fead commit 3943876
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 49 deletions.
1 change: 1 addition & 0 deletions kyu_7/sort_out_the_men_from_boys/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Sort Out The Men From Boys."""
10 changes: 5 additions & 5 deletions kyu_7/sort_out_the_men_from_boys/men_from_boys.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""
Solution for -> Sort Out The Men From Boys
Solution for -> Sort Out The Men From Boys.
Created by Egor Kostan.
GitHub: https://github.com/ikostan
"""

from typing import List


def men_from_boys(arr: List[int]) -> list:
def men_from_boys(arr: List[int]) -> List[int]:
"""
Sort out the men from the boys.
Expand All @@ -19,12 +20,11 @@ def men_from_boys(arr: List[int]) -> list:
Since, Men are stronger than Boys,
then Even numbers in ascending order
while odds in descending.
:param arr: list
:return: list
:param arr: List
:return: List
"""
boys: List[int] = []
men: List[int] = []

for a in arr:
if a % 2 == 0:
if a not in men:
Expand Down
86 changes: 42 additions & 44 deletions kyu_7/sort_out_the_men_from_boys/test_men_from_boys.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Test for -> Sort Out The Men From Boys
Test for -> Sort Out The Men From Boys.
Created by Egor Kostan.
GitHub: https://github.com/ikostan
"""
Expand All @@ -9,6 +10,7 @@

import unittest
import allure
from parameterized import parameterized
from utils.log_func import print_log
from kyu_7.sort_out_the_men_from_boys.men_from_boys import men_from_boys

Expand All @@ -31,14 +33,42 @@
name='Source/Kata')
# pylint: enable-msg=R0801
class MenFromBoysTestCase(unittest.TestCase):
"""
Testing men_from_boys function
"""
"""Testing men_from_boys function."""

def test_men_from_boys(self):
@parameterized.expand([
([7, 3, 14, 17],
[14, 17, 7, 3]),
([2, 43, 95, 90, 37],
[2, 90, 95, 43, 37]),
([20, 33, 50, 34, 43, 46],
[20, 34, 46, 50, 43, 33]),
([82, 91, 72, 76, 76, 100, 85],
[72, 76, 82, 100, 91, 85]),
([2, 15, 17, 15, 2, 10, 10, 17, 1, 1],
[2, 10, 17, 15, 1]),
([-32, -39, -35, -41],
[-32, -35, -39, -41]),
([-64, -71, -63, -66, -65],
[-66, -64, -63, -65, -71]),
([-94, -99, -100, -99, -96, -99],
[-100, -96, -94, -99]),
([-53, -26, -53, -27, -49, -51, -14],
[-26, -14, -27, -49, -51, -53]),
([-17, -45, -15, -33, -85, -56, -86, -30],
[-86, -56, -30, -15, -17, -33, -45, -85]),
([12, 89, -38, -78],
[-78, -38, 12, 89]),
([2, -43, 95, -90, 37],
[-90, 2, 95, 37, -43]),
([82, -61, -87, -12, 21, 1],
[-12, 82, 21, 1, -61, -87]),
([63, -57, 76, -85, 88, 2, -28],
[-28, 2, 76, 88, 63, -57, -85]),
([49, 818, -282, 900, 928, 281, -282, -1],
[-282, 818, 900, 928, 281, 49, -1])])
def test_men_from_boys(self, arr, expected):
"""
Testing men_from_boys function with
various test inputs
Testing men_from_boys function with various test inputs.
Scenario
Now that the competition gets tough it
Expand Down Expand Up @@ -70,40 +100,8 @@ def test_men_from_boys(self):
'<h3>Test Description:</h3>'
"<p></p>")
# pylint: enable-msg=R0801
with allure.step('Given an list of integers => '
'separate the even numbers from the odds'):
test_data: tuple = (
([7, 3, 14, 17],
[14, 17, 7, 3]),
([2, 43, 95, 90, 37],
[2, 90, 95, 43, 37]),
([20, 33, 50, 34, 43, 46],
[20, 34, 46, 50, 43, 33]),
([82, 91, 72, 76, 76, 100, 85],
[72, 76, 82, 100, 91, 85]),
([2, 15, 17, 15, 2, 10, 10, 17, 1, 1],
[2, 10, 17, 15, 1]),
([-32, -39, -35, -41],
[-32, -35, -39, -41]),
([-64, -71, -63, -66, -65],
[-66, -64, -63, -65, -71]),
([-94, -99, -100, -99, -96, -99],
[-100, -96, -94, -99]),
([-53, -26, -53, -27, -49, -51, -14],
[-26, -14, -27, -49, -51, -53]),
([-17, -45, -15, -33, -85, -56, -86, -30],
[-86, -56, -30, -15, -17, -33, -45, -85]),
([12, 89, -38, -78],
[-78, -38, 12, 89]),
([2, -43, 95, -90, 37],
[-90, 2, 95, 37, -43]),
([82, -61, -87, -12, 21, 1],
[-12, 82, 21, 1, -61, -87]),
([63, -57, 76, -85, 88, 2, -28],
[-28, 2, 76, 88, 63, -57, -85]),
([49, 818, -282, 900, 928, 281, -282, -1],
[-282, 818, 900, 928, 281, 49, -1]))

for arr, expected in test_data:
print_log(arr=arr, expected=expected)
self.assertEqual(expected, men_from_boys(arr))
with allure.step(f'Given an list of integers => {arr}'
f'separate the even numbers from the odds'
f' and verify the expected result: {expected}.'):
print_log(arr=arr, expected=expected)
self.assertEqual(expected, men_from_boys(arr))

0 comments on commit 3943876

Please sign in to comment.