-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_jar.py
More file actions
35 lines (27 loc) · 675 Bytes
/
test_jar.py
File metadata and controls
35 lines (27 loc) · 675 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import pytest
from jar import Jar
def test_init():
jar = Jar()
assert jar.capacity == 12
assert jar.size == 0
with pytest.raises(ValueError):
Jar(-1)
with pytest.raises(ValueError):
Jar("ten")
def test_str():
jar = Jar()
jar.deposit(3)
assert str(jar) == "🍪🍪🍪"
def test_deposit():
jar = Jar(5)
jar.deposit(3)
assert jar.size == 3
with pytest.raises(ValueError):
jar.deposit(3) # would exceed capacity
def test_withdraw():
jar = Jar()
jar.deposit(5)
jar.withdraw(2)
assert jar.size == 3
with pytest.raises(ValueError):
jar.withdraw(10) # not enough cookies