feat: add addition and subtraction to Money and Price
This commit is contained in:
@@ -5,3 +5,9 @@ from decimal import Decimal
|
||||
@dataclass(frozen=True)
|
||||
class Money:
|
||||
amount: Decimal
|
||||
|
||||
def __add__(self, other):
|
||||
return Money(self.amount + other.amount)
|
||||
|
||||
def __sub__(self, other):
|
||||
return Money(self.amount - other.amount)
|
||||
|
||||
@@ -22,3 +22,18 @@ def test_money_equality():
|
||||
money1 = Money(amount=Decimal("50.00"))
|
||||
money2 = Money(amount=Decimal("50.00"))
|
||||
assert money1 == money2
|
||||
|
||||
|
||||
def test_money_add():
|
||||
money1 = Money(amount=Decimal("2.00"))
|
||||
money2 = Money(amount=Decimal("3.00"))
|
||||
|
||||
assert (money1 + money2) == Money(amount=Decimal("5.00"))
|
||||
assert money1 == Money(amount=Decimal("2.00"))
|
||||
assert money2 == Money(amount=Decimal("3.00"))
|
||||
|
||||
|
||||
def test_money_substract():
|
||||
money1 = Money(amount=Decimal("5.00"))
|
||||
money2 = Money(amount=Decimal("3.00"))
|
||||
assert (money1 - money2) == Money(amount=Decimal("2.00"))
|
||||
|
||||
Reference in New Issue
Block a user