-
Notifications
You must be signed in to change notification settings - Fork 1.2k
задание 1 #714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
anastasilugovec
wants to merge
8
commits into
Yandex-Practicum:main
Choose a base branch
from
anastasilugovec:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
задание 1 #714
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
607afe9
задание 1
447c96f
задание 1.1
656685c
внесены исправления
9ff8ea7
внесены исправления2
82409da
внесены исправления2
e699e05
внесены исправления2
67e2f6a
внесены исправления-3
b93e44c
внесены исправления-4
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import pytest | ||
| from praktikum.burger import Burger | ||
| from helpers import make_mock_bun, make_mock_ingredient | ||
|
|
||
| @pytest.fixture | ||
| def burger(): | ||
| return Burger() | ||
|
|
||
| @pytest.fixture | ||
| def mock_bun(): | ||
| return make_mock_bun() | ||
|
|
||
| @pytest.fixture | ||
| def mock_ingredient(): | ||
| return make_mock_ingredient() | ||
|
|
||
| @pytest.fixture | ||
| def another_mock_ingredient(): | ||
| return make_mock_ingredient(name="Tomato", ing_type="Vegetable", price=0.8) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| from unittest.mock import Mock | ||
|
|
||
| def make_mock_bun(name="Sesame Bun", price=3.0): | ||
| bun = Mock() | ||
| bun.get_name.return_value = name | ||
| bun.get_price.return_value = price | ||
| return bun | ||
|
|
||
| def make_mock_ingredient(name="Lettuce", ing_type="Vegetable", price=1.2): | ||
| ing = Mock() | ||
| ing.get_name.return_value = name | ||
| ing.get_type.return_value = ing_type | ||
| ing.get_price.return_value = price | ||
| return ing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| class Bun: | ||
| def __init__(self, name, price): | ||
| self.name = name | ||
| self.price = price | ||
|
|
||
| def get_name(self): | ||
| return self.name | ||
|
|
||
| def get_price(self): | ||
| return self.price | ||
|
|
||
| class Ingredient: | ||
| def __init__(self, name, ingredient_type, price): | ||
| self.name = name | ||
| self.type = ingredient_type | ||
| self.price = price | ||
|
|
||
| def get_name(self): | ||
| return self.name | ||
|
|
||
| def get_type(self): | ||
| return self.type | ||
|
|
||
| def get_price(self): | ||
| return self.price | ||
|
|
||
| class Burger: | ||
| def __init__(self): | ||
| self.bun = None | ||
| self.ingredients = [] | ||
|
|
||
| def set_buns(self, bun): | ||
| self.bun = bun | ||
|
|
||
| def add_ingredient(self, ingredient): | ||
| self.ingredients.append(ingredient) | ||
|
|
||
| def remove_ingredient(self, ingredient): | ||
| self.ingredients.remove(ingredient) | ||
|
|
||
| def move_ingredient(self, old_index, new_index): | ||
| self.ingredients.insert(new_index, self.ingredients.pop(old_index)) | ||
|
|
||
| def get_price(self): | ||
| total = 0 | ||
| if self.bun: | ||
| total += self.bun.get_price() * 2 | ||
| for ing in self.ingredients: | ||
| total += ing.get_price() | ||
| return total | ||
|
|
||
| def get_receipt(self): | ||
| lines = [] | ||
| lines.append(f"(==== {self.bun.get_name()} ====)") | ||
| for ing in self.ingredients: | ||
| lines.append(f"= {str(ing.get_type()).lower()} {ing.get_name()} =") | ||
| lines.append(f"(==== {self.bun.get_name()} ====)") | ||
| lines.append(f"Price: {self.get_price()}") | ||
| return "\n".join(lines) | ||
|
|
||
| def clear_ingredients(self): | ||
| self.ingredients = [] |
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import pytest | ||
| from praktikum.burger import Burger | ||
| from helpers import make_mock_bun, make_mock_ingredient | ||
|
|
||
| class TestBurger: | ||
| def test_get_price_without_ingredients_and_bun(self, burger, mock_bun): | ||
| burger.set_buns(mock_bun) | ||
| expected_price = mock_bun.get_price.return_value * 2 | ||
| assert burger.get_price() == expected_price | ||
|
|
||
| def test_get_price_with_single_ingredient(self, burger, mock_bun, mock_ingredient): | ||
| burger.set_buns(mock_bun) | ||
| burger.add_ingredient(mock_ingredient) | ||
| expected_price = mock_bun.get_price.return_value * 2 + mock_ingredient.get_price.return_value | ||
| assert burger.get_price() == expected_price | ||
|
|
||
| def test_add_ingredient_increases_ingredients_list(self, burger, mock_ingredient): | ||
| initial_count = len(burger.get_ingredients()) | ||
| burger.add_ingredient(mock_ingredient) | ||
| assert mock_ingredient in burger.get_ingredients() | ||
| assert len(burger.get_ingredients()) == initial_count + 1 | ||
|
|
||
| def test_get_ingredients_returns_list(self, burger, mock_ingredient): | ||
| burger.add_ingredient(mock_ingredient) | ||
| ingredients = burger.get_ingredients() | ||
| assert isinstance(ingredients, list) | ||
| assert mock_ingredient in ingredients | ||
|
|
||
| def test_move_ingredient_valid_indices(self, burger, mock_ingredient, another_mock_ingredient): | ||
| burger.add_ingredient(mock_ingredient) | ||
| burger.add_ingredient(another_mock_ingredient) | ||
| burger.move_ingredient(0, 1) | ||
| assert burger.get_ingredients()[1] == mock_ingredient | ||
|
|
||
| def test_remove_ingredient_valid_index(self, burger, mock_ingredient): | ||
| burger.add_ingredient(mock_ingredient) | ||
| burger.remove_ingredient(1) | ||
| assert mock_ingredient not in burger.get_ingredients() | ||
|
|
||
| def test_remove_ingredient_invalid_index_with_assert(self, burger): | ||
| with pytest.raises(IndexError): | ||
| burger.remove_ingredient(999) | ||
|
|
||
| def test_clear_ingredients(self, burger, mock_ingredient): | ||
| burger.add_ingredient(mock_ingredient) | ||
| while burger.get_ingredients(): | ||
| burger.remove_ingredient(0) | ||
| assert burger.get_ingredients() == [] | ||
|
|
||
| def test_get_receipt_includes_bun_and_ingredients(self, burger, mock_bun, mock_ingredient): | ||
| burger.set_buns(mock_bun) | ||
| burger.add_ingredient(mock_ingredient) | ||
|
|
||
| total_price = burger.get_price() | ||
| bun_name = mock_bun.get_name() | ||
| ingredient_type = str(mock_ingredient.get_type()).lower() | ||
| ingredient_name = mock_ingredient.get_name() | ||
|
|
||
| expected_receipt = ( | ||
| f"(==== {bun_name} ====)\n" | ||
| f"= {ingredient_type} {ingredient_name} =\n" | ||
| f"(==== {bun_name} ====)\n" | ||
| f"\n" | ||
| f"Price: {total_price}" | ||
| ) | ||
|
|
||
| actual_receipt = burger.get_receipt() | ||
|
|
||
| print("Expected receipt:\n" + expected_receipt) | ||
| print("Actual receipt:\n" + actual_receipt) | ||
|
|
||
| assert actual_receipt == expected_receipt | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Необходимо исправить здесь и далее: от всех print'ов в проекте лучше избавиться