-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_jar.py
50 lines (44 loc) · 1.38 KB
/
test_jar.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from jar import Jar
import pytest
@pytest.fixture
def empty_jar():
return Jar()
@pytest.fixture
def jar_with_capacity_10():
return Jar(10)
def test_init():
with pytest.raises(ValueError):
Jar(-1)
jar = Jar(0)
assert jar.capacity == 0
assert jar.size == 0
jar = Jar(12)
assert jar.capacity == 12
assert jar.size == 0
def test_str(empty_jar):
assert str(empty_jar) == ""
empty_jar.deposit(1)
assert str(empty_jar) == "🍪"
empty_jar.deposit(11)
assert str(empty_jar) == "🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪"
def test_deposit(jar_with_capacity_10):
with pytest.raises(ValueError):
jar_with_capacity_10.deposit(-1)
with pytest.raises(ValueError):
jar_with_capacity_10.deposit(11)
jar_with_capacity_10.deposit(3)
assert jar_with_capacity_10.size == 3
jar_with_capacity_10.deposit(7)
assert jar_with_capacity_10.size == 10
def test_withdraw(jar_with_capacity_10):
with pytest.raises(ValueError):
jar_with_capacity_10.withdraw(-1)
with pytest.raises(ValueError):
jar_with_capacity_10.withdraw(1)
jar_with_capacity_10.deposit(5)
jar_with_capacity_10.withdraw(2)
assert jar_with_capacity_10.size == 3
with pytest.raises(ValueError):
jar_with_capacity_10.withdraw(4)
jar_with_capacity_10.withdraw(3)
assert jar_with_capacity_10.size == 0