diff --git a/.github/workflows/pydocstyle_kyu8.yml b/.github/workflows/pydocstyle_kyu8.yml new file mode 100644 index 00000000000..0757b0c333b --- /dev/null +++ b/.github/workflows/pydocstyle_kyu8.yml @@ -0,0 +1,46 @@ +--- +name: pydocstyle for kyu8 + +on: # yamllint disable-line rule:truthy + push: + branches: + - 'kyu8' + +permissions: + contents: read + pull-requests: read + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.x"] + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + # This is the version of the action for setting up Python, + # not the Python version. + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + # You can test your matrix by printing the current Python version + - name: Display Python version + run: python -c "import sys; print(sys.version)" + - name: Install dependencies + run: | + python -m pip install --upgrade pip setuptools wheel + pip install -r requirements.txt + pip install pydocstyle + pip install types-requests + - name: Check to make sure that the module is in your Python path + run: | + echo $PYTHONPATH + - name: Check pydocstyle version + run: | + pydocstyle --version + - name: Doc style checking with pydocstyle + # Pydocstyle testing (Guide) + # https://www.pydocstyle.org/en/stable/usage.html#cli-usage + run: | + pydocstyle --verbose --explain --count kyu_8 diff --git a/docs/kyu_8/kyu_8.closest_elevator.rst b/docs/kyu_8/kyu_8.closest_elevator.rst new file mode 100644 index 00000000000..87d8946ffa8 --- /dev/null +++ b/docs/kyu_8/kyu_8.closest_elevator.rst @@ -0,0 +1,32 @@ +kyu\_8.closest\_elevator package +================================ + +Submodules +---------- + +kyu\_8.closest\_elevator.closest\_elevator module +------------------------------------------------- + +.. automodule:: kyu_8.closest_elevator.closest_elevator + :members: + :undoc-members: + :show-inheritance: + :private-members: + +kyu\_8.closest\_elevator.test\_closest\_elevator module +------------------------------------------------------- + +.. automodule:: kyu_8.closest_elevator.test_closest_elevator + :members: + :undoc-members: + :show-inheritance: + :private-members: + +Module contents +--------------- + +.. automodule:: kyu_8.closest_elevator + :members: + :undoc-members: + :show-inheritance: + :private-members: diff --git a/docs/kyu_8/kyu_8.greek_sort.rst b/docs/kyu_8/kyu_8.greek_sort.rst index 8d34ffa8d2d..640c357c1c5 100644 --- a/docs/kyu_8/kyu_8.greek_sort.rst +++ b/docs/kyu_8/kyu_8.greek_sort.rst @@ -4,19 +4,19 @@ kyu\_8.greek\_sort package Submodules ---------- -kyu\_8.greek\_sort.greek\_comparator module -------------------------------------------- +kyu\_8.greek\_sort.evaluator module +----------------------------------- -.. automodule:: kyu_8.greek_sort.greek_comparator +.. automodule:: kyu_8.greek_sort.evaluator :members: :undoc-members: :show-inheritance: :private-members: -kyu\_8.greek\_sort.evaluator module +kyu\_8.greek\_sort.greek\_comparator module ------------------------------------------- -.. automodule:: kyu_8.greek_sort.evaluator +.. automodule:: kyu_8.greek_sort.greek_comparator :members: :undoc-members: :show-inheritance: diff --git a/docs/kyu_8/kyu_8.rst b/docs/kyu_8/kyu_8.rst index 4ebf3f9ed13..a144d283b9c 100644 --- a/docs/kyu_8/kyu_8.rst +++ b/docs/kyu_8/kyu_8.rst @@ -11,6 +11,7 @@ Subpackages kyu_8.alternating_case kyu_8.century_from_year kyu_8.check_the_exam + kyu_8.closest_elevator kyu_8.convert_string_to_an_array kyu_8.count_the_monkeys kyu_8.counting_sheep diff --git a/kyu_8/README.md b/kyu_8/README.md index 31f86dbec1c..739f1ecf7ce 100644 --- a/kyu_8/README.md +++ b/kyu_8/README.md @@ -15,44 +15,45 @@ harder the kata the faster you advance. ### List of Completed Kata (Python 3) -| No. | Puzzle/Kata Name | Solution / GitHub Link | -|-----|-------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------| -|1 |[altERnaTIng cAsE <=> ALTerNAtiNG CaSe](https://www.codewars.com/kata/56efc695740d30f963000557) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/alternating_case) | -|2 |[Check the exam](https://www.codewars.com/kata/5a3dd29055519e23ec000074) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/check_the_exam) | -|3 |[Counting sheep...](https://www.codewars.com/kata/54edbc7200b811e956000556) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/counting_sheep) | -|4 |[Find the first non-consecutive number](https://www.codewars.com/kata/58f8a3a27a5c28d92e000144) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/find_the_first_non_consecutive_number)| -|5 |[Grasshopper - Check for Factor](https://www.codewars.com/kata/55cbc3586671f6aa070000fb) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/grasshopper_check_for_factor) | -|6 |[Grasshopper - Messi goals function](https://www.codewars.com/kata/55f73be6e12baaa5900000d4) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/grasshopper_messi_goals_function) | -|7 |[Grasshopper - Personalized Message](https://www.codewars.com/kata/5772da22b89313a4d50012f7) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/grasshopper_personalized_message) | -|8 |[Grasshopper - Summation](https://www.codewars.com/kata/55d24f55d7dd296eb9000030) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/grasshopper_summation) | -|9 |[Is it a palindrome](https://www.codewars.com/kata/57a1fd2ce298a731b20006a4) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/is_it_a_palindrome) | -|10 |[Is your period late](https://www.codewars.com/kata/578a8a01e9fd1549e50001f1) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/is_your_period_late) | -|11 |[Keep Hydrated!](https://www.codewars.com/kata/582cb0224e56e068d800003c) |[Solution](https://github.com/ikostan/codewars/blob/master/kyu_8/keep_hydrated/README.md) | -|12 |[Logical calculator](https://www.codewars.com/kata/57096af70dad013aa200007b) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/logical_calculator) | -|13 |[MakeUpperCase](https://www.codewars.com/kata/57a0556c7cb1f31ab3000ad7) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/make_upper_case) | -|14 |[Multiply](https://www.codewars.com/kata/50654ddff44f800200000004) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/multiply) | -|15 |[My head is at the wrong end](https://www.codewars.com/kata/56f699cd9400f5b7d8000b55) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/my_head_is_at_the_wrong_end) | -|16 |[Remove First and Last Character](https://www.codewars.com/kata/56bc28ad5bdaeb48760009b0) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/remove_first_and_last_character) | -|17 |[Remove String Spaces](https://www.codewars.com/kata/57eae20f5500ad98e50002c5) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/remove_string_spaces) | -|18 |[Reversed Strings](https://www.codewars.com/kata/5168bb5dfe9a00b126000018) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/reversed_strings) | -|19 |[L1: Set Alarm](https://www.codewars.com/kata/568dcc3c7f12767a62000038) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/set_alarm) | -|20 |[Surface Area and Volume of a Box](https://www.codewars.com/kata/565f5825379664a26b00007c) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/surface_area_and_volume_of_box) | -|21 |[Swap Values](https://www.codewars.com/kata/5388f0e00b24c5635e000fc6) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/swap_values) | -|22 |[Grasshopper - Terminal game move function](https://www.codewars.com/kata/563a631f7cbbc236cf0000c2) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/terminal_game_move_function) | -|23 |[Third Angle of a Triangle](https://www.codewars.com/kata/5a023c426975981341000014) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/third_angle_of_triangle) | -|24 |[Well of Ideas - Easy Version](https://www.codewars.com/kata/57f222ce69e09c3630000212) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/well_of_ideas_easy_version) | -|25 |[Will there be enough space](https://www.codewars.com/kata/5875b200d520904a04000003) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/will_there_be_enough_space) | -|26 |[A wolf in sheep's clothing](https://www.codewars.com/kata/5c8bfa44b9d1192e1ebd3d15) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/wolf_in_sheep_clothing) | -|27 |[Formatting decimal places #0](https://www.codewars.com/kata/5641a03210e973055a00000d) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/formatting_decimal_places_0) | -|28 |[Convert a string to an array](https://www.codewars.com/kata/57e76bc428d6fbc2d500036d) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/convert_string_to_an_array) | -|29 |[The Feast of Many Beasts](https://www.codewars.com/kata/5aa736a455f906981800360d) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/the_feast_of_many_beasts) | -|30 |[Count the Monkeys!](https://www.codewars.com/kata/count-the-monkeys) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/count_the_monkeys) | -|31 |[Keep up the hoop](https://www.codewars.com/kata/55cb632c1a5d7b3ad0000145) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/keep_up_the_hoop) | -|32 |[Enumerable Magic #25 - Take the First N Elements](https://www.codewars.com/kata/545afd0761aa4c3055001386)|[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/enumerable_magic_25) | -|33 |[Will you make it?](https://www.codewars.com/kata/5861d28f124b35723e00005e) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/will_you_make_it) | -|34 |[Century From Year](https://www.codewars.com/kata/5a3fe3dde1ce0e8ed6000097) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/century_from_year) | -|35 |[Holiday VI - Shark Pontoon](https://www.codewars.com/kata/57e921d8b36340f1fd000059) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/holiday_vi_shark_pontoon) | -|36 |[My head is at the wrong end!](https://www.codewars.com/kata/56f699cd9400f5b7d8000b55) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/my_head_is_at_the_wrong_end) | -|37 |[Greek Sort](https://www.codewars.com/kata/56bc1acf66a2abc891000561) |[Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/greek_sort) | +| No. | Puzzle/Kata Name | Solution / GitHub Link | +|-----|:--------------------------------------------------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------:| +| 1 | [altERnaTIng cAsE <=> ALTerNAtiNG CaSe](https://www.codewars.com/kata/56efc695740d30f963000557) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/alternating_case) | +| 2 | [Check the exam](https://www.codewars.com/kata/5a3dd29055519e23ec000074) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/check_the_exam) | +| 3 | [Counting sheep...](https://www.codewars.com/kata/54edbc7200b811e956000556) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/counting_sheep) | +| 4 | [Find the first non-consecutive number](https://www.codewars.com/kata/58f8a3a27a5c28d92e000144) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/find_the_first_non_consecutive_number) | +| 5 | [Grasshopper - Check for Factor](https://www.codewars.com/kata/55cbc3586671f6aa070000fb) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/grasshopper_check_for_factor) | +| 6 | [Grasshopper - Messi goals function](https://www.codewars.com/kata/55f73be6e12baaa5900000d4) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/grasshopper_messi_goals_function) | +| 7 | [Grasshopper - Personalized Message](https://www.codewars.com/kata/5772da22b89313a4d50012f7) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/grasshopper_personalized_message) | +| 8 | [Grasshopper - Summation](https://www.codewars.com/kata/55d24f55d7dd296eb9000030) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/grasshopper_summation) | +| 9 | [Is it a palindrome](https://www.codewars.com/kata/57a1fd2ce298a731b20006a4) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/is_it_a_palindrome) | +| 10 | [Is your period late](https://www.codewars.com/kata/578a8a01e9fd1549e50001f1) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/is_your_period_late) | +| 11 | [Keep Hydrated!](https://www.codewars.com/kata/582cb0224e56e068d800003c) | [Solution](https://github.com/ikostan/codewars/blob/master/kyu_8/keep_hydrated/README.md) | +| 12 | [Logical calculator](https://www.codewars.com/kata/57096af70dad013aa200007b) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/logical_calculator) | +| 13 | [MakeUpperCase](https://www.codewars.com/kata/57a0556c7cb1f31ab3000ad7) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/make_upper_case) | +| 14 | [Multiply](https://www.codewars.com/kata/50654ddff44f800200000004) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/multiply) | +| 15 | [My head is at the wrong end](https://www.codewars.com/kata/56f699cd9400f5b7d8000b55) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/my_head_is_at_the_wrong_end) | +| 16 | [Remove First and Last Character](https://www.codewars.com/kata/56bc28ad5bdaeb48760009b0) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/remove_first_and_last_character) | +| 17 | [Remove String Spaces](https://www.codewars.com/kata/57eae20f5500ad98e50002c5) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/remove_string_spaces) | +| 18 | [Reversed Strings](https://www.codewars.com/kata/5168bb5dfe9a00b126000018) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/reversed_strings) | +| 19 | [L1: Set Alarm](https://www.codewars.com/kata/568dcc3c7f12767a62000038) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/set_alarm) | +| 20 | [Surface Area and Volume of a Box](https://www.codewars.com/kata/565f5825379664a26b00007c) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/surface_area_and_volume_of_box) | +| 21 | [Swap Values](https://www.codewars.com/kata/5388f0e00b24c5635e000fc6) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/swap_values) | +| 22 | [Grasshopper - Terminal game move function](https://www.codewars.com/kata/563a631f7cbbc236cf0000c2) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/terminal_game_move_function) | +| 23 | [Third Angle of a Triangle](https://www.codewars.com/kata/5a023c426975981341000014) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/third_angle_of_triangle) | +| 24 | [Well of Ideas - Easy Version](https://www.codewars.com/kata/57f222ce69e09c3630000212) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/well_of_ideas_easy_version) | +| 25 | [Will there be enough space](https://www.codewars.com/kata/5875b200d520904a04000003) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/will_there_be_enough_space) | +| 26 | [A wolf in sheep's clothing](https://www.codewars.com/kata/5c8bfa44b9d1192e1ebd3d15) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/wolf_in_sheep_clothing) | +| 27 | [Formatting decimal places #0](https://www.codewars.com/kata/5641a03210e973055a00000d) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/formatting_decimal_places_0) | +| 28 | [Convert a string to an array](https://www.codewars.com/kata/57e76bc428d6fbc2d500036d) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/convert_string_to_an_array) | +| 29 | [The Feast of Many Beasts](https://www.codewars.com/kata/5aa736a455f906981800360d) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/the_feast_of_many_beasts) | +| 30 | [Count the Monkeys!](https://www.codewars.com/kata/count-the-monkeys) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/count_the_monkeys) | +| 31 | [Keep up the hoop](https://www.codewars.com/kata/55cb632c1a5d7b3ad0000145) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/keep_up_the_hoop) | +| 32 | [Enumerable Magic #25 - Take the First N Elements](https://www.codewars.com/kata/545afd0761aa4c3055001386) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/enumerable_magic_25) | +| 33 | [Will you make it?](https://www.codewars.com/kata/5861d28f124b35723e00005e) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/will_you_make_it) | +| 34 | [Century From Year](https://www.codewars.com/kata/5a3fe3dde1ce0e8ed6000097) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/century_from_year) | +| 35 | [Holiday VI - Shark Pontoon](https://www.codewars.com/kata/57e921d8b36340f1fd000059) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/holiday_vi_shark_pontoon) | +| 36 | [My head is at the wrong end!](https://www.codewars.com/kata/56f699cd9400f5b7d8000b55) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/my_head_is_at_the_wrong_end) | +| 37 | [Greek Sort](https://www.codewars.com/kata/56bc1acf66a2abc891000561) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/greek_sort) | +| 38 | [Closest elevator](https://www.codewars.com/kata/5c374b346a5d0f77af500a5a) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_8/closest_elevator) | [Source](https://www.codewars.com/about) diff --git a/kyu_8/__init__.py b/kyu_8/__init__.py index e69de29bb2d..3959b412ade 100644 --- a/kyu_8/__init__.py +++ b/kyu_8/__init__.py @@ -0,0 +1 @@ +"""8 kyu - Beginner package.""" diff --git a/kyu_8/alternating_case/__init__.py b/kyu_8/alternating_case/__init__.py index e69de29bb2d..4463be21191 100644 --- a/kyu_8/alternating_case/__init__.py +++ b/kyu_8/alternating_case/__init__.py @@ -0,0 +1 @@ +"""altERnaTIng cAsE <=> ALTerNAtiNG CaSe.""" diff --git a/kyu_8/alternating_case/alternating_case.py b/kyu_8/alternating_case/alternating_case.py index 06304da424b..f298b2e7c23 100644 --- a/kyu_8/alternating_case/alternating_case.py +++ b/kyu_8/alternating_case/alternating_case.py @@ -1,5 +1,6 @@ """ -altERnaTIng cAsE <=> ALTerNAtiNG CaSe +altERnaTIng cAsE <=> ALTerNAtiNG CaSe. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,9 +8,11 @@ def to_alternating_case(string: str) -> str: """ - each lowercase letter becomes uppercase and - each uppercase letter becomes lowercase - :param string: - :return: + Alternating case. + + Each lowercase letter becomes uppercase and + each uppercase letter becomes lowercase. + :param string: str + :return: str """ return ''.join((char.upper() if char.islower() else char.lower()) for char in string) diff --git a/kyu_8/alternating_case/test_alternating_case.py b/kyu_8/alternating_case/test_alternating_case.py index e11dc12b8e4..18fc1462444 100644 --- a/kyu_8/alternating_case/test_alternating_case.py +++ b/kyu_8/alternating_case/test_alternating_case.py @@ -1,5 +1,6 @@ """ -Testing for altERnaTIng cAsE <=> ALTerNAtiNG CaSe +Testing for altERnaTIng cAsE <=> ALTerNAtiNG CaSe. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -8,6 +9,7 @@ import unittest import allure +from parameterized import parameterized from utils.log_func import print_log from kyu_8.alternating_case.alternating_case \ import to_alternating_case @@ -26,13 +28,23 @@ name='Source/Kata') # pylint: enable=R0801 class AlternatingCaseTestCase(unittest.TestCase): - """ - Testing to_alternating_case function - """ + """Testing to_alternating_case function.""" - def test_alternating_case(self): + @parameterized.expand([ + ("hello world", "HELLO WORLD"), + ("HELLO WORLD", "hello world"), + ("HeLLo WoRLD", "hEllO wOrld"), + ("hello WORLD", "HELLO world"), + ("12345", "12345"), + ("1a2b3c4d5e", "1A2B3C4D5E"), + ("String.prototype.toAlternatingCase", + "sTRING.PROTOTYPE.TOaLTERNATINGcASE"), + ("Hello World", "hELLO wORLD"), + ("altERnaTIng cAsE", "ALTerNAtiNG CaSe")]) + def test_alternating_case(self, string, expected): """ - Testing to_alternating_case function + Testing to_alternating_case function with various test data. + :return: """ # pylint: disable=R0801 @@ -40,26 +52,13 @@ def test_alternating_case(self): allure.dynamic.severity(allure.severity_level.NORMAL) allure.dynamic.description_html( '

