diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 000000000..b17a04d62 Binary files /dev/null and b/.DS_Store differ diff --git a/.coverage b/.coverage new file mode 100644 index 000000000..d83ff9ed6 Binary files /dev/null and b/.coverage differ diff --git a/__pycache__/__init__.cpython-314.pyc b/__pycache__/__init__.cpython-314.pyc new file mode 100644 index 000000000..6b03029ae Binary files /dev/null and b/__pycache__/__init__.cpython-314.pyc differ diff --git a/__pycache__/bun.cpython-314.pyc b/__pycache__/bun.cpython-314.pyc new file mode 100644 index 000000000..c826b4578 Binary files /dev/null and b/__pycache__/bun.cpython-314.pyc differ diff --git a/__pycache__/burger.cpython-314.pyc b/__pycache__/burger.cpython-314.pyc new file mode 100644 index 000000000..81249baf1 Binary files /dev/null and b/__pycache__/burger.cpython-314.pyc differ diff --git a/__pycache__/database.cpython-314.pyc b/__pycache__/database.cpython-314.pyc new file mode 100644 index 000000000..cba6f5eb6 Binary files /dev/null and b/__pycache__/database.cpython-314.pyc differ diff --git a/__pycache__/ingredient.cpython-314.pyc b/__pycache__/ingredient.cpython-314.pyc new file mode 100644 index 000000000..240f99cfa Binary files /dev/null and b/__pycache__/ingredient.cpython-314.pyc differ diff --git a/__pycache__/ingredient_types.cpython-314.pyc b/__pycache__/ingredient_types.cpython-314.pyc new file mode 100644 index 000000000..f0903b12a Binary files /dev/null and b/__pycache__/ingredient_types.cpython-314.pyc differ diff --git a/__pycache__/praktikum.cpython-314.pyc b/__pycache__/praktikum.cpython-314.pyc new file mode 100644 index 000000000..78f6decca Binary files /dev/null and b/__pycache__/praktikum.cpython-314.pyc differ diff --git a/burger.py b/burger.py index 2b3b6a88b..3f71aaa29 100644 --- a/burger.py +++ b/burger.py @@ -1,7 +1,7 @@ from typing import List -from praktikum.bun import Bun -from praktikum.ingredient import Ingredient +from bun import Bun +from ingredient import Ingredient class Burger: 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/requirements.txt b/requirements.txt new file mode 100644 index 000000000..447976318 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,7 @@ +coverage==7.13.4 +iniconfig==2.3.0 +packaging==26.0 +pluggy==1.6.0 +Pygments==2.19.2 +pytest==9.0.2 +pytest-cov==7.0.0 diff --git a/tests/.coverage b/tests/.coverage new file mode 100644 index 000000000..2ad4680a0 Binary files /dev/null and b/tests/.coverage differ diff --git a/tests/__pycache__/conftest.cpython-314-pytest-9.0.2.pyc b/tests/__pycache__/conftest.cpython-314-pytest-9.0.2.pyc new file mode 100644 index 000000000..381798775 Binary files /dev/null and b/tests/__pycache__/conftest.cpython-314-pytest-9.0.2.pyc differ diff --git a/tests/__pycache__/test_bun.cpython-314-pytest-9.0.2.pyc b/tests/__pycache__/test_bun.cpython-314-pytest-9.0.2.pyc new file mode 100644 index 000000000..dddf5a2d7 Binary files /dev/null and b/tests/__pycache__/test_bun.cpython-314-pytest-9.0.2.pyc differ diff --git a/tests/__pycache__/test_burger.cpython-314-pytest-9.0.2.pyc b/tests/__pycache__/test_burger.cpython-314-pytest-9.0.2.pyc new file mode 100644 index 000000000..fae089292 Binary files /dev/null and b/tests/__pycache__/test_burger.cpython-314-pytest-9.0.2.pyc differ diff --git a/tests/__pycache__/test_database.cpython-314-pytest-9.0.2.pyc b/tests/__pycache__/test_database.cpython-314-pytest-9.0.2.pyc new file mode 100644 index 000000000..ac3cfd0f9 Binary files /dev/null and b/tests/__pycache__/test_database.cpython-314-pytest-9.0.2.pyc differ diff --git a/tests/__pycache__/test_ingredient.cpython-314-pytest-9.0.2.pyc b/tests/__pycache__/test_ingredient.cpython-314-pytest-9.0.2.pyc new file mode 100644 index 000000000..5001e408a Binary files /dev/null and b/tests/__pycache__/test_ingredient.cpython-314-pytest-9.0.2.pyc differ diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 000000000..aa96f3271 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,26 @@ +import pytest +from unittest.mock import Mock + + +@pytest.fixture(params=["SAUCE", "FILLING"]) +def mock_ingredient(request): + type_param = request.param + mock_ingredient = Mock() + mock_ingredient.get_price.return_value = 12.99 + mock_ingredient.get_name.return_value = f"test{type_param.lower().capitalize()}" + mock_ingredient.get_type.return_value = type_param + return mock_ingredient + + +@pytest.fixture +def mock_bun(): + mock_bun = Mock() + mock_bun.get_price.return_value = 99.5 + mock_bun.get_name.return_value = "testBun" + return mock_bun + + +@pytest.fixture +def burger(): + from burger import Burger + return Burger() \ No newline at end of file diff --git a/tests/test_bun.py b/tests/test_bun.py new file mode 100644 index 000000000..9c8673787 --- /dev/null +++ b/tests/test_bun.py @@ -0,0 +1,18 @@ +import sys +import os +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from bun import Bun + +class TestBun: + + bun = Bun("testBun", "99.5") + + def test_bun_init(self): + assert self.bun.name == "testBun" + assert self.bun.price == "99.5" + + def test_bun_get_name(self): + assert self.bun.get_name() == "testBun" + + def test_bun_get_price(self): + assert self.bun.get_price() == "99.5" \ No newline at end of file diff --git a/tests/test_burger.py b/tests/test_burger.py new file mode 100644 index 000000000..14e58e0ba --- /dev/null +++ b/tests/test_burger.py @@ -0,0 +1,52 @@ +import sys +import os +from unittest.mock import Mock +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from burger import Burger + +class TestBurger: + + def test_burger_init(self, burger): + assert burger.bun == None + assert burger.ingredients == [] + + def test_burger_set_buns(self, burger, mock_bun): + burger.set_buns(mock_bun) + assert burger.bun == mock_bun + + def test_burger_add_ingredient(self, burger, mock_ingredient): + burger.add_ingredient(mock_ingredient) + assert burger.ingredients == [mock_ingredient] + + def test_burger_remove_ingredient(self, burger, mock_ingredient): + burger.add_ingredient(mock_ingredient) + burger.remove_ingredient(0) + assert burger.ingredients == [] + + def test_burger_move_ingredient(self, burger, mock_ingredient): + mock_ingredient2 = Mock() + mock_ingredient2.get_price.return_value = 15.0 + mock_ingredient2.get_name.return_value = f"new{mock_ingredient.get_type().lower().capitalize()}" + mock_ingredient2.get_type.return_value = mock_ingredient.get_type() + + burger.add_ingredient(mock_ingredient) + burger.add_ingredient(mock_ingredient2) + burger.move_ingredient(1, 0) + assert burger.ingredients == [mock_ingredient2, mock_ingredient] + + def test_burger_get_price(self, burger, mock_bun, mock_ingredient): + burger.set_buns(mock_bun) + burger.add_ingredient(mock_ingredient) + # Expected price: (99.5 * 2) + 12.99 = 211.99 + assert burger.get_price() == 211.99 + + def test_burger_get_receipt(self, burger, mock_bun, mock_ingredient): + burger.set_buns(mock_bun) + burger.add_ingredient(mock_ingredient) + # Expected receipt: + ingredient_type = mock_ingredient.get_type().lower() + ingredient_name = mock_ingredient.get_name() + bun_name = mock_bun.get_name() + price = burger.get_price() + expected_receipt = f"(==== {bun_name} ====)\n= {ingredient_type} {ingredient_name} =\n(==== testBun ====)\n\nPrice: {price}" + assert burger.get_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..bf5d9839c --- /dev/null +++ b/tests/test_database.py @@ -0,0 +1,60 @@ +import sys +import os +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from database import Database + + +class TestDatabase: + + def test_database_init(self): + db = Database() + + # Test buns initialization + assert len(db.buns) == 3 + assert db.buns[0].name == "black bun" + assert db.buns[0].price == 100 + assert db.buns[1].name == "white bun" + assert db.buns[1].price == 200 + assert db.buns[2].name == "red bun" + assert db.buns[2].price == 300 + + + assert len(db.ingredients) == 6 + + + sauces = [ing for ing in db.ingredients if ing.type == "SAUCE"] + assert len(sauces) == 3 + assert sauces[0].name == "hot sauce" + assert sauces[0].price == 100 + assert sauces[1].name == "sour cream" + assert sauces[1].price == 200 + assert sauces[2].name == "chili sauce" + assert sauces[2].price == 300 + + + fillings = [ing for ing in db.ingredients if ing.type == "FILLING"] + assert len(fillings) == 3 + assert fillings[0].name == "cutlet" + assert fillings[0].price == 100 + assert fillings[1].name == "dinosaur" + assert fillings[1].price == 200 + assert fillings[2].name == "sausage" + assert fillings[2].price == 300 + + def test_database_available_buns(self): + db = Database() + buns = db.available_buns() + assert len(buns) == 3 + assert buns[0].name == "black bun" + assert buns[1].name == "white bun" + assert buns[2].name == "red bun" + + def test_database_available_ingredients(self): + db = Database() + ingredients = db.available_ingredients() + assert len(ingredients) == 6 + + sauce_count = len([ing for ing in ingredients if ing.type == "SAUCE"]) + filling_count = len([ing for ing in ingredients if ing.type == "FILLING"]) + assert sauce_count == 3 + assert filling_count == 3 diff --git a/tests/test_ingredient.py b/tests/test_ingredient.py new file mode 100644 index 000000000..0120280bc --- /dev/null +++ b/tests/test_ingredient.py @@ -0,0 +1,26 @@ +import sys +import os +import pytest +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from ingredient import Ingredient + +@pytest.mark.parametrize("type", ["SAUCE", "FILLING"]) +class TestIngredient: + + def test_ingredient_init(self, type): + ingredient = Ingredient(type, "testIngredient", 12.99) + assert ingredient.type == type + assert ingredient.name == "testIngredient" + assert ingredient.price == 12.99 + + def test_ingredient_get_name(self, type): + ingredient = Ingredient(type, "testIngredient", 12.99) + assert ingredient.get_name() == "testIngredient" + + def test_ingredient_get_price(self, type): + ingredient = Ingredient(type, "testIngredient", 12.99) + assert ingredient.get_price() == 12.99 + + def test_ingredient_get_type(self, type): + ingredient = Ingredient(type, "testIngredient", 12.99) + assert ingredient.get_type() == type \ No newline at end of file