From f3f8cf2d33bbc4a43456a679390c6d1729bda97f Mon Sep 17 00:00:00 2001 From: Egor Kostan <20955183+ikostan@users.noreply.github.com> Date: Tue, 17 Dec 2024 03:42:42 -0800 Subject: [PATCH] # Help the bookseller --- kyu_6/help_the_bookseller/__init__.py | 1 + kyu_6/help_the_bookseller/stock_list.py | 5 +- kyu_6/help_the_bookseller/test_stock_list.py | 71 +++++++++----------- 3 files changed, 36 insertions(+), 41 deletions(-) diff --git a/kyu_6/help_the_bookseller/__init__.py b/kyu_6/help_the_bookseller/__init__.py index e69de29bb2d..75cea309e18 100644 --- a/kyu_6/help_the_bookseller/__init__.py +++ b/kyu_6/help_the_bookseller/__init__.py @@ -0,0 +1 @@ +"""Help the bookseller.""" diff --git a/kyu_6/help_the_bookseller/stock_list.py b/kyu_6/help_the_bookseller/stock_list.py index c611ade7d79..4a03dc9e7f9 100644 --- a/kyu_6/help_the_bookseller/stock_list.py +++ b/kyu_6/help_the_bookseller/stock_list.py @@ -1,5 +1,6 @@ """ -Solution for -> Help the bookseller ! +Solution for -> Help the bookseller!. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,6 +8,8 @@ def stock_list(list_of_art: list, list_of_cat: list) -> str: """ + Stock list function. + You will be given a stockist (e.g. : L) and a list of categories in capital letters e.g : M = {"A", "B", "C", "W"} diff --git a/kyu_6/help_the_bookseller/test_stock_list.py b/kyu_6/help_the_bookseller/test_stock_list.py index d21c275c48e..853f1fe0a41 100644 --- a/kyu_6/help_the_bookseller/test_stock_list.py +++ b/kyu_6/help_the_bookseller/test_stock_list.py @@ -1,5 +1,6 @@ """ -Test for -> Help the bookseller ! +Test for -> Help the bookseller!. + 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_6.help_the_bookseller.stock_list import stock_list @@ -24,12 +26,28 @@ url='https://www.codewars.com/kata/54dc6f5a224c26032800005c', name='Source/Kata') class StockListTestCase(unittest.TestCase): - """ - Testing stock_list function - """ - def test_stock_list(self): + """Testing stock_list function.""" + + @parameterized.expand([ + (["ABAR 200", "CDXE 500", "BKWR 250", "BTSQ 890", "DRTY 600"], + ["A", "B"], "(A : 200) - (B : 1140)"), + (['BBAR 150', 'CDXE 515', 'BKWR 250', 'BTSQ 890', 'DRTY 600'], + ['A', 'B', 'C', 'D'], + '(A : 0) - (B : 1290) - (C : 515) - (D : 600)'), + (['CBART 20', 'CDXEF 50', 'BKWRK 25', 'BTSQZ 89', 'DRTYM 60'], + ['A', 'B', 'C', 'W'], + '(A : 0) - (B : 114) - (C : 70) - (W : 0)'), + (['ROXANNE 102', 'RHODODE 123', 'BKWRKAA 125', 'BTSQZFG 239', + 'DRTYMKH 060'], ['B', 'R', 'D', 'X'], + '(B : 364) - (R : 225) - (D : 60) - (X : 0)'), + (['ROXANNE 102', 'RHODODE 123', 'BKWRKAA 125', 'BTSQZFG 239', + 'DRTYMKH 060'], + ['U', 'V', 'R'], '(U : 0) - (V : 0) - (R : 225)'), + ([], ['B', 'R', 'D', 'X'], '')]) + def test_stock_list(self, list_of_art, list_of_cat, expected): """ - Testing stock_list function with various test data + Testing stock_list function with various test data. + :return: """ # pylint: disable-msg=R0801 @@ -46,40 +64,13 @@ def test_stock_list(self): "to each category of M and to sum their quantity according to " "each category.

") # pylint: enable-msg=R0801 - test_data: tuple = ( - (["ABAR 200", "CDXE 500", "BKWR 250", "BTSQ 890", "DRTY 600"], - ["A", "B"], - "(A : 200) - (B : 1140)"), - (['BBAR 150', 'CDXE 515', 'BKWR 250', 'BTSQ 890', 'DRTY 600'], - ['A', 'B', 'C', 'D'], - '(A : 0) - (B : 1290) - (C : 515) - (D : 600)'), - (['CBART 20', 'CDXEF 50', 'BKWRK 25', 'BTSQZ 89', 'DRTYM 60'], - ['A', 'B', 'C', 'W'], - '(A : 0) - (B : 114) - (C : 70) - (W : 0)'), - (['ROXANNE 102', 'RHODODE 123', 'BKWRKAA 125', 'BTSQZFG 239', - 'DRTYMKH 060'], - ['B', 'R', 'D', 'X'], - '(B : 364) - (R : 225) - (D : 60) - (X : 0)'), - (['ROXANNE 102', 'RHODODE 123', 'BKWRKAA 125', 'BTSQZFG 239', - 'DRTYMKH 060'], - ['U', 'V', 'R'], - '(U : 0) - (V : 0) - (R : 225)'), - ([], - ['B', 'R', 'D', 'X'], - '')) - - for list_of_art, list_of_cat, expected in test_data: - actual_result = stock_list(list_of_art, list_of_cat) - - with allure.step(f"Enter test data ({list_of_art}, " - f"{list_of_cat}) and verify the " - f"expected output ({expected}) vs " - f"actual result ({actual_result})"): - - print_log(list_of_artt=list_of_art, + actual_result = stock_list(list_of_art, list_of_cat) + with allure.step(f"Enter test data ({list_of_art}, " + f"{list_of_cat}) and verify the " + f"expected output ({expected}) vs " + f"actual result ({actual_result})"): + print_log(list_of_artt=list_of_art, list_of_cat=list_of_cat, expected=expected, result=actual_result) - - self.assertEqual(expected, - actual_result) + self.assertEqual(expected, actual_result)