Codewars badge:

' - '' + '' '

Test Description:

' "

") # pylint: enable=R0801 - with allure.step("Enter test string and verify the output"): - test_data: tuple = ( - ("hello world", "HELLO WORLD"), - ("HELLO WORLD", "hello world"), - ("HeLLo WoRLD", "hEllO wOrld"), - ("hello WORLD", "HELLO world"), - ("12345", "12345"), - ("1a2b3c4d5e", "1A2B3C4D5E"), - ("String.prototype.toAlternatingCase", - "sTRING.PROTOTYPE.TOaLTERNATINGcASE"), - ("Hello World", "hELLO wORLD"), - ("altERnaTIng cAsE", "ALTerNAtiNG CaSe")) - - for d in test_data: - string = d[0] - expected = d[1] - print_log(string=string, expected=expected) - self.assertEqual(to_alternating_case(string), expected) + with allure.step(f"Enter test string: {string} " + f"and verify the expected output: {expected}."): + print_log(string=string, expected=expected) + self.assertEqual(to_alternating_case(string), expected) diff --git a/kyu_8/century_from_year/__init__.py b/kyu_8/century_from_year/__init__.py index e69de29bb2d..228c0682982 100644 --- a/kyu_8/century_from_year/__init__.py +++ b/kyu_8/century_from_year/__init__.py @@ -0,0 +1 @@ +"""Century From Year.""" diff --git a/kyu_8/century_from_year/century.py b/kyu_8/century_from_year/century.py index b3687eb368f..b6406ec4aa0 100644 --- a/kyu_8/century_from_year/century.py +++ b/kyu_8/century_from_year/century.py @@ -1,5 +1,6 @@ """ -Solution for -> Century From Year +Solution for -> Century From Year. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,7 +8,8 @@ def century(year: int) -> int: """ - Given a year, return the century it is in + Given a year, return the century it is in. + :param year: int :return: int """ diff --git a/kyu_8/century_from_year/test_century.py b/kyu_8/century_from_year/test_century.py index 1c86b9c549c..37cf962a18b 100644 --- a/kyu_8/century_from_year/test_century.py +++ b/kyu_8/century_from_year/test_century.py @@ -1,5 +1,6 @@ """ -Test for -> Century From Year +Test for -> Century From Year. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -9,6 +10,7 @@ import unittest import allure +from parameterized import parameterized from kyu_8.century_from_year.century import century from utils.log_func import print_log @@ -32,45 +34,45 @@ # pylint: enable-msg=R0801 class CenturyTestCase(unittest.TestCase): """ + Testing century function. + The first century spans from the year 1 up to and including the year 100, The second - from the year 101 up to and including the year 200, etc. """ - def test_century(self): + @parameterized.expand([ + (1705, 18, 'Testing for year 1705'), + (1900, 19, 'Testing for year 1900'), + (1601, 17, 'Testing for year 1601'), + (2000, 20, 'Testing for year 2000'), + (356, 4, 'Testing for year 356'), + (89, 1, 'Testing for year 89')]) + def test_century(self, year, expected, message): """ - Testing century function + Testing century function with various test data. + + :return: """ # pylint: disable-msg=R0801 allure.dynamic.title("Testing century function") allure.dynamic.severity(allure.severity_level.NORMAL) allure.dynamic.description_html( '

Codewars badge:

' - '' + '' '

Test Description:

' - "

Given a year, the function should return the century it is in." + "

Given a year, the function should return " + "the century it is in." "

") # pylint: enable-msg=R0801 - test_data: tuple = ( - (1705, 18, 'Testing for year 1705'), - (1900, 19, 'Testing for year 1900'), - (1601, 17, 'Testing for year 1601'), - (2000, 20, 'Testing for year 2000'), - (356, 4, 'Testing for year 356'), - (89, 1, 'Testing for year 89')) - - for year, expected, message in test_data: - result: int = century(year) - - with allure.step(f"Enter test year ({year}) and verify " - f"the output ({result}) " - f"vs expected ({expected})"): - - print_log(year=year, - result=result, - expected=expected, - message=message) - - self.assertEqual(expected, - result) + result: int = century(year) + with allure.step(f"Enter test year ({year}) and verify " + f"the output ({result}) " + f"vs expected ({expected})"): + print_log(year=year, + result=result, + expected=expected, + message=message) + self.assertEqual(expected, result) diff --git a/kyu_8/check_the_exam/__init__.py b/kyu_8/check_the_exam/__init__.py index e69de29bb2d..b61f6186057 100644 --- a/kyu_8/check_the_exam/__init__.py +++ b/kyu_8/check_the_exam/__init__.py @@ -0,0 +1 @@ +"""Check the exam.""" diff --git a/kyu_8/check_the_exam/check_exam.py b/kyu_8/check_the_exam/check_exam.py index 319bf5d155f..cf3d0a93805 100644 --- a/kyu_8/check_the_exam/check_exam.py +++ b/kyu_8/check_the_exam/check_exam.py @@ -1,5 +1,6 @@ """ -Solution for -> Check the exam +Solution for -> Check the exam. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,6 +8,8 @@ def check_exam(arr1: list, arr2: list) -> int: """ + Check exam. + The first input array contains the correct answers to an exam, like ["a", "a", "b", "d"]. The second one is "answers" array and contains student's answers. @@ -32,7 +35,8 @@ def check_exam(arr1: list, arr2: list) -> int: def char_processor(char: tuple, results: list) -> None: """ - Processing chars based on specified rule + Process chars based on specified rule. + :param char: str :param results: list :return: None diff --git a/kyu_8/check_the_exam/test_check_exam.py b/kyu_8/check_the_exam/test_check_exam.py index 8fc45f2098b..ad27e93914a 100644 --- a/kyu_8/check_the_exam/test_check_exam.py +++ b/kyu_8/check_the_exam/test_check_exam.py @@ -1,5 +1,6 @@ """ -Test for -> Check the exam +Test for -> Check the exam. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -8,6 +9,7 @@ import unittest import allure +from parameterized import parameterized from utils.log_func import print_log from kyu_8.check_the_exam.check_exam import check_exam @@ -28,20 +30,21 @@ name='Source/Kata') # pylint: enable=R0801 class CheckExamTestCase(unittest.TestCase): - """ - Testing check_exam function - """ - - def test_check_exam(self): + """Testing check_exam function.""" + + @parameterized.expand([ + (["a", "a", "b", "b"], ["a", "c", "b", "d"], 6), + (["a", "a", "c", "b"], ["a", "a", "b", ""], 7), + (["a", "a", "b", "c"], ["a", "a", "b", "c"], 16), + (["b", "c", "b", "a"], ["", "a", "a", "c"], 0)]) + def test_check_exam(self, arr1, arr2, expected): """ - Testing check_exam function + Testing check_exam function with various test data. - The function should return the score - for this array of answers, giving +4 - for each correct answer, -1 for each - incorrect answer, and +0 for each blank + The function should return the score for this + array of answers, giving +4 for each correct answer, + -1 for each incorrect answer, and +0 for each blank answer(empty string). - :return: """ # pylint: disable=R0801 @@ -49,22 +52,12 @@ def test_check_exam(self): allure.dynamic.severity(allure.severity_level.NORMAL) allure.dynamic.description_html( '

Codewars badge:

' - '' + '' '

Test Description:

' "

") # pylint: enable=R0801 with allure.step("Enter arr1 and arr2 and verify the output"): - data: tuple = ( - (["a", "a", "b", "b"], ["a", "c", "b", "d"], 6), - (["a", "a", "c", "b"], ["a", "a", "b", ""], 7), - (["a", "a", "b", "c"], ["a", "a", "b", "c"], 16), - (["b", "c", "b", "a"], ["", "a", "a", "c"], 0)) - - for arr1, arr2, expected in data: - print_log(arr1=arr1, - arr2=arr2, - expected=expected) - - self.assertEqual(expected, - check_exam(arr1, arr2)) + print_log(arr1=arr1, arr2=arr2, expected=expected) + self.assertEqual(expected, check_exam(arr1, arr2)) diff --git a/kyu_8/closest_elevator/README.md b/kyu_8/closest_elevator/README.md new file mode 100644 index 00000000000..51e1fa33e81 --- /dev/null +++ b/kyu_8/closest_elevator/README.md @@ -0,0 +1,30 @@ +# Closest elevator + +## Description + +Given 2 elevators (named "left" and "right") in a building with 3 floors +(numbered 0 to 2), write a function accepting 3 arguments (in order): + +`left` - The current floor of the left elevator +`right` - The current floor of the right elevator +`call` - The floor that called an elevator + +It should return the name of the elevator closest to the called floor ("left"/"right"). + +In the case where both elevators are equally distant from the called floor, +choose the elevator to the right. + +You can assume that the inputs will always be valid integers between 0-2. + +## Examples + +``` +left right call result + 0 1 0 "left" + 0 1 1 "right" + 0 1 2 "right" + 0 0 0 "right" + 0 2 1 "right" +``` + +[Source](https://www.codewars.com/kata/5c374b346a5d0f77af500a5a) \ No newline at end of file diff --git a/kyu_8/closest_elevator/__init__.py b/kyu_8/closest_elevator/__init__.py new file mode 100644 index 00000000000..7eaf34320c3 --- /dev/null +++ b/kyu_8/closest_elevator/__init__.py @@ -0,0 +1 @@ +"""Closest elevator.""" diff --git a/kyu_8/closest_elevator/closest_elevator.py b/kyu_8/closest_elevator/closest_elevator.py new file mode 100644 index 00000000000..3a04743db19 --- /dev/null +++ b/kyu_8/closest_elevator/closest_elevator.py @@ -0,0 +1,23 @@ +""" +Solution for -> Closest elevator. + +Created by Egor Kostan. +GitHub: https://github.com/ikostan +""" + +def elevator(left: int, right: int, call: int) -> str: + """ + Return closest elevator number. + + :param left: int + :param right: int + :param call: int + :return: str + """ + if right == left == call: + return 'right' + + if left == call or abs(call - left) < abs(call - right): + return 'left' + + return 'right' diff --git a/kyu_8/closest_elevator/test_closest_elevator.py b/kyu_8/closest_elevator/test_closest_elevator.py new file mode 100644 index 00000000000..fb6e3bc0873 --- /dev/null +++ b/kyu_8/closest_elevator/test_closest_elevator.py @@ -0,0 +1,62 @@ +""" +Test for -> Closest elevator. + +Created by Egor Kostan. +GitHub: https://github.com/ikostan +""" + +# Algorithms + +import unittest +import allure +from parameterized import parameterized +from utils.log_func import print_log +from kyu_8.closest_elevator.closest_elevator import elevator + + +# pylint: disable=R0801 +@allure.epic('8 kyu') +@allure.parent_suite('Beginner') +@allure.suite("Data Structures") +@allure.sub_suite("Unit Tests") +@allure.feature("Lists") +@allure.story('Closest elevator') +@allure.tag('FUNDAMENTALS', + 'ALGORITHMS') +@allure.link( + url='https://www.codewars.com/kata/5c374b346a5d0f77af500a5a', + name='Source/Kata') +# pylint: enable=R0801 +class ClosestElevatorTestCase(unittest.TestCase): + """Test elevator function.""" + + @parameterized.expand([ + ((0, 1, 0), "left"), + ((0, 1, 1), "right"), + ((0, 1, 2), "right"), + ((0, 0, 0), "right"), + ((0, 2, 1), "right")]) + def test_elevator_basic(self, elevators, expected): + """ + Testing 'elevator' function with various test data. + + :return: + """ + # pylint: disable=R0801 + allure.dynamic.title("Testing elevator function") + allure.dynamic.severity(allure.severity_level.NORMAL) + allure.dynamic.description_html( + '

Codewars badge:

' + '' + '

Test Description:

' + "

") + # pylint: enable=R0801 + with allure.step(f"Enter test data: {elevators} " + f"and verify the expected output: {expected}."): + left, right, call = elevators + result: str = elevator(left, right, call) + print_log(expected=expected, left=left, right=right, call=call) + message: str = f'elevators: {elevators}, result: {result}, expected: {expected}' + self.assertEqual(expected, result, msg=message) diff --git a/kyu_8/convert_string_to_an_array/__init__.py b/kyu_8/convert_string_to_an_array/__init__.py index e69de29bb2d..a236a70d07e 100644 --- a/kyu_8/convert_string_to_an_array/__init__.py +++ b/kyu_8/convert_string_to_an_array/__init__.py @@ -0,0 +1 @@ +"""Convert a string to an array.""" diff --git a/kyu_8/convert_string_to_an_array/string_to_array.py b/kyu_8/convert_string_to_an_array/string_to_array.py index 724f48905f5..14fa4a648a0 100644 --- a/kyu_8/convert_string_to_an_array/string_to_array.py +++ b/kyu_8/convert_string_to_an_array/string_to_array.py @@ -1,5 +1,6 @@ """ -Solution for -> Convert a string to an array +Solution for -> Convert a string to an array. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,8 +8,8 @@ def string_to_array(s: str) -> list: """ - A function to split a string and - convert it into an array of words + Split a string and convert it into an array of words. + :param s: str :return: list """ diff --git a/kyu_8/convert_string_to_an_array/test_string_to_array.py b/kyu_8/convert_string_to_an_array/test_string_to_array.py index d389160b0cd..72f48dfe51e 100644 --- a/kyu_8/convert_string_to_an_array/test_string_to_array.py +++ b/kyu_8/convert_string_to_an_array/test_string_to_array.py @@ -1,5 +1,6 @@ """ -Test for -> Convert a string to an array +Test for -> Convert a string to an array. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -8,6 +9,7 @@ import unittest import allure +from parameterized import parameterized from utils.log_func import print_log from kyu_8.convert_string_to_an_array.string_to_array \ import string_to_array @@ -28,11 +30,16 @@ name='Source/Kata') # pylint: enable=R0801 class StringToArrayTestCase(unittest.TestCase): - """ - Testing string_to_array function. - """ + """Testing string_to_array function.""" - def test_string_to_array(self): + @parameterized.expand([ + ("Robin Singh", ["Robin", "Singh"]), + ("CodeWars", ["CodeWars"]), + ("I love arrays they are my favorite", + ["I", "love", "arrays", "they", "are", "my", "favorite"]), + ("1 2 3", ["1", "2", "3"]), + ("", [""])]) + def test_string_to_array(self, s, expected): """ Testing string_to_array function. @@ -50,15 +57,7 @@ def test_string_to_array(self): '

Test Description:

' "

