Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

currency_converter normal mode #2

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Found error in test file and edited both scripts to fix.
Daniel Newell committed Jan 20, 2015
commit 891b5cd066d9e58905ca9701efa0fc7e34a21e11
7 changes: 4 additions & 3 deletions currency.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@

def convert(rates, value, origin, to):

for countries in rates:
if countries[0] == origin and countries[1] == to:
print(countries[2]*value)
return countries[2]*value
elif countries[0] == to and countries[1] == origin:
print(round(1/rates[0][2]*value, 2))
return round(1/rates[0][2]*value, 2)
print(round(1/countries[2]*value, 2))
return round(1/countries[2]*value, 2)

if __name__ == '__main__':

convert([("USD", "EUR", 0.74), ("EUR", "JPY", 145.949)],
1, "EUR", "JPY")
1, "JPY", "EUR")
17 changes: 16 additions & 1 deletion test_currency.py
Original file line number Diff line number Diff line change
@@ -6,6 +6,21 @@ def test_convert():
assert convert([("USD", "USD", 1)], 75, "USD", "USD") == 75
assert convert([("USD", "EUR", 0.74)], 1, "USD", "EUR") == .74
assert convert([("USD", "EUR", 0.74)], .5, "USD", "EUR") == .37

def test_convert_with_reverse_rate():

assert convert([("USD", "EUR", 0.74)], 1, "EUR", "USD") == 1.35

def test_convert_with_two_rates():

assert convert([("USD", "EUR", 0.74), ("EUR", "JPY", 145.949)],
1, "EUR", "JPY") == 145.949

assert convert([("USD", "EUR", 0.74), ("EUR", "JPY", 145.949)],
1, "JPY", "EUR") == .01

assert convert([("USD", "EUR", 0.74), ("EUR", "JPY", 145.949)],
1, "USD", "EUR") == .74

assert convert([("USD", "EUR", 0.74), ("EUR", "JPY", 145.949)],
1, "EUR", "JPY")
1, "EUR", "USD") == 1.35