Browse Source

Add test for function 'convert'

remotes/origin/feature/currency-exchange
Shivam Chaudhary 2 years ago
parent
commit
33e3f3eb6f
  1. 102
      tests/test_currencyExchange.c

102
tests/test_currencyExchange.c

@ -11,62 +11,86 @@ void tearDown(void)
{ {
} }
void test_toUSD(void) {
/* Arrange */
//void test_toUSD(void) {
//
// /* Arrange */
//
// int length = 5;
// float euro[] = {34, 233, 400, 100, 45};
//
// float expectedUSD[length];
// float resultUSD[length];
//
// for (int i = 0; i < length; i++) {
// resultUSD[i] = toUSD(euro[i]);
// }
//
// /* Act */
//
// for (int i = 0; i < length; i++) {
// expectedUSD[i] = euro[i] * CURRENT_USD_RATE_OF_ONE_EURO;
// }
//
// /* Assert */
//
// for (int i = 0; i < length; i++) {
// TEST_ASSERT_EQUAL_FLOAT(expectedUSD[i], resultUSD[i]);
// }
//
//}
//
//void test_toGBP(void) {
//
// /* Arrange */
//
// int length = 5;
// float euro[] = {34, 233, 400, 100, 45};
//
// float expectedGBP[length];
// float resultGBP[length];
//
// for (int i = 0; i < length; i++) {
// resultGBP[i] = toGBP(euro[i]);
// }
//
// /* Act */
//
// for (int i = 0; i < length; i++) {
// expectedGBP[i] = euro[i] * CURRENT_GBP_RATE_OF_ONE_EURO;
// }
//
// /* Assert */
//
// for (int i = 0; i < length; i++) {
// TEST_ASSERT_EQUAL_FLOAT(expectedGBP[i], resultGBP[i]);
// }
//
//}
void test_convert(void) {
int length = 5; int length = 5;
float euro[] = {34, 233, 400, 100, 45}; float euro[] = {34, 233, 400, 100, 45};
float expectedUSD[length]; float expectedUSD[length];
float resultUSD[length];
for (int i = 0; i < length; i++) {
resultUSD[i] = toUSD(euro[i]);
}
/* Act */
for (int i = 0; i < length; i++) {
expectedUSD[i] = euro[i] * CURRENT_USD_RATE_OF_ONE_EURO;
}
/* Assert */
for (int i = 0; i < length; i++) {
TEST_ASSERT_EQUAL_FLOAT(expectedUSD[i], resultUSD[i]);
}
}
void test_toGBP(void) {
/* Arrange */
int length = 5;
float euro[] = {34, 233, 400, 100, 45};
float expectedGBP[length]; float expectedGBP[length];
float resultUSD[length];
float resultGBP[length]; float resultGBP[length];
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
resultGBP[i] = toGBP(euro[i]);
expectedUSD[i] = euro[i] * CURRENT_USD_RATE_OF_ONE_EURO;
expectedGBP[i] = euro[i] * CURRENT_GBP_RATE_OF_ONE_EURO;
} }
/* Act */
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
expectedGBP[i] = euro[i] * CURRENT_GBP_RATE_OF_ONE_EURO;
resultUSD[i] = convert(euro[i], 1);
resultGBP[i] = convert(euro[i], 2);
} }
/* Assert */
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(expectedGBP[i], resultGBP[i]); TEST_ASSERT_EQUAL_FLOAT(expectedGBP[i], resultGBP[i]);
} }
} }
#endif // TEST #endif // TEST
Loading…
Cancel
Save