") # pylint: enable=R0801 - with allure.step("Enter a test string and verify the output"): - test_data: tuple = ( - ("Robin Singh", ["Robin", "Singh"]), - ("CodeWars", ["CodeWars"]), - ("I love arrays they are my favorite", - ["I", "love", "arrays", "they", "are", "my", "favorite"]), - ("1 2 3", ["1", "2", "3"]), - ("", [""])) - - for s, expected in test_data: - print_log(s=s, expected=expected) - self.assertEqual(expected, string_to_array(s)) + with allure.step(f"Enter a test string: {s} " + f"and verify the output: {expected}."): + print_log(s=s, expected=expected) + self.assertEqual(expected, string_to_array(s)) diff --git a/kyu_8/count_the_monkeys/__init__.py b/kyu_8/count_the_monkeys/__init__.py index e69de29bb2d..3eca16bf08d 100644 --- a/kyu_8/count_the_monkeys/__init__.py +++ b/kyu_8/count_the_monkeys/__init__.py @@ -0,0 +1 @@ +"""Count the Monkeys.""" diff --git a/kyu_8/count_the_monkeys/monkey_count.py b/kyu_8/count_the_monkeys/monkey_count.py index c089aa86894..bf4467b021a 100644 --- a/kyu_8/count_the_monkeys/monkey_count.py +++ b/kyu_8/count_the_monkeys/monkey_count.py @@ -1,5 +1,6 @@ """ -Solution for -> Count the Monkeys! +Solution for -> Count the Monkeys!. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,6 +8,8 @@ def monkey_count(n: int) -> list: """ + Count monkeys. + You take your son to the forest to see the monkeys. You know that there are a certain number there (n), but your son is too young to just appreciate the full diff --git a/kyu_8/count_the_monkeys/test_monkey_count.py b/kyu_8/count_the_monkeys/test_monkey_count.py index 095047df308..24e7e002a84 100644 --- a/kyu_8/count_the_monkeys/test_monkey_count.py +++ b/kyu_8/count_the_monkeys/test_monkey_count.py @@ -1,5 +1,6 @@ """ -Test for -> Count the Monkeys! +Test for -> Count the Monkeys!. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -9,6 +10,7 @@ import unittest import allure +from parameterized import parameterized from utils.log_func import print_log from kyu_8.count_the_monkeys.monkey_count \ import monkey_count @@ -33,13 +35,19 @@ name='Source/Kata') # pylint: enable=R0801 class MonkeyCountTestCase(unittest.TestCase): - """ - Testing monkey_count function - """ + """Testing monkey_count function.""" - def test_monkey_count(self): + @parameterized.expand([ + (1, [1]), + (5, [1, 2, 3, 4, 5]), + (3, [1, 2, 3]), + (9, [1, 2, 3, 4, 5, 6, 7, 8, 9]), + (10, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), + (20, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20])]) + def test_monkey_count(self, n, expected): """ - Testing monkey_count function + Testing monkey_count function. You take your son to the forest to see the monkeys. You know that there are a certain number there (n), @@ -62,16 +70,7 @@ def test_monkey_count(self): '

Test Description:

' "

") # pylint: enable=R0801 - with allure.step("Enter a number (int) and verify the output"): - test_data: tuple = ( - (1, [1]), - (5, [1, 2, 3, 4, 5]), - (3, [1, 2, 3]), - (9, [1, 2, 3, 4, 5, 6, 7, 8, 9]), - (10, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), - (20, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, - 12, 13, 14, 15, 16, 17, 18, 19, 20])) - - for n, expected in test_data: - print_log(n=n, expected=expected) - self.assertEqual(expected, monkey_count(n)) + with allure.step(f"Enter a number (int): {n} " + f"and verify the expected output: {expected}."): + print_log(n=n, expected=expected) + self.assertEqual(expected, monkey_count(n)) diff --git a/kyu_8/counting_sheep/__init__.py b/kyu_8/counting_sheep/__init__.py index e69de29bb2d..b676058b62c 100644 --- a/kyu_8/counting_sheep/__init__.py +++ b/kyu_8/counting_sheep/__init__.py @@ -0,0 +1 @@ +"""Counting sheep.""" diff --git a/kyu_8/counting_sheep/counting_sheep.py b/kyu_8/counting_sheep/counting_sheep.py index be4c8583b89..8ade6f78b92 100644 --- a/kyu_8/counting_sheep/counting_sheep.py +++ b/kyu_8/counting_sheep/counting_sheep.py @@ -1,12 +1,15 @@ """ Solution for -> Counting sheep... + Created by Egor Kostan. GitHub: https://github.com/ikostan """ -def count_sheeps(array_of_sheeps: list) -> int: +def count_sheep(array_of_sheep: list) -> int: """ + Count sheep. + Consider an array of sheep where some sheep may be missing from their place. We need a function that counts the number of sheep @@ -14,8 +17,8 @@ def count_sheeps(array_of_sheeps: list) -> int: Hint: Don't forget to check for bad values like null/undefined - :param array_of_sheeps: - :return: + :param array_of_sheep: list + :return: int """ - return 0 if array_of_sheeps is None \ - else array_of_sheeps.count(True) + return 0 if array_of_sheep is None \ + else array_of_sheep.count(True) diff --git a/kyu_8/counting_sheep/test_counting_sheep.py b/kyu_8/counting_sheep/test_counting_sheep.py index 5b48b889a49..0f1c9eb47bd 100644 --- a/kyu_8/counting_sheep/test_counting_sheep.py +++ b/kyu_8/counting_sheep/test_counting_sheep.py @@ -1,5 +1,6 @@ """ Test for -> Counting sheep... + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -9,7 +10,7 @@ import unittest import allure from utils.log_func import print_log -from kyu_8.counting_sheep.counting_sheep import count_sheeps +from kyu_8.counting_sheep.counting_sheep import count_sheep # pylint: disable=R0801 @@ -26,13 +27,12 @@ name='Source/Kata') # pylint: enable=R0801 class CountingSheepTestCase(unittest.TestCase): - """ - Testing 'count_sheeps' function - """ + """Testing 'count_sheep' function.""" def test_counting_sheep(self): """ - Testing 'count_sheeps' function + Testing 'count_sheep' function. + Consider an array of sheep where some sheep may be missing from their place. We need a function that counts the @@ -42,12 +42,13 @@ def test_counting_sheep(self): """ # pylint: disable=R0801 allure.dynamic.title( - "Testing 'count_sheeps' function: positive flow") + "Testing 'count_sheep' function: positive flow") allure.dynamic.severity(allure.severity_level.NORMAL) allure.dynamic.description_html( '

Codewars badge:

' - '' + '' '

Test Description:

' "

") # pylint: enable=R0801 @@ -60,13 +61,14 @@ def test_counting_sheep(self): expected: int = 17 print_log(list=lst, expected=expected) self.assertEqual(expected, - count_sheeps(lst), + count_sheep(lst), f"There are 17 sheep in total, " - f"not {count_sheeps(lst)}") + f"not {count_sheep(lst)}") def test_counting_sheep_bad_input(self): """ - Testing 'count_sheeps' function + Testing 'count_sheep' function, invalid values. + Hint: Don't forget to check for bad values like null/undefined :return: @@ -86,25 +88,27 @@ def test_counting_sheep_bad_input(self): expected: int = 0 print_log(list=lst, expected=expected) self.assertEqual(expected, - count_sheeps(lst), + count_sheep(lst), f"There are 0 sheep in total, " - f"not {count_sheeps(lst)}") + f"not {count_sheep(lst)}") def test_counting_sheep_empty_list(self): """ - Testing 'count_sheeps' function + Testing 'count_sheep' function, empty list. + Hint: Don't forget to check for bad values like empty list :return: """ # pylint: disable=R0801 allure.dynamic.title( - "Testing 'count_sheeps' function: empty list") + "Testing 'count_sheep' function: empty list") allure.dynamic.severity(allure.severity_level.NORMAL) allure.dynamic.description_html( '

Codewars badge:

' - '' + '' '

Test Description:

' "

") # pylint: enable=R0801 @@ -112,25 +116,27 @@ def test_counting_sheep_empty_list(self): expected: int = 0 print_log(list=lst, expected=expected) self.assertEqual(expected, - count_sheeps(lst), + count_sheep(lst), f"There are 0 sheep in total, " - f"not {count_sheeps(lst)}") + f"not {count_sheep(lst)}") def test_counting_sheep_mixed_list(self): """ - Testing 'count_sheeps' function + Testing 'count_sheep' function, null value. + Hint: Don't forget to check for bad values like mixed list :return: """ # pylint: disable=R0801 allure.dynamic.title( - "Testing 'count_sheeps' function: mixed list") + "Testing 'count_sheep' function: mixed list") allure.dynamic.severity(allure.severity_level.NORMAL) allure.dynamic.description_html( '

Codewars badge:

' - '' + '' '

Test Description:

' "

") # pylint: enable=R0801 @@ -138,6 +144,6 @@ def test_counting_sheep_mixed_list(self): expected: int = 1 print_log(list=lst, expected=expected) self.assertEqual(expected, - count_sheeps(lst), + count_sheep(lst), f"There are 0 sheep in total, " - f"not {count_sheeps(lst)}") + f"not {count_sheep(lst)}") diff --git a/kyu_8/enumerable_magic_25/__init__.py b/kyu_8/enumerable_magic_25/__init__.py index e69de29bb2d..410c8d0558c 100644 --- a/kyu_8/enumerable_magic_25/__init__.py +++ b/kyu_8/enumerable_magic_25/__init__.py @@ -0,0 +1 @@ +"""Enumerable Magic #25 - Take the First N Elements.""" diff --git a/kyu_8/enumerable_magic_25/take.py b/kyu_8/enumerable_magic_25/take.py index 107e0bb3450..0512f533432 100644 --- a/kyu_8/enumerable_magic_25/take.py +++ b/kyu_8/enumerable_magic_25/take.py @@ -1,5 +1,6 @@ """ -Solution for -> Enumerable Magic #25 - Take the First N Elements +Solution for -> Enumerable Magic #25 - Take the First N Elements. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,8 +8,10 @@ def take(arr: list, n: int) -> list: """ + 'take' function. + Accepts a list/array and a number n, - and returns a list/array array of the + and returns a list/array of the first n elements from the list/array. :param arr: list diff --git a/kyu_8/enumerable_magic_25/test_take.py b/kyu_8/enumerable_magic_25/test_take.py index ab1cb2d98ba..97d7be1a043 100644 --- a/kyu_8/enumerable_magic_25/test_take.py +++ b/kyu_8/enumerable_magic_25/test_take.py @@ -1,5 +1,6 @@ """ -Test for -> Enumerable Magic #25 - Take the First N Elements +Test for -> Enumerable Magic #25 - Take the First N Elements. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -8,6 +9,7 @@ import unittest import allure +from parameterized import parameterized from utils.log_func import print_log from kyu_8.enumerable_magic_25.take import take @@ -25,13 +27,17 @@ name='Source/Kata') # pylint: enable=R0801 class TakeTestCase(unittest.TestCase): - """ - Testing take function - """ + """Testing 'take' function.""" - def test_take(self): + @parameterized.expand([ + ([0, 1, 2, 3, 5, 8, 13], 3, [0, 1, 2]), + ([51], 35, [51]), + ([], 3, []), + ([0, 1, 2, 3, 5, 8, 13], 0, [])]) + def test_take(self, arr, n, expected): """ - Testing the function with various test data + Testing the function with various test data. + :return: """ # pylint: disable=R0801 @@ -39,8 +45,9 @@ def test_take(self): allure.dynamic.severity(allure.severity_level.NORMAL) allure.dynamic.description_html( '

Codewars badge:

' - '' + '' '

Test Description:

' "

Create a method take that accepts a list/array and a" " number n, and returns a list/array array of the first " @@ -49,31 +56,14 @@ def test_take(self): "https://docs.python.org/3/library/stdtypes" ".html#sequence-types-list-tuple-range

