Browse Source

Merge branch 'feature/currency-exchange' into feature/balance-operations

remotes/origin/feature/loan-eligibility
Shivam Chaudhary 2 years ago
parent
commit
f1730d516d
  1. 7
      src/currencyExchange.c
  2. 4
      src/currencyExchange.h
  3. 10
      tests/test_currencyExchange.c

7
src/currencyExchange.c

@ -7,6 +7,13 @@ float convert(float euro, int newCurrencyCode) {
case CURRENCY_CODE_GBP: case CURRENCY_CODE_GBP:
return ( euro * GBP_RATE_OF_ONE_EURO ); 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; return -1;

4
src/currencyExchange.h

@ -5,9 +5,13 @@
#define USD_RATE_OF_ONE_EURO 1.07 #define USD_RATE_OF_ONE_EURO 1.07
#define GBP_RATE_OF_ONE_EURO 0.89 #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_USD 1
#define CURRENCY_CODE_GBP 2 #define CURRENCY_CODE_GBP 2
#define CURRENCY_CODE_JAPANESE_YEN 3
#define CURRENCY_CODE_CHINESE_YUAN 4
float convert(float euro, int newCurrencyCode); float convert(float euro, int newCurrencyCode);

10
tests/test_currencyExchange.c

@ -20,13 +20,19 @@ void test_convert(void) {
float expectedUSD[length]; float expectedUSD[length];
float expectedGBP[length]; float expectedGBP[length];
float expectedYEN[length];
float expectedYUAN[length];
float resultUSD[length]; float resultUSD[length];
float resultGBP[length]; float resultGBP[length];
float resultYEN[length];
float resultYUAN[length];
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
expectedUSD[i] = euro[i] * USD_RATE_OF_ONE_EURO; expectedUSD[i] = euro[i] * USD_RATE_OF_ONE_EURO;
expectedGBP[i] = euro[i] * GBP_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 */ /* Act */
@ -34,6 +40,8 @@ void test_convert(void) {
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
resultUSD[i] = convert(euro[i], CURRENCY_CODE_USD); resultUSD[i] = convert(euro[i], CURRENCY_CODE_USD);
resultGBP[i] = convert(euro[i], CURRENCY_CODE_GBP); 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*/ /* Assert*/
@ -41,6 +49,8 @@ void test_convert(void) {
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
TEST_ASSERT_EQUAL_FLOAT(expectedUSD[i], resultUSD[i]); TEST_ASSERT_EQUAL_FLOAT(expectedUSD[i], resultUSD[i]);
TEST_ASSERT_EQUAL_FLOAT(expectedGBP[i], resultGBP[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]);
} }
} }

Loading…
Cancel
Save