From e3e049ffef456fdb2788f815d5c59089fe27ef86 Mon Sep 17 00:00:00 2001 From: Daniel Newell Date: Tue, 20 Jan 2015 13:40:26 -0500 Subject: [PATCH 1/9] First test to check whether same countries == same value. --- currency.py | 4 ++++ test_currency.py | 6 ++++++ 2 files changed, 10 insertions(+) create mode 100644 currency.py create mode 100644 test_currency.py diff --git a/currency.py b/currency.py new file mode 100644 index 0000000..703460e --- /dev/null +++ b/currency.py @@ -0,0 +1,4 @@ + +def convert(rates, value, origin, to): + + return rates[0][2]*value diff --git a/test_currency.py b/test_currency.py new file mode 100644 index 0000000..f3b66bd --- /dev/null +++ b/test_currency.py @@ -0,0 +1,6 @@ + +from currency import convert + +def test_convert(): + + assert convert([("USD", "USD", 1)], 75, "USD", "USD") == 75 From c2f408e3d98bb44e22f74e6e1d912b979b409d11 Mon Sep 17 00:00:00 2001 From: Daniel Newell Date: Tue, 20 Jan 2015 13:46:53 -0500 Subject: [PATCH 2/9] Second test passed --- test_currency.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test_currency.py b/test_currency.py index f3b66bd..b4bf659 100644 --- a/test_currency.py +++ b/test_currency.py @@ -4,3 +4,4 @@ def test_convert(): assert convert([("USD", "USD", 1)], 75, "USD", "USD") == 75 + assert convert([("USD", "EUR", 0.74)], 1, "USD", "EUR") == .74 From dc2bade7c92321c0505dea42a449ba8b302488ec Mon Sep 17 00:00:00 2001 From: Daniel Newell Date: Tue, 20 Jan 2015 13:50:37 -0500 Subject: [PATCH 3/9] Third test passed. --- test_currency.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test_currency.py b/test_currency.py index b4bf659..8e1a20d 100644 --- a/test_currency.py +++ b/test_currency.py @@ -5,3 +5,4 @@ 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 From 15c6c91252e757135be622b577b52f41ff5b49a2 Mon Sep 17 00:00:00 2001 From: Daniel Newell Date: Tue, 20 Jan 2015 14:17:01 -0500 Subject: [PATCH 4/9] Got test number 3 working --- currency.py | 2 ++ test_currency.py | 1 + 2 files changed, 3 insertions(+) diff --git a/currency.py b/currency.py index 703460e..16eb56d 100644 --- a/currency.py +++ b/currency.py @@ -1,4 +1,6 @@ def convert(rates, value, origin, to): + if (rates[0][1], rates[0][0]) == (origin, to): + return round(1/rates[0][2]*value, 2) return rates[0][2]*value diff --git a/test_currency.py b/test_currency.py index 8e1a20d..72f894e 100644 --- a/test_currency.py +++ b/test_currency.py @@ -6,3 +6,4 @@ 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 + assert convert([("USD", "EUR", 0.74)], 1, "EUR", "USD") == 1.35 From 268794c43858c227fa272a7dfa6d696b16cfd3e8 Mon Sep 17 00:00:00 2001 From: Daniel Newell Date: Tue, 20 Jan 2015 14:56:13 -0500 Subject: [PATCH 5/9] Completed test number 4, had to re do all the code to get it all to pass --- currency.py | 14 +++++++++++--- test_currency.py | 2 ++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/currency.py b/currency.py index 16eb56d..dc6ad0e 100644 --- a/currency.py +++ b/currency.py @@ -1,6 +1,14 @@ def convert(rates, value, origin, to): - if (rates[0][1], rates[0][0]) == (origin, to): - return round(1/rates[0][2]*value, 2) + 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) - return rates[0][2]*value +if __name__ == '__main__': + + convert([("USD", "EUR", 0.74), ("EUR", "JPY", 145.949)], + 1, "EUR", "JPY") diff --git a/test_currency.py b/test_currency.py index 72f894e..d8835d1 100644 --- a/test_currency.py +++ b/test_currency.py @@ -7,3 +7,5 @@ def test_convert(): assert convert([("USD", "EUR", 0.74)], 1, "USD", "EUR") == .74 assert convert([("USD", "EUR", 0.74)], .5, "USD", "EUR") == .37 assert convert([("USD", "EUR", 0.74)], 1, "EUR", "USD") == 1.35 + assert convert([("USD", "EUR", 0.74), ("EUR", "JPY", 145.949)], + 1, "EUR", "JPY") From 891b5cd066d9e58905ca9701efa0fc7e34a21e11 Mon Sep 17 00:00:00 2001 From: Daniel Newell Date: Tue, 20 Jan 2015 15:10:45 -0500 Subject: [PATCH 6/9] Found error in test file and edited both scripts to fix. --- currency.py | 7 ++++--- test_currency.py | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/currency.py b/currency.py index dc6ad0e..58fa697 100644 --- a/currency.py +++ b/currency.py @@ -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") diff --git a/test_currency.py b/test_currency.py index d8835d1..cda8522 100644 --- a/test_currency.py +++ b/test_currency.py @@ -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 From 666e050a0b1c0a1624edc7e0c4097ae6ef194086 Mon Sep 17 00:00:00 2001 From: Daniel Newell Date: Tue, 20 Jan 2015 15:29:21 -0500 Subject: [PATCH 7/9] Added more robust tests --- currency.py | 4 +--- test_currency.py | 9 +++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/currency.py b/currency.py index 58fa697..2fc30ac 100644 --- a/currency.py +++ b/currency.py @@ -3,13 +3,11 @@ 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/countries[2]*value, 2)) return round(1/countries[2]*value, 2) if __name__ == '__main__': convert([("USD", "EUR", 0.74), ("EUR", "JPY", 145.949)], - 1, "JPY", "EUR") + 1, "JPY", "USD") diff --git a/test_currency.py b/test_currency.py index cda8522..9e81be2 100644 --- a/test_currency.py +++ b/test_currency.py @@ -24,3 +24,12 @@ def test_convert_with_two_rates(): assert convert([("USD", "EUR", 0.74), ("EUR", "JPY", 145.949)], 1, "EUR", "USD") == 1.35 + + +def test_convert_with_more_than_two_rates(): + + assert convert([("USD", "EUR", 0.74), ("EUR", "JPY", 145.949), ("USD" ,"AUD", 1.22)], + 1, "USD", "AUD") == 1.22 + + assert convert([("USD", "EUR", 0.74), ("EUR", "JPY", 145.949), ("USD" ,"AUD", 1.22)], + 1, "AUD", "USD") == .82 From d0b789d71f877632ca09d6c48b4580d2ace40930 Mon Sep 17 00:00:00 2001 From: Daniel Newell Date: Tue, 20 Jan 2015 15:52:54 -0500 Subject: [PATCH 8/9] Fixed up pep8 formatting --- currency-converter | 1 + currency.py | 5 ----- test_currency.py | 19 +++++++++++-------- 3 files changed, 12 insertions(+), 13 deletions(-) create mode 160000 currency-converter diff --git a/currency-converter b/currency-converter new file mode 160000 index 0000000..be08f16 --- /dev/null +++ b/currency-converter @@ -0,0 +1 @@ +Subproject commit be08f162c74502ec7c7eb1240f6a025e4114adff diff --git a/currency.py b/currency.py index 2fc30ac..8e42e36 100644 --- a/currency.py +++ b/currency.py @@ -6,8 +6,3 @@ def convert(rates, value, origin, to): return countries[2]*value elif countries[0] == to and countries[1] == origin: return round(1/countries[2]*value, 2) - -if __name__ == '__main__': - - convert([("USD", "EUR", 0.74), ("EUR", "JPY", 145.949)], - 1, "JPY", "USD") diff --git a/test_currency.py b/test_currency.py index 9e81be2..4064792 100644 --- a/test_currency.py +++ b/test_currency.py @@ -1,35 +1,38 @@ from currency import convert + 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 + 1, "EUR", "JPY") == 145.949 assert convert([("USD", "EUR", 0.74), ("EUR", "JPY", 145.949)], - 1, "JPY", "EUR") == .01 + 1, "JPY", "EUR") == .01 assert convert([("USD", "EUR", 0.74), ("EUR", "JPY", 145.949)], - 1, "USD", "EUR") == .74 + 1, "USD", "EUR") == .74 assert convert([("USD", "EUR", 0.74), ("EUR", "JPY", 145.949)], - 1, "EUR", "USD") == 1.35 + 1, "EUR", "USD") == 1.35 def test_convert_with_more_than_two_rates(): - assert convert([("USD", "EUR", 0.74), ("EUR", "JPY", 145.949), ("USD" ,"AUD", 1.22)], - 1, "USD", "AUD") == 1.22 + assert convert([("USD", "EUR", 0.74), ("EUR", "JPY", 145.949), + ("USD", "AUD", 1.22)], 1, "USD", "AUD") == 1.22 - assert convert([("USD", "EUR", 0.74), ("EUR", "JPY", 145.949), ("USD" ,"AUD", 1.22)], - 1, "AUD", "USD") == .82 + assert convert([("USD", "EUR", 0.74), ("EUR", "JPY", 145.949), + ("USD", "AUD", 1.22)], 1, "AUD", "USD") == .82 From 8f509b6c4d234178c4645cd6f415047d23ba17f9 Mon Sep 17 00:00:00 2001 From: Daniel Newell Date: Tue, 20 Jan 2015 15:54:10 -0500 Subject: [PATCH 9/9] Deleted extra directory --- .DS_Store | Bin 0 -> 6148 bytes currency-converter | 1 - 2 files changed, 1 deletion(-) create mode 100644 .DS_Store delete mode 160000 currency-converter diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..01b9af29dd26605a9bf1a5a57468abc8efefcd38 GIT binary patch literal 6148 zcmeHKOHKko5Pgj-KsFOsE@$aR5^pdPFk#^a_M&`(Bp}Mi=x&bTp*(;G@E-W8x*;=+ zCa#Rps-)^Q)%E)GW-?6!aE2HPv?F1^3`x1;>$)&H&G^Ij0sllX|@ip>^;fU9d7GbJI3Ai z-N@26ob@XtLXAE#dzr{#0dox|^&2+@dHQzkGdz@!L_9^3>?MG%7+!teh4EH8u z(A{Rk2-FH=)MXucR_ThB+4WY@K?~r zs_ZqZex$ouGWNc+Vtp!EK8G_i1x$f|t^m($u}aOOMN_~OFa>rB$oC1#%ZCdyyKqBsIy=XY zwHz+-Xweif1@a0U_@9xS|E;g@|9O)AG6hV5Kc#>xH@nRSw-nCS!sg_xjp^5PF{w*E l?kH^NQOsI7ijV1P%*WCoCIM5A%+TzQfXZOO6!=jEJ^)!gjL851 literal 0 HcmV?d00001 diff --git a/currency-converter b/currency-converter deleted file mode 160000 index be08f16..0000000 --- a/currency-converter +++ /dev/null @@ -1 +0,0 @@ -Subproject commit be08f162c74502ec7c7eb1240f6a025e4114adff