From 6369691a540520661cb1693f4aa75b1731a937ab Mon Sep 17 00:00:00 2001 From: Shivam Chaudhary Date: Thu, 9 Feb 2023 18:32:22 +0100 Subject: [PATCH 1/3] Add more cases to convert currency to YEN and YUAN --- src/currencyExchange.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/currencyExchange.c b/src/currencyExchange.c index 2a22334..83bf372 100644 --- a/src/currencyExchange.c +++ b/src/currencyExchange.c @@ -7,6 +7,13 @@ float convert(float euro, int newCurrencyCode) { case CURRENCY_CODE_GBP: return ( euro * GBP_RATE_OF_ONE_EURO ); + + case CURRENCY_CODE_JAPANESE_YEN: + return ( euro * JAPANESE_YEN_RATE_OF_ONE_EURO ); + + case CURRENCY_CODE_CHINESE_YUAN: + return ( euro * CHINESE_YUAN_RATE_OF_ONE_EURO ); + } return -1; From fc7d0a52458a1face8c8b2a025f2d43fffdd36c7 Mon Sep 17 00:00:00 2001 From: Shivam Chaudhary Date: Thu, 9 Feb 2023 18:33:03 +0100 Subject: [PATCH 2/3] Add constant values for new currencies --- src/currencyExchange.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/currencyExchange.h b/src/currencyExchange.h index 6629fcc..7aac148 100644 --- a/src/currencyExchange.h +++ b/src/currencyExchange.h @@ -2,8 +2,12 @@ #define USD_RATE_OF_ONE_EURO 1.07 #define GBP_RATE_OF_ONE_EURO 0.89 +#define JAPANESE_YEN_RATE_OF_ONE_EURO 140.9 +#define CHINESE_YUAN_RATE_OF_ONE_EURO 7.29 #define CURRENCY_CODE_USD 1 #define CURRENCY_CODE_GBP 2 +#define CURRENCY_CODE_JAPANESE_YEN 3 +#define CURRENCY_CODE_CHINESE_YUAN 4 float convert(float euro, int newCurrencyCode); \ No newline at end of file From 56a6bd202a43527778ce81f3011a08a5c25f799b Mon Sep 17 00:00:00 2001 From: Shivam Chaudhary Date: Thu, 9 Feb 2023 18:34:29 +0100 Subject: [PATCH 3/3] Add tests for newly added currencies --- tests/test_currencyExchange.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_currencyExchange.c b/tests/test_currencyExchange.c index 821f56a..aae8db0 100644 --- a/tests/test_currencyExchange.c +++ b/tests/test_currencyExchange.c @@ -20,13 +20,19 @@ void test_convert(void) { float expectedUSD[length]; float expectedGBP[length]; + float expectedYEN[length]; + float expectedYUAN[length]; float resultUSD[length]; float resultGBP[length]; + float resultYEN[length]; + float resultYUAN[length]; for (int i = 0; i < length; i++) { expectedUSD[i] = euro[i] * USD_RATE_OF_ONE_EURO; expectedGBP[i] = euro[i] * GBP_RATE_OF_ONE_EURO; + expectedYEN[i] = euro[i] * JAPANESE_YEN_RATE_OF_ONE_EURO; + expectedYUAN[i] = euro[i] * CHINESE_YUAN_RATE_OF_ONE_EURO; } /* Act */ @@ -34,6 +40,8 @@ void test_convert(void) { for (int i = 0; i < length; i++) { resultUSD[i] = convert(euro[i], CURRENCY_CODE_USD); resultGBP[i] = convert(euro[i], CURRENCY_CODE_GBP); + resultYEN[i] = convert(euro[i], CURRENCY_CODE_JAPANESE_YEN); + resultYUAN[i] = convert(euro[i], CURRENCY_CODE_CHINESE_YUAN); } /* Assert*/ @@ -41,6 +49,8 @@ void test_convert(void) { for (int i = 0; i < length; i++) { TEST_ASSERT_EQUAL_FLOAT(expectedUSD[i], resultUSD[i]); TEST_ASSERT_EQUAL_FLOAT(expectedGBP[i], resultGBP[i]); + TEST_ASSERT_EQUAL_FLOAT(expectedYEN[i], resultYEN[i]); + TEST_ASSERT_EQUAL_FLOAT(expectedYUAN[i], resultYUAN[i]); } }