") # pylint: enable=R0801 - test_data: tuple = ( - ([0, 1, 2, 3, 5, 8, 13], - 3, - [0, 1, 2]), - ([51], - 35, - [51]), - ([], - 3, - []), - ([0, 1, 2, 3, 5, 8, 13], - 0, - [])) - - for arr, n, expected in test_data: - actual_result = take(arr, n) - - with allure.step(f"Enter a list ({arr}) and verify the " - f"expected output ({expected}) " - f"vs actual result ({actual_result})"): + actual_result = take(arr, n) + with allure.step(f"Enter a list ({arr}) and verify the " + f"expected output ({expected}) " + f"vs actual result ({actual_result})"): - print_log(rr=arr, + print_log(rr=arr, n=n, expected=expected, result=actual_result) - self.assertEqual(expected, - actual_result) + self.assertEqual(expected, actual_result) diff --git a/kyu_8/find_the_first_non_consecutive_number/__init__.py b/kyu_8/find_the_first_non_consecutive_number/__init__.py index e69de29bb2d..97e0a5e54d6 100644 --- a/kyu_8/find_the_first_non_consecutive_number/__init__.py +++ b/kyu_8/find_the_first_non_consecutive_number/__init__.py @@ -0,0 +1 @@ +"""Find the first non-consecutive number.""" diff --git a/kyu_8/find_the_first_non_consecutive_number/first_non_consecutive.py b/kyu_8/find_the_first_non_consecutive_number/first_non_consecutive.py index e88d5a1c966..0c21f38cd62 100644 --- a/kyu_8/find_the_first_non_consecutive_number/first_non_consecutive.py +++ b/kyu_8/find_the_first_non_consecutive_number/first_non_consecutive.py @@ -1,5 +1,6 @@ """ -Solution for -> Find the first non-consecutive number +Solution for -> Find the first non-consecutive number. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ diff --git a/kyu_8/find_the_first_non_consecutive_number/test_first_non_consecutive.py b/kyu_8/find_the_first_non_consecutive_number/test_first_non_consecutive.py index fe89221e5a2..ff9c7a69abb 100644 --- a/kyu_8/find_the_first_non_consecutive_number/test_first_non_consecutive.py +++ b/kyu_8/find_the_first_non_consecutive_number/test_first_non_consecutive.py @@ -1,5 +1,6 @@ """ -Test for -> Find the first non-consecutive number +Test for -> Find the first non-consecutive number. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -27,12 +28,12 @@ name='Source/Kata') # pylint: enable=R0801 class FirstNonConsecutiveTestCase(unittest.TestCase): - """ - Testing first_non_consecutive function - """ + """Testing first_non_consecutive function.""" def test_first_non_consecutive_none(self): """ + Testing first_non_consecutive function, non-consecutive numbers. + If the whole array is consecutive then return null or Nothing or None. :return: @@ -42,12 +43,13 @@ def test_first_non_consecutive_none(self): allure.dynamic.severity(allure.severity_level.NORMAL) allure.dynamic.description_html( '

Codewars badge:

' - '' + '' '

Test Description:

' "

") # pylint: enable=R0801 - with allure.step("Pass a list with no non consecutive numbers"): + with allure.step("Pass a list with non-consecutive numbers"): lst: list = [1, 2, 3, 4, 5, 6, 7, 8] expected: None = None @@ -62,7 +64,8 @@ def test_first_non_consecutive_none(self): def test_first_non_consecutive_large_list(self): """ - Large lists + Testing large lists. + :return: """ # pylint: disable=R0801 @@ -70,8 +73,9 @@ def test_first_non_consecutive_large_list(self): allure.dynamic.severity(allure.severity_level.NORMAL) allure.dynamic.description_html( '

Codewars badge:

' - '' + '' '

Test Description:

' "

") # pylint: enable=R0801 @@ -114,6 +118,8 @@ def test_first_non_consecutive_large_list(self): def test_first_non_consecutive_positive(self): """ + Test non-consecutive positive numbers. + If we have an array [1,2,3,4,6,7,8] then 1 then 2 then 3 then 4 are all consecutive but 6 is not, so that's the first non-consecutive number. @@ -124,8 +130,9 @@ def test_first_non_consecutive_positive(self): allure.dynamic.severity(allure.severity_level.NORMAL) allure.dynamic.description_html( '

Codewars badge:

' - '' + '' '

Test Description:

' "

") # pylint: enable=R0801 @@ -170,16 +177,19 @@ def test_first_non_consecutive_positive(self): def test_first_non_consecutive_negative(self): """ - non-consecutive is a negative number. + Test non-consecutive is a negative number. + :return: """ # pylint: disable=R0801 - allure.dynamic.title("Negative non consecutive number should be returned") + allure.dynamic.title( + "Negative non consecutive number should be returned") allure.dynamic.severity(allure.severity_level.NORMAL) allure.dynamic.description_html( '

Codewars badge:

' - '' + '' '

Test Description:

' "

") # pylint: enable=R0801 diff --git a/kyu_8/formatting_decimal_places_0/__init__.py b/kyu_8/formatting_decimal_places_0/__init__.py index e69de29bb2d..1ced7a92204 100644 --- a/kyu_8/formatting_decimal_places_0/__init__.py +++ b/kyu_8/formatting_decimal_places_0/__init__.py @@ -0,0 +1 @@ +"""Formatting decimal places #0.""" diff --git a/kyu_8/formatting_decimal_places_0/test_two_decimal_places.py b/kyu_8/formatting_decimal_places_0/test_two_decimal_places.py index d25a74b52da..057315550ba 100644 --- a/kyu_8/formatting_decimal_places_0/test_two_decimal_places.py +++ b/kyu_8/formatting_decimal_places_0/test_two_decimal_places.py @@ -1,5 +1,6 @@ """ -Test for -> Formatting decimal places #0 +Test for -> Formatting decimal places #0. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -8,6 +9,7 @@ import unittest import allure +from parameterized import parameterized from utils.log_func import print_log from kyu_8.formatting_decimal_places_0.two_decimal_places \ import two_decimal_places @@ -29,14 +31,21 @@ name='Source/Kata') # pylint: enable=R0801 class TwoDecimalPlacesTestCase(unittest.TestCase): - """ - Testing two_decimal_places function - """ + """Testing two_decimal_places function.""" - def test_two_decimal_places(self): + @parameterized.expand([ + (4.659725356, + 4.66, + "didn't work for 4.659725356"), + (173735326.3783732637948948, + 173735326.38, + "didn't work for 173735326.3783732637948948"), + (4.653725356, + 4.65, + "didn't work for 4.653725356")]) + def test_two_decimal_places(self, n, expected, msg): """ - Testing two_decimal_places function - with various test inputs. + Testing two_decimal_places function with various test inputs. Each number should be formatted that it is rounded to two decimal places. You don't @@ -50,25 +59,12 @@ def test_two_decimal_places(self): allure.dynamic.severity(allure.severity_level.NORMAL) allure.dynamic.description_html( '

Codewars badge:

' - '' + '' '

Test Description:

' "

") # pylint: enable=R0801 with allure.step("Pass a number and verify the output"): - data: tuple = ( - (4.659725356, - 4.66, - "didn't work for 4.659725356"), - (173735326.3783732637948948, - 173735326.38, - "didn't work for 173735326.3783732637948948"), - (4.653725356, - 4.65, - "didn't work for 4.653725356")) - - for n, expected, msg in data: - print_log(n=n, expected=expected) - self.assertEqual(expected, - two_decimal_places(n), - msg) + print_log(n=n, expected=expected) + self.assertEqual(expected, two_decimal_places(n), msg) diff --git a/kyu_8/formatting_decimal_places_0/two_decimal_places.py b/kyu_8/formatting_decimal_places_0/two_decimal_places.py index f6202d3bd6c..43822163c39 100644 --- a/kyu_8/formatting_decimal_places_0/two_decimal_places.py +++ b/kyu_8/formatting_decimal_places_0/two_decimal_places.py @@ -1,5 +1,6 @@ """ -Solution for -> Formatting decimal places #0 +Solution for -> Formatting decimal places #0. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,6 +8,8 @@ def two_decimal_places(n: float) -> float: """ + Convert a number into decimal. + Each number should be formatted that it is rounded to two decimal places. You don't need to check whether the input is a valid diff --git a/kyu_8/grasshopper_check_for_factor/__init__.py b/kyu_8/grasshopper_check_for_factor/__init__.py index e69de29bb2d..e8573f8e858 100644 --- a/kyu_8/grasshopper_check_for_factor/__init__.py +++ b/kyu_8/grasshopper_check_for_factor/__init__.py @@ -0,0 +1 @@ +"""Grasshopper.""" diff --git a/kyu_8/grasshopper_check_for_factor/check_for_factor.py b/kyu_8/grasshopper_check_for_factor/check_for_factor.py index 9073809a97c..b22755abbf9 100644 --- a/kyu_8/grasshopper_check_for_factor/check_for_factor.py +++ b/kyu_8/grasshopper_check_for_factor/check_for_factor.py @@ -1,5 +1,6 @@ """ -Solution for -> Grasshopper - Check for factor +Solution for -> Grasshopper - Check for factor. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,8 +8,7 @@ def check_for_factor(base: int, factor: int) -> bool: """ - This function should test if the - factor is a factor of base. + Check if the factor is a factor of base. Factors are numbers you can multiply together to get another number. diff --git a/kyu_8/grasshopper_check_for_factor/test_check_for_factor.py b/kyu_8/grasshopper_check_for_factor/test_check_for_factor.py index 52ace47678c..6b8597bb418 100644 --- a/kyu_8/grasshopper_check_for_factor/test_check_for_factor.py +++ b/kyu_8/grasshopper_check_for_factor/test_check_for_factor.py @@ -1,5 +1,6 @@ """ -Test for -> Grasshopper - Check for factor +Test for -> Grasshopper - Check for factor. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -8,6 +9,7 @@ import unittest import allure +from parameterized import parameterized from utils.log_func import print_log from kyu_8.grasshopper_check_for_factor.check_for_factor \ import check_for_factor @@ -29,11 +31,14 @@ name='Source/Kata') # pylint: disable=R0801 class CheckForFactorTestCase(unittest.TestCase): - """ - Testing check_for_factor function. - """ - - def test_check_for_factor_true(self): + """Testing check_for_factor function.""" + + @parameterized.expand([ + (10, 2, True), + (63, 7, True), + (2450, 5, True), + (24612, 3, True)]) + def test_check_for_factor_true(self, base, factor, expected): """ Testing check_for_factor function. @@ -49,28 +54,22 @@ def test_check_for_factor_true(self): allure.dynamic.severity(allure.severity_level.NORMAL) allure.dynamic.description_html( '

Codewars badge:

' - '' + '' '

Test Description:

' "

") # pylint: enable=R0801 with allure.step("Return true if it is a factor"): - data: tuple = ( - (10, 2, True), - (63, 7, True), - (2450, 5, True), - (24612, 3, True)) - - for base, factor, expected in data: - - print_log(base=base, - factor=factor, - expected=expected) - - self.assertEqual(expected, - check_for_factor(base, factor)) - - def test_check_for_factor_false(self): + print_log(base=base, factor=factor, expected=expected) + self.assertEqual(expected, check_for_factor(base, factor)) + + @parameterized.expand([ + (9, 2, False), + (653, 7, False), + (2453, 5, False), + (24617, 3, False)]) + def test_check_for_factor_false(self, base, factor, expected): """ Testing check_for_factor function. @@ -86,23 +85,12 @@ def test_check_for_factor_false(self): allure.dynamic.severity(allure.severity_level.NORMAL) allure.dynamic.description_html( '

Codewars badge:

' - '' + '' '

Test Description:

' "

") # pylint: enable=R0801 with allure.step("Return false if it is not a factor"): - data: tuple = ( - (9, 2, False), - (653, 7, False), - (2453, 5, False), - (24617, 3, False)) - - for base, factor, expected in data: - - print_log(base=base, - factor=factor, - expected=expected) - - self.assertEqual(expected, - check_for_factor(base, factor)) + print_log(base=base, factor=factor, expected=expected) + self.assertEqual(expected, check_for_factor(base, factor)) diff --git a/kyu_8/grasshopper_messi_goals_function/__init__.py b/kyu_8/grasshopper_messi_goals_function/__init__.py index e69de29bb2d..b041eb78383 100644 --- a/kyu_8/grasshopper_messi_goals_function/__init__.py +++ b/kyu_8/grasshopper_messi_goals_function/__init__.py @@ -0,0 +1 @@ +"""Grasshopper - Messi goals function.""" diff --git a/kyu_8/grasshopper_messi_goals_function/messi_goals_function.py b/kyu_8/grasshopper_messi_goals_function/messi_goals_function.py index 439037ca19d..8891f8333af 100644 --- a/kyu_8/grasshopper_messi_goals_function/messi_goals_function.py +++ b/kyu_8/grasshopper_messi_goals_function/messi_goals_function.py @@ -1,5 +1,6 @@ """ -Solution for -> Messi goals function +Solution for -> Messi goals function. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,6 +8,8 @@ def goals(la_liga: int, copa_delrey: int, champions_league: int) -> int: """ + Goals function. + The function returns Messi's total number of goals in all three leagues: - LaLiga diff --git a/kyu_8/grasshopper_messi_goals_function/test_messi_goals_function.py b/kyu_8/grasshopper_messi_goals_function/test_messi_goals_function.py index a69045f494d..faad955dd3d 100644 --- a/kyu_8/grasshopper_messi_goals_function/test_messi_goals_function.py +++ b/kyu_8/grasshopper_messi_goals_function/test_messi_goals_function.py @@ -1,5 +1,6 @@ """ -Test for -> Messi goals function +Test for -> Messi goals function. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -26,14 +27,15 @@ name='Source/Kata') # pylint: enable=R0801 class GoalsTestCase(unittest.TestCase): - """ - Testing goals function - """ + """Testing goals function.""" def test_goals(self): """ - Verify that the function returns Messi's - total number of goals in all three leagues. + Testing 'goals' function with various test data. + + Verify that the function returns Messi's total + number of goals in all three leagues. + :return: """ # pylint: disable=R0801 @@ -41,8 +43,9 @@ def test_goals(self): allure.dynamic.severity(allure.severity_level.NORMAL) allure.dynamic.description_html( '

Codewars badge:

' - '' + '' '

Test Description:

' "

") # pylint: enable=R0801 diff --git a/kyu_8/grasshopper_personalized_message/__init__.py b/kyu_8/grasshopper_personalized_message/__init__.py index e69de29bb2d..491c5af033c 100644 --- a/kyu_8/grasshopper_personalized_message/__init__.py +++ b/kyu_8/grasshopper_personalized_message/__init__.py @@ -0,0 +1 @@ +"""Grasshopper - Personalized Message.""" diff --git a/kyu_8/grasshopper_personalized_message/grasshopper_personalized_message.py b/kyu_8/grasshopper_personalized_message/grasshopper_personalized_message.py index 32e43086b0f..2ffbc91f663 100644 --- a/kyu_8/grasshopper_personalized_message/grasshopper_personalized_message.py +++ b/kyu_8/grasshopper_personalized_message/grasshopper_personalized_message.py @@ -1,5 +1,6 @@ """ -Solution for -> Personalized greeting +Solution for -> Personalized greeting. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,9 +8,9 @@ def greet(name: str, owner: str) -> str: """ - Function that gives a personalized greeting. - This function takes two parameters: name and owner. + Return a personalized greeting. + This function takes two parameters: name and owner. :param name: str :param owner: str :return: diff --git a/kyu_8/grasshopper_personalized_message/test_grasshopper_personalized_message.py b/kyu_8/grasshopper_personalized_message/test_grasshopper_personalized_message.py index c7ebc2db024..a6ebc4e21a2 100644 --- a/kyu_8/grasshopper_personalized_message/test_grasshopper_personalized_message.py +++ b/kyu_8/grasshopper_personalized_message/test_grasshopper_personalized_message.py @@ -1,5 +1,6 @@ """ -Test for -> Personalized greeting +Test for -> Personalized greeting. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -23,18 +24,17 @@ @allure.tag('FUNDAMENTALS', 'CONDITIONAL STATEMENTS', 'CONTROL FLOW') -@allure.link(url='https://www.codewars.com/kata/5772da22b89313a4d50012f7', - name='Source/Kata') +@allure.link( + url='https://www.codewars.com/kata/5772da22b89313a4d50012f7', + name='Source/Kata') # pylint: enable=R0801 class GreetTestCase(unittest.TestCase): - """ - Testing greet function - """ + """Testing greet function.""" def test_greet(self): """ - Use conditionals to to verify that greet - function returns the proper message. + Conditionals tests to verify that greet function returns the proper message. + :return: """ # pylint: disable=R0801 @@ -43,8 +43,9 @@ def test_greet(self): allure.dynamic.severity(allure.severity_level.NORMAL) allure.dynamic.description_html( '

Codewars badge:

' - '' + '' '

Test Description:

' "

") # pylint: enable=R0801 diff --git a/kyu_8/grasshopper_summation/__init__.py b/kyu_8/grasshopper_summation/__init__.py index e69de29bb2d..1afc95ba7c6 100644 --- a/kyu_8/grasshopper_summation/__init__.py +++ b/kyu_8/grasshopper_summation/__init__.py @@ -0,0 +1 @@ +"""Grasshopper - Summation.""" diff --git a/kyu_8/grasshopper_summation/summation.py b/kyu_8/grasshopper_summation/summation.py index 244c2dd01d4..b0d76af18ef 100644 --- a/kyu_8/grasshopper_summation/summation.py +++ b/kyu_8/grasshopper_summation/summation.py @@ -1,5 +1,6 @@ """ -Solution for -> Grasshopper - Summation +Solution for -> Grasshopper - Summation. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,12 +8,12 @@ def summation(num: int) -> int: """ - A program that finds the summation of every - number from 1 to num. + Find the summation of every number from 1 to num. + The number will always be a positive integer greater than 0. - :param num: - :return: + :param num: int + :return: int """ result: int = 0 for i in range(1, num + 1): diff --git a/kyu_8/grasshopper_summation/test_summation.py b/kyu_8/grasshopper_summation/test_summation.py index 888f66a3f9b..9463ac9c165 100644 --- a/kyu_8/grasshopper_summation/test_summation.py +++ b/kyu_8/grasshopper_summation/test_summation.py @@ -1,5 +1,6 @@ """ -Test for -> Grasshopper - Summation +Test for -> Grasshopper - Summation. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -8,6 +9,7 @@ import unittest import allure +from parameterized import parameterized from utils.log_func import print_log from kyu_8.grasshopper_summation.summation import summation @@ -28,14 +30,18 @@ name='Source/Kata') # pylint: enable=R0801 class SummationTestCase(unittest.TestCase): - """ - Testing summation function - """ + """Testing summation function.""" - def test_summation(self): + @parameterized.expand([ + (1, 1), + (8, 36), + (22, 253), + (100, 5050), + (213, 22791)]) + def test_summation(self, num, expected): """ - Testing summation function - with various test inputs + Testing summation function with various test inputs. + :return: """ # pylint: disable=R0801 @@ -43,21 +49,13 @@ def test_summation(self): allure.dynamic.severity(allure.severity_level.NORMAL) allure.dynamic.description_html( '

Codewars badge:

' - '' + '' '

Test Description:

' "

") # pylint: enable=R0801 - with allure.step("Enter number and verify the output"): - test_data: tuple = ( - (1, 1), - (8, 36), - (22, 253), - (100, 5050), - (213, 22791)) - - for d in test_data: - num: int = d[0] - expected: int = d[1] - print_log(num=num, expected=expected) - self.assertEqual(summation(num), expected) + with allure.step(f"Enter a number: {num} " + f"and verify the expected output: {expected}."): + print_log(num=num, expected=expected) + self.assertEqual(summation(num), expected) diff --git a/kyu_8/greek_sort/__init__.py b/kyu_8/greek_sort/__init__.py index e69de29bb2d..c7b87d9e076 100644 --- a/kyu_8/greek_sort/__init__.py +++ b/kyu_8/greek_sort/__init__.py @@ -0,0 +1 @@ +"""Greek Sort.""" diff --git a/kyu_8/greek_sort/evaluator.py b/kyu_8/greek_sort/evaluator.py index ed4a7f7f3f2..908e2b3e7ff 100644 --- a/kyu_8/greek_sort/evaluator.py +++ b/kyu_8/greek_sort/evaluator.py @@ -1,11 +1,15 @@ """ -Evaluates the expression +Evaluator function for -> Greek Sort. + +Created by Egor Kostan. +GitHub: https://github.com/ikostan """ def evaluator(result: int, expected: str) -> bool: """ - Evaluator + Compare two arguments. + :param result: int :param expected: str :return: bool diff --git a/kyu_8/greek_sort/greek_comparator.py b/kyu_8/greek_sort/greek_comparator.py index c3c6cb9665c..3be8ac276f6 100644 --- a/kyu_8/greek_sort/greek_comparator.py +++ b/kyu_8/greek_sort/greek_comparator.py @@ -1,5 +1,6 @@ """ -Solution for -> Greek Sort +Solution for -> Greek Sort. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -15,10 +16,12 @@ def greek_comparator(lhs: str, rhs: str) -> int: """ + Greek comparator function. + A custom comparison function of two arguments (iterable elements) which should return a negative, zero or positive number depending on whether the first argument is considered smaller than, equal to, - or larger than the second argument + or larger than the second argument. :param lhs: str :param rhs: str :return: int diff --git a/kyu_8/greek_sort/test_greek_comparator.py b/kyu_8/greek_sort/test_greek_comparator.py index e2f70debdf6..5213b0fc477 100644 --- a/kyu_8/greek_sort/test_greek_comparator.py +++ b/kyu_8/greek_sort/test_greek_comparator.py @@ -1,5 +1,6 @@ """ -Test for -> Greek Sort +Test for -> Greek Sort. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -8,6 +9,7 @@ import unittest import allure +from parameterized import parameterized from kyu_8.greek_sort.greek_comparator import greek_comparator from kyu_8.greek_sort.evaluator import evaluator from utils.log_func import print_log @@ -24,14 +26,16 @@ url='https://www.codewars.com/kata/56bc1acf66a2abc891000561', name='Source/Kata') class GreekComparatorTestCase(unittest.TestCase): - """ - Testing greek_comparator function - """ + """Testing greek_comparator function.""" - def test_greek_comparator(self): + @parameterized.expand([ + ('alpha', 'beta', '< 0'), + ('psi', 'psi', '== 0'), + ('upsilon', 'rho', '> 0')]) + def test_greek_comparator(self, lhs, rhs, expected): """ - Testing greek_comparator function - with various test inputs + Testing greek_comparator function with various test inputs. + :return: """ # pylint: disable=R0801 @@ -39,8 +43,9 @@ def test_greek_comparator(self): allure.dynamic.severity(allure.severity_level.NORMAL) allure.dynamic.description_html( '

Codewars badge:

' - '' + '' '

Test Description:

' "

A custom comparison function of two arguments (iterable" " elements) which should return a negative, zero or positive" @@ -48,26 +53,17 @@ def test_greek_comparator(self): " smaller than, equal to, or larger than the second argument" "

") # pylint: enable=R0801 - test_data: tuple = ( - ('alpha', 'beta', '< 0'), - ('psi', 'psi', '== 0'), - ('upsilon', 'rho', '> 0')) - - for d in test_data: - lhs, rhs, expected = d[0], d[1], d[2] - result = greek_comparator(lhs, rhs) - - with allure.step(f"Enter test inputs({lhs}, {rhs}) " - f"and assert expected ({expected}) " - f"vs actual result ({result})"): + result = greek_comparator(lhs, rhs) + with allure.step(f"Enter test inputs({lhs}, {rhs}) " + f"and assert expected ({expected}) " + f"vs actual result ({result})"): - expression: str = f'{result} {expected}' + expression: str = f'{result} {expected}' - print_log(lhs=lhs, - rhs=rhs, - expected=expected, - result=result, - expression=expression) + print_log(lhs=lhs, + rhs=rhs, + expected=expected, + result=result, + expression=expression) - self.assertTrue(evaluator(result=result, - expected=expected)) + self.assertTrue(evaluator(result=result, expected=expected)) diff --git a/kyu_8/holiday_vi_shark_pontoon/__init__.py b/kyu_8/holiday_vi_shark_pontoon/__init__.py index e69de29bb2d..d2ec6b21e8c 100644 --- a/kyu_8/holiday_vi_shark_pontoon/__init__.py +++ b/kyu_8/holiday_vi_shark_pontoon/__init__.py @@ -0,0 +1 @@ +"""Holiday VI - Shark Pontoon.""" diff --git a/kyu_8/holiday_vi_shark_pontoon/shark.py b/kyu_8/holiday_vi_shark_pontoon/shark.py index c1b97b07c7b..2decb2b5b55 100644 --- a/kyu_8/holiday_vi_shark_pontoon/shark.py +++ b/kyu_8/holiday_vi_shark_pontoon/shark.py @@ -1,5 +1,6 @@ """ -Solution for -> Holiday VI - Shark Pontoon +Solution for -> Holiday VI - Shark Pontoon. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -11,6 +12,8 @@ def shark(pontoon_distance, shark_speed, dolphin) -> str: """ + Shark function. + You are given 5 variables: sharkDistance = distance the shark needs to cover to eat you in metres, sharkSpeed = how fast it can move in metres/second, pontoonDistance = how far you need @@ -19,7 +22,6 @@ def shark(pontoon_distance, the swimming speed of the shark as the dolphin will attack it. If you make it, return "Alive!", if not, return "Shark Bait!". - :param pontoon_distance: :param shark_distance: :param you_speed: diff --git a/kyu_8/holiday_vi_shark_pontoon/test_shark.py b/kyu_8/holiday_vi_shark_pontoon/test_shark.py index 712bc97e21c..350946571f7 100644 --- a/kyu_8/holiday_vi_shark_pontoon/test_shark.py +++ b/kyu_8/holiday_vi_shark_pontoon/test_shark.py @@ -1,5 +1,6 @@ """ -Test for -> Holiday VI - Shark Pontoon +Test for -> Holiday VI - Shark Pontoon. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -26,13 +27,12 @@ url='https://www.codewars.com/kata/57e921d8b36340f1fd000059', name='Source/Kata') class SharkTestCase(unittest.TestCase): - """ - Testing shark function - """ + """Testing shark function.""" def test_shark_alive_1(self): """ - Testing shark function -> positive + Testing shark function -> positive #1. + :return: """ # pylint: disable=R0801 @@ -66,7 +66,8 @@ def test_shark_alive_1(self): def test_shark_alive_2(self): """ - Testing shark function -> positive + Testing shark function -> positive #2. + :return: """ # pylint: disable=R0801 @@ -100,7 +101,8 @@ def test_shark_alive_2(self): def test_shark_bait(self): """ - Testing shark function -> negative + Testing shark function -> negative. + :return: """ # pylint: disable=R0801 diff --git a/kyu_8/is_it_a_palindrome/__init__.py b/kyu_8/is_it_a_palindrome/__init__.py index e69de29bb2d..d96511f544b 100644 --- a/kyu_8/is_it_a_palindrome/__init__.py +++ b/kyu_8/is_it_a_palindrome/__init__.py @@ -0,0 +1 @@ +"""Is it a palindrome.""" diff --git a/kyu_8/is_it_a_palindrome/is_palindrome.py b/kyu_8/is_it_a_palindrome/is_palindrome.py index 0e0afcb961b..88ba9606d18 100644 --- a/kyu_8/is_it_a_palindrome/is_palindrome.py +++ b/kyu_8/is_it_a_palindrome/is_palindrome.py @@ -1,5 +1,6 @@ """ -Solution for -> Is it a palindrome? +Solution for -> Is it a palindrome?. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,8 +8,10 @@ def is_palindrome(s: str) -> bool: """ + Palindrome testing function. + Write function isPalindrome that checks if - a given string (case insensitive) is a palindrome. + a given string (case-insensitive) is a palindrome. :param s: str :return: bool """ diff --git a/kyu_8/is_it_a_palindrome/test_is_palindrome.py b/kyu_8/is_it_a_palindrome/test_is_palindrome.py index 71fea953daf..5d28ea002fe 100644 --- a/kyu_8/is_it_a_palindrome/test_is_palindrome.py +++ b/kyu_8/is_it_a_palindrome/test_is_palindrome.py @@ -1,5 +1,6 @@ """ -Test for -> Is it a palindrome? +Test for -> Is it a palindrome?. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -8,6 +9,7 @@ import unittest import allure +from parameterized import parameterized from utils.log_func import print_log from kyu_8.is_it_a_palindrome.is_palindrome import is_palindrome @@ -25,18 +27,28 @@ name='Source/Kata') # pylint: enable=R0801 class IsPalindromeTestCase(unittest.TestCase): - """ - Testing is_palindrome function - """ + """Testing is_palindrome function.""" - def test_is_palindrome(self): + @parameterized.expand([ + ('a', True), + ('aba', True), + ('Abba', True), + ('malam', True), + ('walter', False), + ('kodok', True), + ('Kasue', False), + ('NdjXglGnYGKhQtuAcxNWFwVRZZDMrFmiOPMZsvr', False), + ('XqmUTaAmrrYitgNwkCwaWdFYsEhfIeOohViba', False), + ('ZtItThFBUPCSCbtcUfDwXzyajhRIWioUHpVzN', False), + ('XqNeuBjbshHwqjoUNGHhVRolqxWRRWYYbN', False)]) + def test_is_palindrome(self, string, expected): """ - Testing is_palindrome function - with various test inputs + Testing is_palindrome function with various test inputs. The function should check if a - given string (case insensitive) + given string (case-insensitive) is a palindrome. + :return: """ # pylint: disable=R0801 allure.dynamic.title("Testing is_palindrome function") @@ -46,22 +58,10 @@ def test_is_palindrome(self): '' '

Test Description:

' - "

") - - with allure.step("Enter test string and verify the output"): - test_data: tuple = ( - ('a', True), - ('aba', True), - ('Abba', True), - ('malam', True), - ('walter', False), - ('kodok', True), - ('Kasue', False), - ('NdjXglGnYGKhQtuAcxNWFwVRZZDMrFmiOPMZsvr', False), - ('XqmUTaAmrrYitgNwkCwaWdFYsEhfIeOohViba', False), - ('ZtItThFBUPCSCbtcUfDwXzyajhRIWioUHpVzN', False), - ('XqNeuBjbshHwqjoUNGHhVRolqxWRRWYYbN', False)) + "

isPalindrome that checks if a given string " + "(case insensitive) is a palindrome.

") - for string, expected in test_data: - print_log(string=string, expected=expected) - self.assertEqual(expected, is_palindrome(string)) + with allure.step(f"Enter test string: {string} " + f"and verify expected output: {expected}."): + print_log(string=string, expected=expected) + self.assertEqual(expected, is_palindrome(string)) diff --git a/kyu_8/is_your_period_late/__init__.py b/kyu_8/is_your_period_late/__init__.py index e69de29bb2d..0328c3963b9 100644 --- a/kyu_8/is_your_period_late/__init__.py +++ b/kyu_8/is_your_period_late/__init__.py @@ -0,0 +1 @@ +"""Is your period late.""" diff --git a/kyu_8/is_your_period_late/is_your_period_late.py b/kyu_8/is_your_period_late/is_your_period_late.py index 122f68b50c8..c310e5f4213 100644 --- a/kyu_8/is_your_period_late/is_your_period_late.py +++ b/kyu_8/is_your_period_late/is_your_period_late.py @@ -1,5 +1,6 @@ """ -Solution for -> Is your period late +Solution for -> Is your period late. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ diff --git a/kyu_8/is_your_period_late/test_is_your_period_late.py b/kyu_8/is_your_period_late/test_is_your_period_late.py index eb75b23032f..b47b73b21f7 100644 --- a/kyu_8/is_your_period_late/test_is_your_period_late.py +++ b/kyu_8/is_your_period_late/test_is_your_period_late.py @@ -1,5 +1,6 @@ """ -Test for -> Is your period late +Test for -> Is your period late. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -27,13 +28,12 @@ name='Source/Kata') # pylint: enable=R0801 class PeriodIsLateTestCase(unittest.TestCase): - """ - Testing period_is_late function - """ + """Testing period_is_late function.""" def test_period_is_late_positive(self): """ - Positive tests + Positive tests. + :return: """ # pylint: disable=R0801 @@ -44,7 +44,7 @@ def test_period_is_late_positive(self): '' '

Test Description:

' - "

") + "

Positive tests.

") # pylint: enable=R0801 with allure.step("Pass last, today and period length"): last: date = date(2016, 6, 13) @@ -96,7 +96,8 @@ def test_period_is_late_positive(self): def test_period_is_late_negative(self): """ - Negative tests + Negative tests. + :return: """ # pylint: disable=R0801 @@ -107,7 +108,7 @@ def test_period_is_late_negative(self): '' '

Test Description:

' - "

") + "

Negative tests.

") # pylint: enable=R0801 with allure.step("Pass last, today and period length"): last: date = date(2016, 6, 13) diff --git a/kyu_8/keep_hydrated/__init__.py b/kyu_8/keep_hydrated/__init__.py index e69de29bb2d..7240da1b8cc 100644 --- a/kyu_8/keep_hydrated/__init__.py +++ b/kyu_8/keep_hydrated/__init__.py @@ -0,0 +1 @@ +"""Keep Hydrated.""" diff --git a/kyu_8/keep_hydrated/keep_hydrated.py b/kyu_8/keep_hydrated/keep_hydrated.py index 454ab57d457..a1bf20807cb 100644 --- a/kyu_8/keep_hydrated/keep_hydrated.py +++ b/kyu_8/keep_hydrated/keep_hydrated.py @@ -1,5 +1,6 @@ """ -Solution for -> Keep Hydrated! +Solution for -> Keep Hydrated!. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,6 +8,8 @@ def litres(time) -> int: """ + 'litres' function. + Because Nathan knows it is important to stay hydrated, he drinks 0.5 litres of water per hour of cycling. diff --git a/kyu_8/keep_hydrated/test_keep_hydrated.py b/kyu_8/keep_hydrated/test_keep_hydrated.py index e8e64b29b50..54f73cc6f56 100644 --- a/kyu_8/keep_hydrated/test_keep_hydrated.py +++ b/kyu_8/keep_hydrated/test_keep_hydrated.py @@ -1,5 +1,6 @@ """ -Test for -> Keep Hydrated! +Test for -> Keep Hydrated!. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -8,6 +9,7 @@ import unittest import allure +from parameterized import parameterized from utils.log_func import print_log from kyu_8.keep_hydrated.keep_hydrated import litres @@ -28,13 +30,20 @@ name='Source/Kata') # pylint: disable=R0801 class KeepHydratedTestCase(unittest.TestCase): - """ - Testing litres function - """ + """Testing litres function.""" - def test_keep_hydrated(self): + @parameterized.expand([ + (2, 1, 'should return 1 litre'), + (1.4, 0, 'should return 0 litres'), + (12.3, 6, 'should return 6 litres'), + (0.82, 0, 'should return 0 litres'), + (11.8, 5, 'should return 5 litres'), + (1787, 893, 'should return 893 litres'), + (0, 0, 'should return 0 litres')]) + def test_keep_hydrated(self, hours, expected, message): """ - Testing litres function with various test inputs + Testing litres function with various test inputs. + :return: """ # pylint: disable=R0801 @@ -45,18 +54,17 @@ def test_keep_hydrated(self): '' '

