feat: pricing function for test tutorial test: test cases for pricing
This commit is contained in:
parent
ed538a8810
commit
6b28a6ab1d
@ -1,2 +1,6 @@
|
|||||||
def discount_price(price: float, percent: float) -> float:
|
def discount_price(price: float, percent: float) -> float:
|
||||||
|
if price < 0:
|
||||||
|
raise ValueError("Price must be >= 0")
|
||||||
|
if not 0 <= percent <= 100:
|
||||||
|
raise ValueError("Percent must be between 0 and 100")
|
||||||
return price - price * percent / 100
|
return price - price * percent / 100
|
||||||
|
|||||||
@ -1,6 +1,21 @@
|
|||||||
from src.tutorial.testing.shop.pricing import discount_price
|
from src.tutorial.testing.shop.pricing import discount_price
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
def test_discount_price_reduces_price():
|
def test_discount_price_reduces_price():
|
||||||
result = discount_price(100.0, 20.0)
|
result = discount_price(100.0, 20.0)
|
||||||
assert result == 80
|
assert result == 80
|
||||||
|
|
||||||
|
assert discount_price(100.0, 50.0) == 50
|
||||||
|
assert discount_price(100.0, 0) == 100
|
||||||
|
assert discount_price(100.0, 100) == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_negative_orice_raises_value_error() -> None:
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
discount_price(-100.0, 50.0) is ValueError
|
||||||
|
|
||||||
|
|
||||||
|
def test_percent_above_hundered_message() -> None:
|
||||||
|
with pytest.raises(ValueError, match="between 0 and 100"):
|
||||||
|
discount_price(100.0, 150.0)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user