Skip to content

Commit

Permalink
# Help the bookseller
Browse files Browse the repository at this point in the history
  • Loading branch information
ikostan committed Dec 17, 2024
1 parent 18b4033 commit f3f8cf2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 41 deletions.
1 change: 1 addition & 0 deletions kyu_6/help_the_bookseller/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Help the bookseller."""
5 changes: 4 additions & 1 deletion kyu_6/help_the_bookseller/stock_list.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
"""
Solution for -> Help the bookseller !
Solution for -> Help the bookseller!.
Created by Egor Kostan.
GitHub: https://github.com/ikostan
"""


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"}
Expand Down
71 changes: 31 additions & 40 deletions kyu_6/help_the_bookseller/test_stock_list.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Test for -> Help the bookseller !
Test for -> Help the bookseller!.
Created by Egor Kostan.
GitHub: https://github.com/ikostan
"""
Expand All @@ -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

Expand All @@ -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
Expand All @@ -46,40 +64,13 @@ def test_stock_list(self):
"to each category of M and to sum their quantity according to "
"each category.</p>")
# 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)

0 comments on commit f3f8cf2

Please sign in to comment.