Queer European MD passionate about IT

test_jar.py 832 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from jar import Jar
  2. def main():
  3. test_capacity()
  4. test_size()
  5. test_deposit()
  6. test_withdraw()
  7. def test_capacity():
  8. j = Jar(capacity=3)
  9. assert j.capacity == 3
  10. def test_size():
  11. j = Jar(capacity=5)
  12. assert j.size == 0
  13. j.deposit(3)
  14. j.withdraw(1)
  15. assert j.size == 2
  16. def test_deposit():
  17. j = Jar(capacity=5)
  18. j.deposit(3)
  19. try:
  20. j.deposit(3)
  21. raise Exception("Deposit n > capacity did not raise ValueError")
  22. except Exception as e:
  23. assert isinstance(e, ValueError)
  24. def test_withdraw():
  25. j = Jar(capacity=5)
  26. j.deposit(3)
  27. j.withdraw(2)
  28. try:
  29. j.withdraw(2)
  30. raise Exception("Withdraw n > size did not raise ValueError")
  31. except Exception as e:
  32. assert isinstance(e, ValueError)
  33. if __name__ == '__main__':
  34. main()