From 878727bef7348c74165422aa0415db644b241f75 Mon Sep 17 00:00:00 2001 From: Egor Kostan <20955183+ikostan@users.noreply.github.com> Date: Tue, 17 Dec 2024 02:25:24 -0800 Subject: [PATCH] # Casino chips --- kyu_6/casino_chips/__init__.py | 1 + kyu_6/casino_chips/solve.py | 6 ++-- kyu_6/casino_chips/test_solve.py | 62 +++++++++++++++----------------- 3 files changed, 33 insertions(+), 36 deletions(-) diff --git a/kyu_6/casino_chips/__init__.py b/kyu_6/casino_chips/__init__.py index e69de29bb2d..85116aaec47 100644 --- a/kyu_6/casino_chips/__init__.py +++ b/kyu_6/casino_chips/__init__.py @@ -0,0 +1 @@ +"""Casino chips.""" diff --git a/kyu_6/casino_chips/solve.py b/kyu_6/casino_chips/solve.py index 10c397f214d..ae532e301ba 100644 --- a/kyu_6/casino_chips/solve.py +++ b/kyu_6/casino_chips/solve.py @@ -1,5 +1,6 @@ """ -Solution for Casino chips +Solution for Casino chips. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,6 +8,8 @@ def solve(arr: list) -> int: """ + Solve function. + You are given three piles of casino chips: white, green and black chips: @@ -26,7 +29,6 @@ def solve(arr: list) -> int: :return: """ arr = sorted(arr) - if arr[0] + arr[1] <= arr[2]: return arr[0] + arr[1] diff --git a/kyu_6/casino_chips/test_solve.py b/kyu_6/casino_chips/test_solve.py index af7b95b5934..5ed35a57740 100644 --- a/kyu_6/casino_chips/test_solve.py +++ b/kyu_6/casino_chips/test_solve.py @@ -1,5 +1,6 @@ """ -Test for Casino chips +Test for Casino chips. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -8,6 +9,7 @@ import unittest import allure +from parameterized import parameterized from kyu_6.casino_chips.solve import solve from utils.log_func import print_log @@ -28,12 +30,26 @@ name='Source/Kata') # pylint: enable-msg=R0801 class SolveTestCase(unittest.TestCase): - """ - Testing solve function - """ - def test_solve(self): + """Testing solve function.""" + + @parameterized.expand([ + ([8, 8, 8], 12), + ([1, 1, 1], 1), + ([8, 1, 4], 5), + ([7, 4, 10], 10), + ([12, 12, 12], 18), + ([6, 6, 6], 9), + ([1, 23, 2], 3), + ([9, 8, 6], 11), + ([10, 9, 6], 12), + ([4, 4, 3], 5), + ([1, 2, 1], 2), + ([4, 1, 1], 2), + ([8, 2, 8], 9)]) + def test_solve(self, arr, expected): """ - Testing 'solve' function with various test data + Testing 'solve' function with various test data. + :return: """ # pylint: disable-msg=R0801 @@ -49,31 +65,9 @@ def test_solve(self): "maximum number of days you can pick the chips. Each " "day you need to take exactly two chips.

") # pylint: enable-msg=R0801 - test_data: tuple = ( - ([8, 8, 8], 12), - ([1, 1, 1], 1), - ([8, 1, 4], 5), - ([7, 4, 10], 10), - ([12, 12, 12], 18), - ([6, 6, 6], 9), - ([1, 23, 2], 3), - ([9, 8, 6], 11), - ([10, 9, 6], 12), - ([4, 4, 3], 5), - ([1, 2, 1], 2), - ([4, 1, 1], 2), - ([8, 2, 8], 9)) - - for arr, expected in test_data: - actual_result = solve(arr) - - with allure.step(f"Enter an array ({arr}) and verify the " - f"expected output ({expected}) vs " - f"actual result ({actual_result})"): - - print_log(arr=arr, - expected=expected, - result=actual_result) - - self.assertEqual(expected, - actual_result) + actual_result = solve(arr) + with allure.step(f"Enter an array ({arr}) and verify the " + f"expected output ({expected}) vs " + f"actual result ({actual_result})"): + print_log(arr=arr, expected=expected, result=actual_result) + self.assertEqual(expected, actual_result)