forked from tiyd-python-2015-01/currency-converter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_currency.py
62 lines (50 loc) · 2.14 KB
/
test_currency.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
51
52
53
54
55
56
57
58
59
60
61
62
from currency import*
def test_convert_value_check():
assert convert(rates=[('USD', 'USD', 1)],
value=5,
from_string='USD',
to_string='USD') == 5
def test_convert_dollar_to_euro():
rates = [('USD', 'EUR', .74), ('USD', 'JPY', 145.949)]
assert convert(rates,
value=1,
from_string='USD',
to_string='EUR') == 0.74
def test_convert_different_values():
rates = [('USD', 'EUR', .74), ('USD', 'JPY', 145.949)]
assert convert(rates, value=5,
from_string='USD', to_string='EUR') == 3.7
assert convert(rates, value=.2,
from_string='USD', to_string='EUR') == 0.15
assert convert(rates, value=0,
from_string='USD', to_string='EUR') == 0
def test_flipped_conversion():
rates = [('USD', 'EUR', .74), ('USD', 'JPY', 145.949)]
assert convert(rates, value=1,
from_string='EUR', to_string='USD') == 1.35
def test_multiple_conversions():
rates = [('USD', 'EUR', .74),
('USD', 'JPY', 145.949),
('USD', 'CAD', 1.21)]
assert convert(rates, value=500,
from_string='USD', to_string='EUR') == 370
assert convert(rates, value=500,
from_string='EUR', to_string='USD') == 675.68
assert convert(rates, value=500,
from_string='USD', to_string='JPY') == 72974.5
assert convert(rates, value=500,
from_string='JPY', to_string='USD') == 3.43
assert convert(rates, value=500,
from_string='USD', to_string='CAD') == 605
def test_exception_check():
rates = [('USD', 'EUR', .74),
('USD', 'JPY', 145.949),
('USD', 'CAD', 1.21)]
assert exception_check(rates, value=500,
from_string='USD', to_string='EUR') == 370
assert exception_check(rates, value=500,
from_string='USD', to_string='FART') == (
"Error message")
assert exception_check(rates, value=500,
from_string='ABC', to_string='DEF') == (
"Error message")