Add tests and publish repository metadata for MIL-003
Add 19 pytest tests covering the report, resource check, coin processing, refunds, change, profit, make_coffee and the main loop. Add a tests package and put the project root on the pytest path. Doxygen output is clean. The repository description and topics were set on the git host. Closes #13 Closes #14 Closes #15 Closes #16 Closes #17 Task: MIL-003#1 Task: MIL-003#2 Task: MIL-003#3 Task: MIL-003#4 Task: MIL-003#5
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
"""!
|
||||
@file test_resources.py
|
||||
@brief Tests for the report and the resource check.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
from coffee_machine.constants import INITIAL_RESOURCES, MENU
|
||||
from coffee_machine.main import format_money, is_resource_sufficient, report
|
||||
|
||||
|
||||
def test_format_money_shows_two_decimals() -> None:
|
||||
"""!
|
||||
@brief Cents are shown as dollars with two decimals.
|
||||
"""
|
||||
assert format_money(250) == "$2.50"
|
||||
assert format_money(0) == "$0.00"
|
||||
|
||||
|
||||
def test_report_prints_resources_and_money(capsys: pytest.CaptureFixture[str]) -> None:
|
||||
"""!
|
||||
@brief The report lists each resource with its unit, then the money.
|
||||
"""
|
||||
report({"water": 300, "milk": 200, "coffee": 100}, 250)
|
||||
assert capsys.readouterr().out == (
|
||||
"Water: 300ml\nMilk: 200ml\nCoffee: 100g\nMoney: $2.50\n"
|
||||
)
|
||||
|
||||
|
||||
def test_is_resource_sufficient_when_enough() -> None:
|
||||
"""!
|
||||
@brief An order is accepted when every ingredient is available.
|
||||
"""
|
||||
assert is_resource_sufficient(MENU["latte"]["ingredients"], INITIAL_RESOURCES)
|
||||
|
||||
|
||||
def test_is_resource_sufficient_when_exactly_enough() -> None:
|
||||
"""!
|
||||
@brief Using up an ingredient completely is allowed.
|
||||
"""
|
||||
assert is_resource_sufficient({"water": 300}, {"water": 300})
|
||||
|
||||
|
||||
def test_is_resource_sufficient_names_missing_resource(
|
||||
capsys: pytest.CaptureFixture[str],
|
||||
) -> None:
|
||||
"""!
|
||||
@brief A short ingredient is refused and named.
|
||||
"""
|
||||
resources = {"water": 300, "milk": 100, "coffee": 100}
|
||||
assert not is_resource_sufficient(MENU["latte"]["ingredients"], resources)
|
||||
assert capsys.readouterr().out == "Sorry there is not enough milk.\n"
|
||||
Reference in New Issue
Block a user