From fdb97161c8fcb3da87193ac659c543d1de7293d5 Mon Sep 17 00:00:00 2001 From: mrsMistral Date: Fri, 6 Mar 2026 19:44:13 +0100 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=201?= =?UTF-8?q?=20=D1=81=20=D1=8E=D0=BD=D0=B8=D1=82-=D1=82=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .coverage | Bin 0 -> 53248 bytes burger.py | 4 +- coverage.xml | 276 +++++++++++++++++++++++++++++++++++++++ database.py | 6 +- tests/test_bun.py | 51 ++++++++ tests/test_burger.py | 82 ++++++++++++ tests/test_database.py | 43 ++++++ tests/test_ingredient.py | 42 ++++++ 8 files changed, 499 insertions(+), 5 deletions(-) create mode 100644 .coverage create mode 100644 coverage.xml create mode 100644 tests/test_bun.py create mode 100644 tests/test_burger.py create mode 100644 tests/test_database.py create mode 100644 tests/test_ingredient.py diff --git a/.coverage b/.coverage new file mode 100644 index 0000000000000000000000000000000000000000..428a0c501a686ee5f7033d985d22b8459270b732 GIT binary patch literal 53248 zcmeI4TWlQF8OLXKW_Nb>b_|hOjD>tuL>()(lNAqDla^u&MsV@~$)yqS9MMykQsYN{W@={(LRaGA%ArM01&I3?Yzysfz%kFFv zBQ!!n4*${aT+W>HpYQvf@0_z|#-5*?K4Axfuen~&3iv(Bgrcg-eVi+bV$!!t-()dp zM^6rDtETpM+clNN^S`XJhm}gA|?ltWWl?ucAQ54&J2D5~9~YnFo>&u}aN5F;tk`dN=1Ox!R~}p=p|3kU9QC3hDL-< z(pa*Ax4Ld?Jl4X9@dY&y>I;%=Ykj9Jn~E=eXuIcyXRV9H_-xcIeBFUWq0=x6_2rq} zLT4BP&Bk!IG?*$F_33H#k{O0kTwC$R7z?4KCU4MNg z#C3AfXmrd9L}2#>msvt%!oa#<`Mm83I!R;c+^qIRVIXU(*^p~FOD@Wva)TMws2@0> z4*GFpjQW|TPlI~TO3aQAb7Mhr&B;-`oTLtye(j{=M6yfakcZI~Wak#uU@M}K8fO2z^LAOHd&00JNY0w4eaAOHe;kigNht_;e@4zE6B`}9Va z?&|5K)t%>d{74599SpL~&gVL?Dfqk~$qkk{IzeFNt z29ajdcI=?pB#o0MY21}TBM?4WC)XslPH$zfg%gnA4~rx?l|gW%(hRmYg)bd6GCC;# zcfV!%f;1i~kj6{~dr}Uj#VlIU{6F`AKA6mM8*0oHIseD||Ijsp00@8p2!H?xfB*=900@8p z2!Oy%O+ZsMr7EBQtL!s{K3G5i1V8`;KmY_l00ck)1V8`;KmY`8LIRprHRbdF5_?Kv z|7Rbt*Vup9%k1y;E`Vp))0Bt>1V8`;KmY_l00ck)1V8`;KmY_l;43CjF6pXyyLoT^ z$kQ+9%ceXieDd$#|MkOz6Gb}smiE7o-h1qopZ(_Qr-${jp_}F%e+kYUdBi9e3UsBKM1{1(kMcB~?EEFR>RD zc7=V&{>9#9uh9Je4fbF5BKzbkb`WwP00JNY0w4eaAOHd&00JNY0w4ea83@REziO7k zO~DK|8r=jiP1Ohwis79BHJ=ZU3_aZFTDZyO + + + + + D:\Mistral\QA\ЯПАвто\projects\Project\Task_1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/database.py b/database.py index 4c75baf71..84d3685d0 100644 --- a/database.py +++ b/database.py @@ -1,8 +1,8 @@ from typing import List -from praktikum.bun import Bun -from praktikum.ingredient import Ingredient -from praktikum.ingredient_types import INGREDIENT_TYPE_SAUCE, INGREDIENT_TYPE_FILLING +from bun import Bun +from ingredient import Ingredient +from ingredient_types import INGREDIENT_TYPE_SAUCE, INGREDIENT_TYPE_FILLING class Database: diff --git a/tests/test_bun.py b/tests/test_bun.py new file mode 100644 index 000000000..9815046ba --- /dev/null +++ b/tests/test_bun.py @@ -0,0 +1,51 @@ +import pytest + +import sys +import os +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) + +from bun import Bun + + +class TestBun: + + @pytest.mark.parametrize( + "name, price", + [ + ("black bun", 100.0), + ("white bun", 50.5), + ("sesame bun", 0), + ("", 10.0), + ] + ) + def test_bun_initialization(self, name, price): + bun = Bun(name, price) + + assert bun.name == name + assert bun.price == price + + @pytest.mark.parametrize( + "name", + [ + "black bun", + "white bun", + "", + ] + ) + def test_get_name_returns_correct_name(self, name): + bun = Bun(name, 100.0) + + assert bun.get_name() == name + + @pytest.mark.parametrize( + "price", + [ + 100.0, + 50.5, + 0, + ] + ) + def test_get_price_returns_correct_price(self, price): + bun = Bun("test bun", price) + + assert bun.get_price() == price \ No newline at end of file diff --git a/tests/test_burger.py b/tests/test_burger.py new file mode 100644 index 000000000..932015559 --- /dev/null +++ b/tests/test_burger.py @@ -0,0 +1,82 @@ +import pytest +from unittest.mock import Mock + +import sys +import os +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) +from burger import Burger + + +class TestBurger: + + @pytest.mark.parametrize("bun_price, ingredient_prices, expected_price", [ + (100, [], 200), + (100, [50], 250), + (100, [50, 25], 275), + (0, [10, 20], 30), + ]) + def test_get_price(self, bun_price, ingredient_prices, expected_price): + burger = Burger() + + bun = Mock() + bun.get_price.return_value = bun_price + burger.set_buns(bun) + + for price in ingredient_prices: + ingredient = Mock() + ingredient.get_price.return_value = price + burger.add_ingredient(ingredient) + + assert burger.get_price() == expected_price + + + @pytest.mark.parametrize("index, new_index, expected_order", [ + (0, 2, [2, 3, 1]), + (2, 0, [3, 1, 2]), + (1, 1, [1, 2, 3]), + ]) + def test_move_ingredient(self, index, new_index, expected_order): + burger = Burger() + + ingredients = [] + for i in [1, 2, 3]: + ingredient = Mock() + ingredient.get_name.return_value = str(i) + ingredients.append(ingredient) + burger.add_ingredient(ingredient) + + burger.move_ingredient(index, new_index) + + result_order = [int(i.get_name()) for i in burger.ingredients] + + assert result_order == expected_order + + + @pytest.mark.parametrize("ingredient_type, expected_type", [ + ("SAUCE", "sauce"), + ("FILLING", "filling"), + ]) + def test_get_receipt(self, ingredient_type, expected_type): + burger = Burger() + + bun = Mock() + bun.get_name.return_value = "black bun" + bun.get_price.return_value = 100 + burger.set_buns(bun) + + ingredient = Mock() + ingredient.get_type.return_value = ingredient_type + ingredient.get_name.return_value = "ketchup" + ingredient.get_price.return_value = 50 + burger.add_ingredient(ingredient) + + receipt = burger.get_receipt() + + expected_receipt = ( + "(==== black bun ====)\n" + f"= {expected_type} ketchup =\n" + "(==== black bun ====)\n\n" + "Price: 250" + ) + + assert receipt == expected_receipt \ No newline at end of file diff --git a/tests/test_database.py b/tests/test_database.py new file mode 100644 index 000000000..933b92d1a --- /dev/null +++ b/tests/test_database.py @@ -0,0 +1,43 @@ +import pytest + +import sys +import os +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) +from database import Database +from bun import Bun +from ingredient import Ingredient +from ingredient_types import INGREDIENT_TYPE_SAUCE, INGREDIENT_TYPE_FILLING + + +class TestDatabase: + + def test_available_buns_returns_all_buns(self): + db = Database() + buns = db.available_buns() + + assert isinstance(buns, list) + assert all(isinstance(bun, Bun) for bun in buns) + assert len(buns) == 3 + + names_prices = [(bun.get_name(), bun.get_price()) for bun in buns] + expected = [("black bun", 100), ("white bun", 200), ("red bun", 300)] + assert names_prices == expected + + def test_available_ingredients_returns_all_ingredients(self): + db = Database() + ingredients = db.available_ingredients() + + assert isinstance(ingredients, list) + assert all(isinstance(ing, Ingredient) for ing in ingredients) + assert len(ingredients) == 6 + + types_names_prices = [(ing.get_type(), ing.get_name(), ing.get_price()) for ing in ingredients] + expected = [ + (INGREDIENT_TYPE_SAUCE, "hot sauce", 100), + (INGREDIENT_TYPE_SAUCE, "sour cream", 200), + (INGREDIENT_TYPE_SAUCE, "chili sauce", 300), + (INGREDIENT_TYPE_FILLING, "cutlet", 100), + (INGREDIENT_TYPE_FILLING, "dinosaur", 200), + (INGREDIENT_TYPE_FILLING, "sausage", 300), + ] + assert types_names_prices == expected \ No newline at end of file diff --git a/tests/test_ingredient.py b/tests/test_ingredient.py new file mode 100644 index 000000000..9d1e63095 --- /dev/null +++ b/tests/test_ingredient.py @@ -0,0 +1,42 @@ +import pytest +import sys +import os +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) +from ingredient import Ingredient + + +class TestIngredient: + + @pytest.mark.parametrize("ingredient_type, name, price", [ + ("SAUCE", "ketchup", 50), + ("FILLING", "cheese", 100), + ("SAUCE", "", 0), + ("FILLING", "bacon", 99.9), + ]) + def test_ingredient_initialization(self, ingredient_type, name, price): + ingredient = Ingredient(ingredient_type, name, price) + + assert ingredient.type == ingredient_type + assert ingredient.name == name + assert ingredient.price == price + + + @pytest.mark.parametrize("price", [0, 10, 99.9]) + def test_get_price(self, price): + ingredient = Ingredient("SAUCE", "test", price) + + assert ingredient.get_price() == price + + + @pytest.mark.parametrize("name", ["ketchup", "cheese", ""]) + def test_get_name(self, name): + ingredient = Ingredient("SAUCE", name, 50) + + assert ingredient.get_name() == name + + + @pytest.mark.parametrize("ingredient_type", ["SAUCE", "FILLING"]) + def test_get_type(self, ingredient_type): + ingredient = Ingredient(ingredient_type, "test", 50) + + assert ingredient.get_type() == ingredient_type \ No newline at end of file