Test Description:

' - "

") + "

" + "Because Nathan knows it is important to stay hydrated, " + " he drinks 0.5 litres of water per hour of cycling." + "

" + "

" + "You get given the time in hours and you need to return " + "the number of litres Nathan will drink, rounded " + "to the smallest value." + "

") # pylint: enable=R0801 - with allure.step("Enter hours and verify the output"): - test_data: tuple = ( - (2, 1, 'should return 1 litre'), - (1.4, 0, 'should return 0 litres'), - (12.3, 6, 'should return 6 litres'), - (0.82, 0, 'should return 0 litres'), - (11.8, 5, 'should return 5 litres'), - (1787, 893, 'should return 893 litres'), - (0, 0, 'should return 0 litres')) - - for hours, expected, message in test_data: - print_log(hours=hours, expected=expected) - self.assertEqual(expected, litres(hours), message) + with allure.step(f"Enter hours: {hours} " + f"and verify the expected output: {expected}."): + print_log(hours=hours, expected=expected) + self.assertEqual(expected, litres(hours), message) diff --git a/kyu_8/keep_up_the_hoop/__init__.py b/kyu_8/keep_up_the_hoop/__init__.py index e69de29bb2d..c1749419584 100644 --- a/kyu_8/keep_up_the_hoop/__init__.py +++ b/kyu_8/keep_up_the_hoop/__init__.py @@ -0,0 +1 @@ +"""Keep up the hoop.""" diff --git a/kyu_8/keep_up_the_hoop/hoop_count.py b/kyu_8/keep_up_the_hoop/hoop_count.py index bff4cedf9a5..9badc57f057 100644 --- a/kyu_8/keep_up_the_hoop/hoop_count.py +++ b/kyu_8/keep_up_the_hoop/hoop_count.py @@ -1,5 +1,6 @@ """ -Solution -> Keep up the hoop +Solution -> Keep up the hoop. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,9 +8,10 @@ def hoop_count(n: int) -> str: """ - A program where Alex can input (n) how many times the - hoop goes round and it will return him an encouraging message + 'hoop_count' function. + A program where Alex can input (n) how many times the + hoop goes round, and it will return him an encouraging message :param n: int :return: str """ diff --git a/kyu_8/keep_up_the_hoop/test_hoop_count.py b/kyu_8/keep_up_the_hoop/test_hoop_count.py index ee377488e2d..fa5ae53c944 100644 --- a/kyu_8/keep_up_the_hoop/test_hoop_count.py +++ b/kyu_8/keep_up_the_hoop/test_hoop_count.py @@ -1,5 +1,6 @@ """ -Test -> Keep up the hoop +Test -> Keep up the hoop. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -25,22 +26,19 @@ name='Source/Kata') # pylint: enable=R0801 class HoopCountTestCase(unittest.TestCase): - """ - Testing hoop_count function - """ + """Testing hoop_count function.""" def test_hoop_count_positive(self): """ - Testing hoop_count function (positive) + Testing hoop_count function (positive). - Alex just got a new hula hoop, he loves it but feels + Alex just got a new hula-hoop, he loves it but feels discouraged because his little brother is better than him Write a program where Alex can input (n) how many times the hoop goes round and it will return him an encouraging message - 10 or more hoops, return "Great, now move on to tricks". - - Not 10 hoops, return "Keep at it until you get it". :return: @@ -54,7 +52,7 @@ def test_hoop_count_positive(self): '' '

Test Description:

' - "

") + "

Testing hoop_count function (positive).

