Skip to content

Instantly share code, notes, and snippets.

@mohammadali66
Created September 13, 2022 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohammadali66/3f2ba9813b2f7c558747ba2a04a238ce to your computer and use it in GitHub Desktop.
Save mohammadali66/3f2ba9813b2f7c558747ba2a04a238ce to your computer and use it in GitHub Desktop.
fiver = Money('gbp', 5)
tenner = Money('gbp', 10)
def can_add_money_values_for_the_same_currency():
assert fiver + fiver == tenner
def can_subtract_money_values():
assert tenner - fiver == fiver
def adding_different_currencies_fails():
with pytest.raises(ValueError):
Money('usd', 10) + Money('gbp', 10)
def can_multiply_money_by_a_number():
assert fiver * 5 == Money('gbp', 25)
def multiplying_two_money_values_is_an_error():
with pytest.raises(TypeError):
tenner * fiver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment