/
test_jar.py
45 lines (37 loc) · 911 Bytes
/
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2023/12/27 19:54
# @Author : QingYang H.
# @File : test_jar.py
import pytest
from jar import Jar
def test_init():
jar = Jar(10)
assert jar.size == 0
assert jar.capacity == 10
with pytest.raises(ValueError):
Jar(0)
with pytest.raises(ValueError):
Jar(-1)
def test_str():
jar = Jar()
assert str(jar) == ""
jar.deposit(1)
assert str(jar) == "🍪"
jar.deposit(11)
assert str(jar) == "🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪"
def test_deposit():
jar = Jar(10)
jar.deposit(1)
assert jar.size == 1
jar.deposit(8)
assert jar.size == 9
with pytest.raises(ValueError):
jar.deposit(2)
def test_withdraw():
jar = Jar(10)
jar.deposit(5)
jar.withdraw(1)
assert jar.size == 4
with pytest.raises(ValueError):
jar.withdraw(5)