") # pylint: enable=R0801 with allure.step("Enter n and verify the result"): n: int = 11 @@ -64,7 +62,8 @@ def test_hoop_count_positive(self): def test_hoop_count_negative(self): """ - Testing hoop_count function (negative) + Testing hoop_count function (negative). + :return: """ # pylint: disable=R0801 @@ -76,7 +75,7 @@ def test_hoop_count_negative(self): '' '

Test Description:

' - "

") + "

Testing hoop_count function (negative).

") # pylint: enable=R0801 with allure.step("Enter n and verify the result"): n: int = 3 diff --git a/kyu_8/logical_calculator/__init__.py b/kyu_8/logical_calculator/__init__.py index e69de29bb2d..ef9d65f99ea 100644 --- a/kyu_8/logical_calculator/__init__.py +++ b/kyu_8/logical_calculator/__init__.py @@ -0,0 +1 @@ +"""Logical calculator.""" diff --git a/kyu_8/logical_calculator/logical_calculator.py b/kyu_8/logical_calculator/logical_calculator.py index 4bcf26788e6..39cfbe75614 100644 --- a/kyu_8/logical_calculator/logical_calculator.py +++ b/kyu_8/logical_calculator/logical_calculator.py @@ -1,5 +1,6 @@ """ -Solution for -> Logical Calculator +Solution for -> Logical Calculator. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,7 +8,7 @@ def logical_calc(array: list, op: str) -> bool: """ - Calculates logical value of boolean array. + Calculate logical value of boolean array. Logical operations: AND, OR and XOR. diff --git a/kyu_8/logical_calculator/test_logical_calculator.py b/kyu_8/logical_calculator/test_logical_calculator.py index 7f4e11cc220..875e0f8bfa1 100644 --- a/kyu_8/logical_calculator/test_logical_calculator.py +++ b/kyu_8/logical_calculator/test_logical_calculator.py @@ -1,5 +1,6 @@ """ -Test for -> Logical Calculator +Test for -> Logical Calculator. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -27,21 +28,17 @@ name='Source/Kata') # pylint: enable=R0801 class LogicalCalculatorTestCase(unittest.TestCase): - """ - Testing logical_calc function - """ + """Testing logical_calc function.""" def test_logical_calc_and(self): """ - And (∧) is the truth-functional - operator of logical conjunction + And (∧) is the truth-functional operator of logical conjunction. - The and of a set of operands is true + The 'and' of a set of operands is true if and only if all of its operands are true. Source: https://en.wikipedia.org/wiki/Logical_conjunction - :return: """ # pylint: disable=R0801 @@ -49,10 +46,13 @@ def test_logical_calc_and(self): allure.dynamic.severity(allure.severity_level.NORMAL) allure.dynamic.description_html( '

Codewars badge:

' - '' + '' '

Test Description:

' - "

") + "

The 'and' of a set of operands is true " + "if and only if all of its operands are true." + "

") # pylint: enable=R0801 with allure.step("Pass an array with 2 members (negative)"): lst: list = [True, False] @@ -97,11 +97,13 @@ def test_logical_calc_and(self): def test_logical_calc_or(self): """ + Testing 'or'. + In logic and mathematics, or is the truth-functional operator of (inclusive) disjunction, also known as alternation. - The or of a set of operands is true if + The 'or' of a set of operands is true if and only if one or more of its operands is true. Source: @@ -117,7 +119,10 @@ def test_logical_calc_or(self): '' '

Test Description:

' - "

") + "

" + "The 'or' of a set of operands is true if " + "and only if one or more of its operands is true." + "

") # pylint: enable=R0801 with allure.step('Pass an array with 2 members (positive)'): lst: list = [True, False] @@ -155,7 +160,9 @@ def test_logical_calc_or(self): def test_logical_calc_xor(self): """ - Exclusive or or exclusive disjunction is a + Testing 'XOR'. + + Exclusive or exclusive disjunction is a logical operation that outputs true only when inputs differ (one is true, the other is false). @@ -170,10 +177,11 @@ def test_logical_calc_xor(self): allure.dynamic.severity(allure.severity_level.NORMAL) allure.dynamic.description_html( '

Codewars badge:

' - '' + '' '

Test Description:

' - "

") + "

XOR outputs true whenever the inputs differ.

") # pylint: enable=R0801 with allure.step('Pass an array with 2 members (positive)'): lst: list = [True, False] diff --git a/kyu_8/make_upper_case/__init__.py b/kyu_8/make_upper_case/__init__.py index e69de29bb2d..f1eedc12b18 100644 --- a/kyu_8/make_upper_case/__init__.py +++ b/kyu_8/make_upper_case/__init__.py @@ -0,0 +1 @@ +"""MakeUpperCase.""" diff --git a/kyu_8/make_upper_case/make_upper_case.py b/kyu_8/make_upper_case/make_upper_case.py index bdf110549ba..b2dd792edbb 100644 --- a/kyu_8/make_upper_case/make_upper_case.py +++ b/kyu_8/make_upper_case/make_upper_case.py @@ -1,5 +1,6 @@ """ -Solution for -> MakeUpperCase +Solution for -> MakeUpperCase. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,7 +8,8 @@ def make_upper_case(s: str) -> str: """ - Function that make UpperCase. + Convert to UpperCase. + :param s: str :return: str """ diff --git a/kyu_8/make_upper_case/test_make_upper_case.py b/kyu_8/make_upper_case/test_make_upper_case.py index 8b4e69f812f..e91e66ce0e9 100644 --- a/kyu_8/make_upper_case/test_make_upper_case.py +++ b/kyu_8/make_upper_case/test_make_upper_case.py @@ -1,5 +1,6 @@ """ -Test for -> MakeUpperCase +Test for -> MakeUpperCase. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -25,13 +26,12 @@ name='Source/Kata') # pylint: enable=R0801 class MakeUpperCaseTestCase(unittest.TestCase): - """ - Testing make_upper_case function - """ + """Testing make_upper_case function.""" def test_make_upper_case(self): """ - Sample Tests for make_upper_case function + Sample Tests for make_upper_case function. + :return: """ # pylint: disable=R0801 @@ -39,10 +39,12 @@ def test_make_upper_case(self): allure.dynamic.severity(allure.severity_level.NORMAL) allure.dynamic.description_html( '

Codewars badge:

' - '' + '' '

Test Description:

' - "

") + "

Make sure 'make_upper_case' function convert " + "strings to UpperCase.

") # pylint: enable=R0801 with allure.step("Pass lower case string and verify the output"): string: str = "hello" diff --git a/kyu_8/multiply/__init__.py b/kyu_8/multiply/__init__.py index e69de29bb2d..b14368ed6b5 100644 --- a/kyu_8/multiply/__init__.py +++ b/kyu_8/multiply/__init__.py @@ -0,0 +1 @@ +"""Multiply.""" diff --git a/kyu_8/multiply/multiply.py b/kyu_8/multiply/multiply.py index 2ee767034da..d229bbee71a 100644 --- a/kyu_8/multiply/multiply.py +++ b/kyu_8/multiply/multiply.py @@ -1,9 +1,5 @@ """ -Multiply Problem Description -The code does not execute properly. Try to figure out why. - -def multiply(a, b): - a * b +Solution for -> Multiply problem. Created by Egor Kostan. GitHub: https://github.com/ikostan @@ -12,9 +8,10 @@ def multiply(a, b): def multiply(a: int, b: int) -> int: """ - Multiply two numbers and return the result - :param a: - :param b: - :return: + Multiply two numbers and return the result. + + :param a: int + :param b: int + :return: int """ return a * b diff --git a/kyu_8/multiply/test_multiply.py b/kyu_8/multiply/test_multiply.py index ad3ad6eacd0..b88e820f674 100644 --- a/kyu_8/multiply/test_multiply.py +++ b/kyu_8/multiply/test_multiply.py @@ -1,5 +1,6 @@ """ -Test for -> Multiply +Test for -> Multiply. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -26,14 +27,12 @@ name='Source/Kata') # pylint: enable-msg=R0801 class MultiplyTestCase(unittest.TestCase): - """ - Testing multiply function - """ + """Testing multiply function.""" def test_multiply(self): """ - Verify that multiply function - returns correct result + Verify that multiply function returns correct results. + :return: """ # pylint: disable-msg=R0801 diff --git a/kyu_8/my_head_is_at_the_wrong_end/__init__.py b/kyu_8/my_head_is_at_the_wrong_end/__init__.py index e69de29bb2d..3e664a34072 100644 --- a/kyu_8/my_head_is_at_the_wrong_end/__init__.py +++ b/kyu_8/my_head_is_at_the_wrong_end/__init__.py @@ -0,0 +1 @@ +"""My head is at the wrong end.""" diff --git a/kyu_8/my_head_is_at_the_wrong_end/fix_the_meerkat.py b/kyu_8/my_head_is_at_the_wrong_end/fix_the_meerkat.py index e8712249bf6..2fd21c771ca 100644 --- a/kyu_8/my_head_is_at_the_wrong_end/fix_the_meerkat.py +++ b/kyu_8/my_head_is_at_the_wrong_end/fix_the_meerkat.py @@ -1,5 +1,6 @@ """ -Solution for -> My head is at the wrong end! +Solution for -> My head is at the wrong end!. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,11 +8,9 @@ def fix_the_meerkat(arr: list) -> list: """ - You will be given an array which will have - three values (tail, body, head). - It is your job to re-arrange the array so - that the animal is the right way round - (head, body, tail). + 'fix_the_meerkat' function. + + Reversing a List in Python. :param arr: :return: """ diff --git a/kyu_8/my_head_is_at_the_wrong_end/test_fix_the_meerkat.py b/kyu_8/my_head_is_at_the_wrong_end/test_fix_the_meerkat.py index 66331140cb1..92fedecf622 100644 --- a/kyu_8/my_head_is_at_the_wrong_end/test_fix_the_meerkat.py +++ b/kyu_8/my_head_is_at_the_wrong_end/test_fix_the_meerkat.py @@ -1,5 +1,6 @@ """ -Test for -> My head is at the wrong end! +Test for -> My head is at the wrong end!. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -8,6 +9,7 @@ import unittest import allure +from parameterized import parameterized from utils.log_func import print_log from kyu_8.my_head_is_at_the_wrong_end.fix_the_meerkat \ import fix_the_meerkat @@ -30,13 +32,24 @@ # pylint: enable=R0801 # @pytest.mark.skip(reason="The solution is not ready") class FixTheMeerkatTestCase(unittest.TestCase): - """ - Testing fix_the_meerkat function - """ + """Testing fix_the_meerkat function.""" - def test_fix_the_meerkat(self): + @parameterized.expand([ + (["tail", "body", "head"], ["head", "body", "tail"]), + (["tails", "body", "heads"], ["heads", "body", "tails"]), + (["bottom", "middle", "top"], ["top", "middle", "bottom"]), + (["lower legs", "torso", "upper legs"], + ["upper legs", "torso", "lower legs"]), + (["ground", "rainbow", "sky"], ["sky", "rainbow", "ground"])]) + def test_fix_the_meerkat(self, arr, expected): """ - Testing fix_the_meerkat function with various test data + Testing fix_the_meerkat function with various test data. + + You will be given an array which will have + three values (tail, body, head). + It is your job to re-arrange the array so + that the animal is the right way round + (head, body, tail). :return: """ # pylint: disable=R0801 @@ -54,21 +67,9 @@ def test_fix_the_meerkat(self): "so that the animal is the right way round (head, body, tail)." "

") # pylint: disable=R0801 - test_data: tuple = ( - (["tail", "body", "head"], ["head", "body", "tail"]), - (["tails", "body", "heads"], ["heads", "body", "tails"]), - (["bottom", "middle", "top"], ["top", "middle", "bottom"]), - (["lower legs", "torso", "upper legs"], - ["upper legs", "torso", "lower legs"]), - (["ground", "rainbow", "sky"], ["sky", "rainbow", "ground"])) - - for data in test_data: - arr: list = data[0] - expected: list = data[1] - result: list = fix_the_meerkat(arr) - - with allure.step(f"Enter test data: {arr} " - f"and assert actual result: {result} " - f"vs expected: {expected}"): - print_log(arr=arr, result=result, expected=expected) - self.assertEqual(expected, result) + result: list = fix_the_meerkat(arr) + with allure.step(f"Enter test data: {arr} " + f"and assert actual result: {result} " + f"vs expected: {expected}"): + print_log(arr=arr, result=result, expected=expected) + self.assertEqual(expected, result) diff --git a/kyu_8/remove_first_and_last_character/__init__.py b/kyu_8/remove_first_and_last_character/__init__.py index e69de29bb2d..d4dad132afd 100644 --- a/kyu_8/remove_first_and_last_character/__init__.py +++ b/kyu_8/remove_first_and_last_character/__init__.py @@ -0,0 +1 @@ +"""Remove First and Last Character.""" diff --git a/kyu_8/remove_first_and_last_character/remove_char.py b/kyu_8/remove_first_and_last_character/remove_char.py index 305ad603678..4f9f7de5c68 100644 --- a/kyu_8/remove_first_and_last_character/remove_char.py +++ b/kyu_8/remove_first_and_last_character/remove_char.py @@ -1,5 +1,6 @@ """ -Solution for -> Remove First and Last Character +Solution for -> Remove First and Last Character. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,13 +8,10 @@ def remove_char(s: str) -> str: """ - A function that removes the first and - last characters of a string. + Remove the first and last characters of a string. You're given one parameter, the original string. - - You don't have to worry with strings - with less than two characters. + You don't have to worry with strings with less than two characters. :param s: str :return: str """ diff --git a/kyu_8/remove_first_and_last_character/test_remove_char.py b/kyu_8/remove_first_and_last_character/test_remove_char.py index 104e80bb659..660a6480b51 100644 --- a/kyu_8/remove_first_and_last_character/test_remove_char.py +++ b/kyu_8/remove_first_and_last_character/test_remove_char.py @@ -1,5 +1,6 @@ """ -Test for -> Remove First and Last Character +Test for -> Remove First and Last Character. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -28,15 +29,13 @@ name='Source/Kata') # pylint: enable=R0801 class RemoveCharTestCase(unittest.TestCase): - """ - Testing remove_char function - """ + """Testing remove_char function.""" def test_remove_char(self): """ - Test that 'remove_char' function - removes the first and - last characters of a string. + Test 'remove_char' function. + + Should remove the first and last characters of a string. :return: """ # pylint: disable=R0801 diff --git a/kyu_8/remove_string_spaces/__init__.py b/kyu_8/remove_string_spaces/__init__.py index e69de29bb2d..9539c9e46bb 100644 --- a/kyu_8/remove_string_spaces/__init__.py +++ b/kyu_8/remove_string_spaces/__init__.py @@ -0,0 +1 @@ +"""Remove String Spaces.""" diff --git a/kyu_8/remove_string_spaces/remove_string_spaces.py b/kyu_8/remove_string_spaces/remove_string_spaces.py index 38d0fcd0605..0711227dd0d 100644 --- a/kyu_8/remove_string_spaces/remove_string_spaces.py +++ b/kyu_8/remove_string_spaces/remove_string_spaces.py @@ -1,5 +1,6 @@ """ -Solution for -> Remove String Spaces +Solution for -> Remove String Spaces. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,8 +8,8 @@ def no_space(x: str) -> str: """ - Remove the spaces from the string, - then return the resultant string. + Remove the spaces from the string. + :param x: str :return: str """ diff --git a/kyu_8/remove_string_spaces/test_remove_string_spaces.py b/kyu_8/remove_string_spaces/test_remove_string_spaces.py index a2f9bbe5b8b..08a9ab566fc 100644 --- a/kyu_8/remove_string_spaces/test_remove_string_spaces.py +++ b/kyu_8/remove_string_spaces/test_remove_string_spaces.py @@ -1,5 +1,6 @@ """ -Test for -> Remove String Spaces +Test for -> Remove String Spaces. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -28,14 +29,12 @@ name='Source/Kata') # pylint: enable-msg=R0801 class NoSpaceTestCase(unittest.TestCase): - """ - Testing no_space function - """ + """Testing no_space function.""" def test_something(self): """ - Test that no_space function removes the spaces - from the string, then return the resultant string. + Test that no_space function with various test dara. + :return: """ # pylint: disable-msg=R0801 diff --git a/kyu_8/reversed_strings/__init__.py b/kyu_8/reversed_strings/__init__.py index e69de29bb2d..0dd0ef57568 100644 --- a/kyu_8/reversed_strings/__init__.py +++ b/kyu_8/reversed_strings/__init__.py @@ -0,0 +1 @@ +"""Reversed Strings.""" diff --git a/kyu_8/reversed_strings/reversed_strings.py b/kyu_8/reversed_strings/reversed_strings.py index ae23a18de99..76c8a9ca868 100644 --- a/kyu_8/reversed_strings/reversed_strings.py +++ b/kyu_8/reversed_strings/reversed_strings.py @@ -1,5 +1,6 @@ """ -Solution for -> Reversed Strings +Solution for -> Reversed Strings. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,7 +8,8 @@ def solution(string: str) -> str: """ - reverses the string value passed into it + Reverse the string value. + :param string: str :return: str """ diff --git a/kyu_8/reversed_strings/test_reversed_strings.py b/kyu_8/reversed_strings/test_reversed_strings.py index 53188413bf7..14414a52021 100644 --- a/kyu_8/reversed_strings/test_reversed_strings.py +++ b/kyu_8/reversed_strings/test_reversed_strings.py @@ -1,5 +1,6 @@ """ -Test for -> Reversed Strings +Test for -> Reversed Strings. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -26,13 +27,12 @@ name='Source/Kata') # pylint: enable=R0801 class ReversedStringsTestCase(unittest.TestCase): - """ - Testing the solution for 'Reversed Strings' problem - """ + """Testing the solution for 'Reversed Strings' problem.""" def test_reversed_strings_empty(self): """ - Test with empty string + Test with empty string. + :return: """ # pylint: disable=R0801 @@ -53,7 +53,8 @@ def test_reversed_strings_empty(self): def test_reversed_strings_one_char(self): """ - Test with one char only + Test with one char only. + :return: """ # pylint: disable=R0801 @@ -74,7 +75,8 @@ def test_reversed_strings_one_char(self): def test_reversed_strings(self): """ - Test with regular string + Test with regular string. + :return: """ # pylint: disable=R0801 diff --git a/kyu_8/set_alarm/__init__.py b/kyu_8/set_alarm/__init__.py index e69de29bb2d..0c0881410bf 100644 --- a/kyu_8/set_alarm/__init__.py +++ b/kyu_8/set_alarm/__init__.py @@ -0,0 +1 @@ +"""L1: Set Alarm.""" diff --git a/kyu_8/set_alarm/set_alarm.py b/kyu_8/set_alarm/set_alarm.py index 176c42c2862..45df87cc92e 100644 --- a/kyu_8/set_alarm/set_alarm.py +++ b/kyu_8/set_alarm/set_alarm.py @@ -1,5 +1,6 @@ """ -Test for -> L1: Set Alarm +Test for -> L1: Set Alarm. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,28 +8,19 @@ def set_alarm(employed: bool, vacation: bool) -> bool: """ + 'set_alarm' function. + A function named setAlarm which receives two parameters. The first parameter, employed, is true whenever you are employed and the second parameter, vacation is true whenever you are on vacation. - The function should return true if you are employed and - not on vacation (because these are the circumstances under - which you need to set an alarm). It should return false - otherwise. - Examples: - - setAlarm(true, true) -> false - setAlarm(false, true) -> false - setAlarm(false, false) -> false - setAlarm(true, false) -> true :param employed: bool :param vacation: bool :return: bool """ - if employed and not vacation: return True return False diff --git a/kyu_8/set_alarm/test_set_alarm.py b/kyu_8/set_alarm/test_set_alarm.py index c5767adfa0a..0b0643f102f 100644 --- a/kyu_8/set_alarm/test_set_alarm.py +++ b/kyu_8/set_alarm/test_set_alarm.py @@ -1,5 +1,6 @@ """ -Test for -> L1: Set Alarm +Test for -> L1: Set Alarm. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -8,6 +9,7 @@ import unittest import allure +from parameterized import parameterized from utils.log_func import print_log from kyu_8.set_alarm.set_alarm import set_alarm @@ -26,11 +28,22 @@ name='Source/Kata') # pylint: enable=R0801 class SetAlarmTestCase(unittest.TestCase): - """ - Testing set_alarm function - """ + """Testing set_alarm function.""" - def test_set_alarm(self): + @parameterized.expand([ + ((True, True), + False, + "Fails when input is True, True"), + ((False, True), + False, + "Fails when input is False, True"), + ((False, False), + False, + "Fails when input is False, False"), + ((True, False), + True, + "Fails when input is True, False")]) + def test_set_alarm(self, test_input, expected, msg): """ Testing set_alarm function with various test inputs. @@ -40,7 +53,6 @@ def test_set_alarm(self): false otherwise. Examples: - setAlarm(true, true) -> false setAlarm(false, true) -> false setAlarm(false, false) -> false @@ -55,31 +67,22 @@ def test_set_alarm(self): '' '

Test Description:

' - "

") + "

" + "The function should return true if you are employed and " + "not on vacation (because these are the circumstances under " + "which you need to set an alarm). It should return false " + "otherwise." + '

' + '

' + 'Examples:' + '
' + 'setAlarm(true, true) -> false
' + 'setAlarm(false, true) -> false
' + 'setAlarm(false, false) -> false
' + 'setAlarm(true, false) -> true
' + "

") # pylint: enable=R0801 with allure.step("Enter test data and verify the output"): - test_data: tuple = ( - ((True, True), - False, - "Fails when input is True, True"), - ((False, True), - False, - "Fails when input is False, True"), - ((False, False), - False, - "Fails when input is False, False"), - ((True, False), - True, - "Fails when input is True, False")) - - for test_input, expected, msg in test_data: - employed: bool = test_input[0] - vacation: bool = test_input[1] - - print_log(employed=employed, - vacation=vacation, - expected=expected) - - self.assertEqual(expected, - set_alarm(employed, vacation), - msg) + employed, vacation = test_input + print_log(employed=employed, vacation=vacation, expected=expected) + self.assertEqual(expected, set_alarm(employed, vacation), msg) diff --git a/kyu_8/surface_area_and_volume_of_box/__init__.py b/kyu_8/surface_area_and_volume_of_box/__init__.py index e69de29bb2d..58f15b59258 100644 --- a/kyu_8/surface_area_and_volume_of_box/__init__.py +++ b/kyu_8/surface_area_and_volume_of_box/__init__.py @@ -0,0 +1 @@ +"""Surface Area and Volume of a Box.""" diff --git a/kyu_8/surface_area_and_volume_of_box/get_size.py b/kyu_8/surface_area_and_volume_of_box/get_size.py index 33f8159f569..7361384429a 100644 --- a/kyu_8/surface_area_and_volume_of_box/get_size.py +++ b/kyu_8/surface_area_and_volume_of_box/get_size.py @@ -1,5 +1,6 @@ """ -Solution for -> Surface Area and Volume of a Box +Solution for -> Surface Area and Volume of a Box. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,8 +8,8 @@ def get_size(w: int, h: int, d: int) -> list: """ - Write a function that returns the total surface - area and volume of a box as an array: [area, volume] + Return the total surface area and volume of a box as an array. + :param w: :param h: :param d: diff --git a/kyu_8/surface_area_and_volume_of_box/test_get_size.py b/kyu_8/surface_area_and_volume_of_box/test_get_size.py index 90d3dc07ff7..b914d568173 100644 --- a/kyu_8/surface_area_and_volume_of_box/test_get_size.py +++ b/kyu_8/surface_area_and_volume_of_box/test_get_size.py @@ -1,5 +1,6 @@ """ -Test for -> Surface Area and Volume of a Box +Test for -> Surface Area and Volume of a Box. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -29,13 +30,12 @@ name='Source/Kata') # pylint: enable=R0801 class GetSizeTestCase(unittest.TestCase): - """ - Testing get_size function - """ + """Testing get_size function.""" def test_get_size(self): """ - Testing get_size function with various inputs + Testing get_size function with various inputs. + :return: """ # pylint: disable=R0801 diff --git a/kyu_8/swap_values/__init__.py b/kyu_8/swap_values/__init__.py index e69de29bb2d..b650c89caf8 100644 --- a/kyu_8/swap_values/__init__.py +++ b/kyu_8/swap_values/__init__.py @@ -0,0 +1 @@ +"""Swap Values.""" diff --git a/kyu_8/swap_values/swap_values.py b/kyu_8/swap_values/swap_values.py index 270bfe2619d..72c7d990dd2 100644 --- a/kyu_8/swap_values/swap_values.py +++ b/kyu_8/swap_values/swap_values.py @@ -1,5 +1,6 @@ """ -Solution for -> Swap Values +Solution for -> Swap Values. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,7 +8,8 @@ def swap_values(args: list) -> None: """ - Swap values + Swap values. + :param args: :return: """ diff --git a/kyu_8/swap_values/test_swap_values.py b/kyu_8/swap_values/test_swap_values.py index 76cb92557c9..8a9b5ebded0 100644 --- a/kyu_8/swap_values/test_swap_values.py +++ b/kyu_8/swap_values/test_swap_values.py @@ -1,5 +1,6 @@ """ -Test for -> Swap Values +Test for -> Swap Values. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -27,13 +28,13 @@ name='Source/Kata') # pylint: enable-msg=R0801 class SwapValuesTestCase(unittest.TestCase): - """ - Testing swap_values function - """ + """Testing swap_values function.""" def test_swap_values(self): """ - Testing swap_values function + Testing swap_values function with various test data. + + :return: """ # pylint: disable=R0801 allure.dynamic.title("Testing swap_values function") @@ -49,7 +50,6 @@ def test_swap_values(self): swap: list = [1, 2] expected: list = [2, 1] swap_values(swap) - print_log(list=swap, expected=expected) self.assertEqual(swap[0], 2) self.assertEqual(swap[1], 1) diff --git a/kyu_8/terminal_game_move_function/__init__.py b/kyu_8/terminal_game_move_function/__init__.py index e69de29bb2d..7b2d7af469e 100644 --- a/kyu_8/terminal_game_move_function/__init__.py +++ b/kyu_8/terminal_game_move_function/__init__.py @@ -0,0 +1 @@ +"""Grasshopper - Terminal game move function.""" diff --git a/kyu_8/terminal_game_move_function/terminal_game_move_function.py b/kyu_8/terminal_game_move_function/terminal_game_move_function.py index b57f9c4196f..34e3630693c 100644 --- a/kyu_8/terminal_game_move_function/terminal_game_move_function.py +++ b/kyu_8/terminal_game_move_function/terminal_game_move_function.py @@ -1,5 +1,6 @@ """ -Solution for -> Grasshopper - Terminal game move function +Solution for -> Grasshopper - Terminal game move function. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,11 +8,13 @@ def move(position: int, roll: int) -> int: """ + 'move' function. + A function for the terminal game that takes the current position of the hero and the roll (1-6) and return the new position. - :param position: - :param roll: - :return: + :param position: int + :param roll: int + :return: int """ return position + (roll * 2) diff --git a/kyu_8/terminal_game_move_function/test_terminal_game_move_function.py b/kyu_8/terminal_game_move_function/test_terminal_game_move_function.py index f236d17e6bd..dc8942074c8 100644 --- a/kyu_8/terminal_game_move_function/test_terminal_game_move_function.py +++ b/kyu_8/terminal_game_move_function/test_terminal_game_move_function.py @@ -1,5 +1,6 @@ """ -Test for -> Grasshopper - Terminal game move function +Test for -> Grasshopper - Terminal game move function. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -26,17 +27,12 @@ name='Source/Kata') # pylint: enable=R0801 class MoveTestCase(unittest.TestCase): - """ - Testing move function - """ + """Testing move function.""" def test_move(self): """ - The player rolls the dice and moves the number - of spaces indicated by the dice two times. + Testing 'move' function with various test data. - Pass position and roll and compare the output - to the expected result :return: """ # pylint: disable=R0801 @@ -47,7 +43,10 @@ def test_move(self): '' '

Test Description:

' - "

") + "

The player rolls the dice and moves the number" + "of spaces indicated by the dice two times.

" + "

Pass position and roll and compare the output" + "to the expected result.

") # pylint: enable=R0801 with allure.step("Test start position zero"): position: int = 0 diff --git a/kyu_8/the_feast_of_many_beasts/__init__.py b/kyu_8/the_feast_of_many_beasts/__init__.py index e69de29bb2d..affe7c98b82 100644 --- a/kyu_8/the_feast_of_many_beasts/__init__.py +++ b/kyu_8/the_feast_of_many_beasts/__init__.py @@ -0,0 +1 @@ +"""The Feast of Many Beasts.""" diff --git a/kyu_8/the_feast_of_many_beasts/feast.py b/kyu_8/the_feast_of_many_beasts/feast.py index d32a6f57b4c..f57febf2c20 100644 --- a/kyu_8/the_feast_of_many_beasts/feast.py +++ b/kyu_8/the_feast_of_many_beasts/feast.py @@ -1,5 +1,6 @@ """ -Solution for -> The Feast of Many Beasts +Solution for -> The Feast of Many Beasts. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,7 +8,9 @@ def feast(beast: str, dish: str) -> bool: """ - A function feast that takes the animal's name and + 'feast' function. + + A function that takes the animal's name and dish as arguments and returns true or false to indicate whether the beast is allowed to bring the dish to the feast. diff --git a/kyu_8/the_feast_of_many_beasts/test_feast.py b/kyu_8/the_feast_of_many_beasts/test_feast.py index 4e71ede1a98..7e3c9344973 100644 --- a/kyu_8/the_feast_of_many_beasts/test_feast.py +++ b/kyu_8/the_feast_of_many_beasts/test_feast.py @@ -1,5 +1,6 @@ """ -Test for -> The Feast of Many Beasts +Test for -> The Feast of Many Beasts. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -26,29 +27,12 @@ name='Source/Kata') # pylint: enable=R0801 class FeastTestCase(unittest.TestCase): - """ - Testing 'feast' function - """ + """Testing 'feast' function.""" def test_feast(self): """ - Testing 'feast' function with various test inputs - - Testing a function feast that takes the animal's - name and dish as arguments and returns true or - false to indicate whether the beast is allowed - to bring the dish to the feast. - - Assume that beast and dish are always lowercase strings, - and that each has at least two letters. beast and dish - may contain hyphens and spaces, but these will not appear - at the beginning or end of the string. They will not - contain numerals. + Testing 'feast' function with various test inputs. - There is just one rule: the dish must start and end with - the same letters as the animal's name. For example, the - great blue heron is bringing garlic naan and the chickadee - is bringing chocolate cake. :return: """ # pylint: disable=R0801 @@ -59,7 +43,19 @@ def test_feast(self): '' '

Test Description:

' - "

") + "

Testing a function feast that takes the animal's " + "name and dish as arguments and returns true or " + "false to indicate whether the beast is allowed " + "to bring the dish to the feast.

" + "

Assume that beast and dish are always lowercase strings, " + "and that each has at least two letters. beast and dish " + "may contain hyphens and spaces, but these will not appear " + "at the beginning or end of the string. They will not " + "contain numerals.

" + "

There is just one rule: the dish must start and end with " + "the same letters as the animal's name. For example, the " + "great blue heron is bringing garlic naan and the chickadee " + "is bringing chocolate cake.

") # pylint: enable=R0801 with allure.step("Enter animal's name and dish " "as arguments and assert the output"): diff --git a/kyu_8/third_angle_of_triangle/__init__.py b/kyu_8/third_angle_of_triangle/__init__.py index e69de29bb2d..5f11b606f95 100644 --- a/kyu_8/third_angle_of_triangle/__init__.py +++ b/kyu_8/third_angle_of_triangle/__init__.py @@ -0,0 +1 @@ +"""Third Angle of a Triangle.""" diff --git a/kyu_8/third_angle_of_triangle/test_third_angle_of_triangle.py b/kyu_8/third_angle_of_triangle/test_third_angle_of_triangle.py index c1cceafebcc..7066b65393e 100644 --- a/kyu_8/third_angle_of_triangle/test_third_angle_of_triangle.py +++ b/kyu_8/third_angle_of_triangle/test_third_angle_of_triangle.py @@ -1,5 +1,6 @@ """ -Test for -> Third Angle of a Triangle +Test for -> Third Angle of a Triangle. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -8,6 +9,7 @@ import unittest import allure +from parameterized import parameterized from utils.log_func import print_log from kyu_8.third_angle_of_triangle.third_angle_of_triangle \ import other_angle @@ -26,14 +28,17 @@ name='Source/Kata') # pylint: enable-msg=R0801 class OtherAngleTestCase(unittest.TestCase): - """ - Testing other_angle - """ - - def test_other_angle(self): + """Testing other_angle function.""" + + @parameterized.expand([ + (30, 60, 90), + (60, 60, 60), + (43, 78, 59), + (10, 20, 150)]) + def test_other_angle(self, a, b, expected): """ - You are given two angles (in degrees) of a triangle. - Find the 3rd. + Testing other_angle function with various test data. + :return: """ # pylint: disable-msg=R0801 @@ -44,49 +49,9 @@ def test_other_angle(self): '' '

Test Description:

' - "

") + "

You are given two angles (in degrees) of a triangle." + "Find the 3rd.

") # pylint: enable-msg=R0801 with allure.step("Enter values of two angles and return the 3rd"): - a: int = 30 - b: int = 60 - expected: int = 90 - - print_log(a=a, - b=b, - expected=expected) - - self.assertEqual(other_angle(a, b), expected) - - with allure.step("Enter values of two angles and return the 3rd"): - a = 60 - b = 60 - expected = 60 - - print_log(a=a, - b=b, - expected=expected) - - self.assertEqual(other_angle(a, b), expected) - self.assertEqual(other_angle(60, 60), 60) - - with allure.step("Enter values of two angles and return the 3rd"): - a = 43 - b = 78 - expected = 59 - - print_log(a=a, - b=b, - expected=expected) - - self.assertEqual(other_angle(a, b), expected) - - with allure.step("Enter values of two angles and return the 3rd"): - a = 10 - b = 20 - expected = 150 - - print_log(a=a, - b=b, - expected=expected) - + print_log(a=a, b=b, expected=expected) self.assertEqual(other_angle(a, b), expected) diff --git a/kyu_8/third_angle_of_triangle/third_angle_of_triangle.py b/kyu_8/third_angle_of_triangle/third_angle_of_triangle.py index 4be2862e8a5..560700e45e0 100644 --- a/kyu_8/third_angle_of_triangle/third_angle_of_triangle.py +++ b/kyu_8/third_angle_of_triangle/third_angle_of_triangle.py @@ -1,5 +1,6 @@ """ -Solution for -> Third Angle of a Triangle +Solution for -> Third Angle of a Triangle. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,6 +8,8 @@ def other_angle(a: int, b: int) -> int: """ + Calculate 3rd angle. + You are given two angles (in degrees) of a triangle. Write a function to return the 3rd. Note: only positive integers will be tested. diff --git a/kyu_8/well_of_ideas_easy_version/__init__.py b/kyu_8/well_of_ideas_easy_version/__init__.py index e69de29bb2d..c4a87c311a7 100644 --- a/kyu_8/well_of_ideas_easy_version/__init__.py +++ b/kyu_8/well_of_ideas_easy_version/__init__.py @@ -0,0 +1 @@ +"""Well of Ideas - Easy Version.""" diff --git a/kyu_8/well_of_ideas_easy_version/test_well_of_ideas_easy_version.py b/kyu_8/well_of_ideas_easy_version/test_well_of_ideas_easy_version.py index 98a48f7b720..a176416565b 100644 --- a/kyu_8/well_of_ideas_easy_version/test_well_of_ideas_easy_version.py +++ b/kyu_8/well_of_ideas_easy_version/test_well_of_ideas_easy_version.py @@ -1,5 +1,6 @@ """ -Tests for -> Well of Ideas - Easy Version +Tests for -> Well of Ideas - Easy Version. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -29,14 +30,12 @@ name='Source/Kata') # pylint: enable=R0801 class WellTestCase(unittest.TestCase): - """ - Testing well function - """ + """Testing 'well' function.""" def test_well_fail(self): """ - If there are no good ideas, - as is often the case, return 'Fail!'. + If there are no good ideas, as is often the case, return 'Fail!'. + :return: """ # pylint: disable=R0801 @@ -44,10 +43,11 @@ def test_well_fail(self): allure.dynamic.severity(allure.severity_level.NORMAL) allure.dynamic.description_html( '

Codewars badge:

' - '' + '' '

Test Description:

' - "

") + "

If there are no good ideas, return 'Fail!'.

") # pylint: enable=R0801 with allure.step("Pass list with no 'good' in it"): lst: list = ['bad', 'bad', 'bad'] @@ -57,8 +57,8 @@ def test_well_fail(self): def test_well_publish(self): """ - If there are one or two good ideas, - return 'Publish!', + If there are one or two good ideas, return 'Publish!'. + :return: """ # pylint: disable=R0801 @@ -69,7 +69,7 @@ def test_well_publish(self): '' '

Test Description:

' - "

") + "

If there are one or two good ideas, return 'Publish!'

") # pylint: enable=R0801 with allure.step("Pass list with one 'good' in it"): lst: list = ['good', 'bad', 'bad', 'bad', 'bad'] @@ -79,8 +79,8 @@ def test_well_publish(self): def test_well_series(self): """ - if there are more than 2 return - 'I smell a series!'. + If there are more than 2 return 'I smell a series!'. + :return: """ # pylint: disable=R0801 @@ -91,7 +91,7 @@ def test_well_series(self): '' '

Test Description:

' - "

") + "

If there are more than 2 return 'I smell a series!'

") # pylint: enable=R0801 with allure.step("Pass list with more than 2 'good' in it"): lst: list = ['good', 'bad', 'bad', diff --git a/kyu_8/well_of_ideas_easy_version/well_of_ideas_easy_version.py b/kyu_8/well_of_ideas_easy_version/well_of_ideas_easy_version.py index 1537dd77892..637a8e19afb 100644 --- a/kyu_8/well_of_ideas_easy_version/well_of_ideas_easy_version.py +++ b/kyu_8/well_of_ideas_easy_version/well_of_ideas_easy_version.py @@ -1,5 +1,6 @@ """ -Solution for -> Well of Ideas - Easy Version +Solution for -> Well of Ideas - Easy Version. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -9,9 +10,8 @@ def well(x: List[str]) -> str: """ - If there are one or two good ideas, return 'Publish!'. - If there are more than 2 return 'I smell a series!'. - If there are no good ideas, return 'Fail!'. + 'well' function. + :param x: List[str] :return: str """ diff --git a/kyu_8/will_there_be_enough_space/__init__.py b/kyu_8/will_there_be_enough_space/__init__.py index e69de29bb2d..dfef7dcb40f 100644 --- a/kyu_8/will_there_be_enough_space/__init__.py +++ b/kyu_8/will_there_be_enough_space/__init__.py @@ -0,0 +1 @@ +"""Will there be enough space.""" diff --git a/kyu_8/will_there_be_enough_space/enough.py b/kyu_8/will_there_be_enough_space/enough.py index aac42941813..c320e23d1e7 100644 --- a/kyu_8/will_there_be_enough_space/enough.py +++ b/kyu_8/will_there_be_enough_space/enough.py @@ -1,5 +1,6 @@ """ -Solution for -> Will there be enough space? +Solution for -> Will there be enough space?. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,6 +8,8 @@ def enough(cap: int, on: int, wait: int) -> int: """ + 'enough' function. + The driver wants you to write a simple program telling him if he will be able to fit all the passengers. @@ -18,7 +21,6 @@ def enough(cap: int, on: int, wait: int) -> int: cap is the amount of people the bus can hold excluding the driver. on is the number of people on the bus. wait is the number of people waiting to get on to the bus. - :param cap: int :param on: int :param wait: int diff --git a/kyu_8/will_there_be_enough_space/test_enough.py b/kyu_8/will_there_be_enough_space/test_enough.py index cb537d703fd..fe941f70f34 100644 --- a/kyu_8/will_there_be_enough_space/test_enough.py +++ b/kyu_8/will_there_be_enough_space/test_enough.py @@ -1,5 +1,6 @@ """ -Tests for -> Will there be enough space? +Tests for -> Will there be enough space?. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -8,6 +9,7 @@ import unittest import allure +from parameterized import parameterized from utils.log_func import print_log from kyu_8.will_there_be_enough_space.enough import enough @@ -26,46 +28,37 @@ name='Source/Kata') # pylint: enable=R0801 class EnoughTestCase(unittest.TestCase): - """ - Testing enough function - """ + """Testing enough function.""" - def test_enough(self): + @parameterized.expand([ + ((10, 5, 5), 0), + ((100, 60, 50), 10), + ((20, 5, 5), 0)]) + def test_enough(self, test_dat, expected): """ - Testing enough function - with various test data + Testing enough function with various test data. - If there is enough space, return 0, - and if there isn't, return the number - of passengers he can't take. :return: """ # pylint: disable=R0801 - allure.dynamic.title("STesting enough function") + allure.dynamic.title("Testing enough function") allure.dynamic.severity(allure.severity_level.NORMAL) allure.dynamic.description_html( '

Codewars badge:

' '' '

Test Description:

' - "

") + "

If there is enough space, return 0, " + "and if there isn't, return the number " + "of passengers he can't take.

") # pylint: enable=R0801 - with allure.step("Enter test data and " - "verify the output"): - test_data: tuple = ( - ((10, 5, 5), 0), - ((100, 60, 50), 10), - ((20, 5, 5), 0)) - - for test_dat, expected in test_data: - cap: int = test_dat[0] - on: int = test_dat[1] - wait: int = test_dat[2] - - print_log(cap=cap, - on=on, - wait=wait, - expected=expected) - - self.assertEqual(expected, - enough(cap, on, wait)) + with allure.step(f"Enter test data: {test_dat} " + f"and verify the expected output: {expected}."): + cap: int = test_dat[0] + on: int = test_dat[1] + wait: int = test_dat[2] + print_log(cap=cap, + on=on, + wait=wait, + expected=expected) + self.assertEqual(expected, enough(cap, on, wait)) diff --git a/kyu_8/will_you_make_it/README.md b/kyu_8/will_you_make_it/README.md index 609ab919f9f..1daf2e24c9d 100644 --- a/kyu_8/will_you_make_it/README.md +++ b/kyu_8/will_you_make_it/README.md @@ -1,4 +1,4 @@ -# Will you make it +# Will you make it? You were camping with your friends far away from home, but when it's time to go back, you realize that you fuel is running out diff --git a/kyu_8/will_you_make_it/__init__.py b/kyu_8/will_you_make_it/__init__.py index e69de29bb2d..8c9870dbbff 100644 --- a/kyu_8/will_you_make_it/__init__.py +++ b/kyu_8/will_you_make_it/__init__.py @@ -0,0 +1 @@ +"""Will you make it?.""" diff --git a/kyu_8/will_you_make_it/test_zero_fuel.py b/kyu_8/will_you_make_it/test_zero_fuel.py index 6ef2863739f..25be63c50e0 100644 --- a/kyu_8/will_you_make_it/test_zero_fuel.py +++ b/kyu_8/will_you_make_it/test_zero_fuel.py @@ -1,5 +1,6 @@ """ -Tests for -> Will you make it? +Tests for -> Will you make it?. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -8,6 +9,7 @@ import unittest import allure +from parameterized import parameterized from kyu_8.will_you_make_it.zero_fuel import zero_fuel from utils.log_func import print_log @@ -28,13 +30,15 @@ name='Source/Kata') # pylint: enable=R0801 class ZeroFuelTestCase(unittest.TestCase): - """ - Testing zero_fuel - """ + """Testing zero_fuel function.""" - def test_zero_fuel(self): + @parameterized.expand([ + ((50, 25, 2), True), + ((100, 50, 1), False)]) + def test_zero_fuel(self, data, expected): """ - Testing the function with various test data + Testing the function with various test data. + :return: """ # pylint: disable=R0801 @@ -42,8 +46,9 @@ def test_zero_fuel(self): allure.dynamic.severity(allure.severity_level.NORMAL) allure.dynamic.description_html( '

Codewars badge:

' - '' + '' '

Test Description:

' "

You were camping with your friends far away from home, " "but when it's time to go back, you realize that you fuel " @@ -51,23 +56,13 @@ def test_zero_fuel(self): "know that on average, your car runs on about 25 miles per " "gallon. There are 2 gallons left. Considering these factors, " "write a function that tells you if it is possible to get to " - "the pump or not. Function should return true (1 in Prolog) if " - "it is possible and false (0 in Prolog) if not. The input values " - "are always positive.

") + "the pump or not. Function should return true (1 in Prolog) " + "if it is possible and false (0 in Prolog) if not. The input " + "values are always positive.

") # pylint: enable=R0801 - test_data: tuple = ( - ((50, 25, 2), True), - ((100, 50, 1), False)) - - for data, expected in test_data: - actual_result = zero_fuel(data[0], data[1], data[2]) - with allure.step(f"Enter data ({data}) and verify the " - f"expected output ({expected}) " - f"vs actual result ({actual_result})"): - - print_log(data=data, - expected=expected, - result=actual_result) - - self.assertEqual(expected, - actual_result) + actual_result = zero_fuel(data[0], data[1], data[2]) + with allure.step(f"Enter data ({data}) and verify the " + f"expected output ({expected}) " + f"vs actual result ({actual_result})"): + print_log(data=data, expected=expected, result=actual_result) + self.assertEqual(expected, actual_result) diff --git a/kyu_8/will_you_make_it/zero_fuel.py b/kyu_8/will_you_make_it/zero_fuel.py index dfdc00d6572..0e97db3fb85 100644 --- a/kyu_8/will_you_make_it/zero_fuel.py +++ b/kyu_8/will_you_make_it/zero_fuel.py @@ -1,12 +1,17 @@ """ -Solution for -> Will you make it? +Solution for -> Will you make it?. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ -def zero_fuel(distance_to_pump: int, mpg: int, fuel_left: int) -> bool: +def zero_fuel(distance_to_pump: int, + mpg: int, + fuel_left: int) -> bool: """ + 'zero_fuel' function. + You were camping with your friends far away from home, but when it's time to go back, you realize that you fuel is running out and the nearest pump is 50 miles away! @@ -16,7 +21,6 @@ def zero_fuel(distance_to_pump: int, mpg: int, fuel_left: int) -> bool: to get to the pump or not. Function should return true (1 in Prolog) if it is possible and false (0 in Prolog) if not. The input values are always positive. - :param distance_to_pump: int :param mpg: int :param fuel_left: int diff --git a/kyu_8/wolf_in_sheep_clothing/__init__.py b/kyu_8/wolf_in_sheep_clothing/__init__.py index e69de29bb2d..6833659fbbf 100644 --- a/kyu_8/wolf_in_sheep_clothing/__init__.py +++ b/kyu_8/wolf_in_sheep_clothing/__init__.py @@ -0,0 +1 @@ +"""A wolf in sheep's clothing.""" diff --git a/kyu_8/wolf_in_sheep_clothing/test_wolf_in_sheep_clothing.py b/kyu_8/wolf_in_sheep_clothing/test_wolf_in_sheep_clothing.py index 5fd1ee09df0..b7f440e2cea 100644 --- a/kyu_8/wolf_in_sheep_clothing/test_wolf_in_sheep_clothing.py +++ b/kyu_8/wolf_in_sheep_clothing/test_wolf_in_sheep_clothing.py @@ -1,5 +1,6 @@ """ -Tests for -> A wolf in sheep's clothing +Tests for -> A wolf in sheep's clothing. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -24,16 +25,17 @@ 'ARRAYS', 'LOOPS', 'CONTROL FLOW') -@allure.link(url='https://www.codewars.com/kata/5c8bfa44b9d1192e1ebd3d15', - name='Source/Kata') +@allure.link( + url='https://www.codewars.com/kata/5c8bfa44b9d1192e1ebd3d15', + name='Source/Kata') # pylint: enable=R0801 class WarnTheSheepTestCase(unittest.TestCase): - """ - Testing warn_the_sheep function - """ + """Testing warn_the_sheep function.""" def test_warn_the_sheep_wolf_at_start(self): """ + Test the 'warn' func when the wolf in the beginning. + If the wolf is the closest animal to you, return "Pls go away and stop eating my sheep". :return: @@ -46,7 +48,8 @@ def test_warn_the_sheep_wolf_at_start(self): '' '

Test Description:

' - "

") + "

If the wolf is the closest animal to you, " + "return \"Pls go away and stop eating my sheep\".

") # pylint: enable=R0801 lst: list = ['wolf', 'sheep', 'sheep', 'sheep', 'sheep', 'sheep', @@ -60,6 +63,8 @@ def test_warn_the_sheep_wolf_at_start(self): def test_warn_the_sheep_wolf_in_middle(self): """ + Test the 'warn' func when the wolf in the middle. + If the wolf is the closest animal to you, return "Pls go away and stop eating my sheep". :return: @@ -72,7 +77,8 @@ def test_warn_the_sheep_wolf_in_middle(self): '' '

Test Description:

' - "

") + "

If the wolf is the closest animal to you, " + "return \"Pls go away and stop eating my sheep\".

") # pylint: enable=R0801 # 1 lst: list = ['sheep', 'sheep', 'sheep', @@ -107,6 +113,8 @@ def test_warn_the_sheep_wolf_in_middle(self): def test_warn_the_sheep_wolf_at_end(self): """ + Test the 'warn' func when the wolf in the end. + If the wolf is not the closest animal to you, return "Oi! Sheep number N! You are about to be eaten by a wolf!" where N is the sheep's position in the queue. @@ -120,7 +128,9 @@ def test_warn_the_sheep_wolf_at_end(self): '' '

Test Description:

' - "

") + "

If the wolf is not the closest animal to you, " + "return \"Oi! Sheep number N! You are about to be eaten by a wolf!\" " + "where N is the sheep's position in the queue.

") # pylint: enable=R0801 lst: list = ['sheep', 'sheep', 'wolf'] expected: str = 'Pls go away and stop eating my sheep' diff --git a/kyu_8/wolf_in_sheep_clothing/wolf_in_sheep_clothing.py b/kyu_8/wolf_in_sheep_clothing/wolf_in_sheep_clothing.py index 7057389988e..628457e199f 100644 --- a/kyu_8/wolf_in_sheep_clothing/wolf_in_sheep_clothing.py +++ b/kyu_8/wolf_in_sheep_clothing/wolf_in_sheep_clothing.py @@ -1,5 +1,6 @@ """ -Solution for -> A wolf in sheep's clothing +Solution for -> A wolf in sheep's clothing. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,8 +8,7 @@ def warn_the_sheep(queue: list) -> str: """ - Warn the sheep in front of the wolf - that it is about to be eaten. + Warn the sheep in front of the wolf. If the wolf is the closest animal to you, return "Pls go away and stop eating my sheep".