You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.4 KiB

  1. #ifdef TEST
  2. #include "unity.h"
  3. #include "../src/currencyExchange.c"
  4. void setUp(void)
  5. {
  6. }
  7. void tearDown(void)
  8. {
  9. }
  10. void test_convert(void) {
  11. /* Arrange */
  12. int length = 10;
  13. float euro[] = {34, 233, 400, 100, 45, 344, 767.32, 122, 435, 899};
  14. float expectedUSD[length];
  15. float expectedGBP[length];
  16. float expectedYEN[length];
  17. float expectedYUAN[length];
  18. float resultUSD[length];
  19. float resultGBP[length];
  20. float resultYEN[length];
  21. float resultYUAN[length];
  22. for (int i = 0; i < length; i++) {
  23. expectedUSD[i] = euro[i] * USD_RATE_OF_ONE_EURO;
  24. expectedGBP[i] = euro[i] * GBP_RATE_OF_ONE_EURO;
  25. expectedYEN[i] = euro[i] * JAPANESE_YEN_RATE_OF_ONE_EURO;
  26. expectedYUAN[i] = euro[i] * CHINESE_YUAN_RATE_OF_ONE_EURO;
  27. }
  28. /* Act */
  29. for (int i = 0; i < length; i++) {
  30. resultUSD[i] = convert(euro[i], CURRENCY_CODE_USD);
  31. resultGBP[i] = convert(euro[i], CURRENCY_CODE_GBP);
  32. resultYEN[i] = convert(euro[i], CURRENCY_CODE_JAPANESE_YEN);
  33. resultYUAN[i] = convert(euro[i], CURRENCY_CODE_CHINESE_YUAN);
  34. }
  35. /* Assert*/
  36. for (int i = 0; i < length; i++) {
  37. TEST_ASSERT_EQUAL_FLOAT(expectedUSD[i], resultUSD[i]);
  38. TEST_ASSERT_EQUAL_FLOAT(expectedGBP[i], resultGBP[i]);
  39. TEST_ASSERT_EQUAL_FLOAT(expectedYEN[i], resultYEN[i]);
  40. TEST_ASSERT_EQUAL_FLOAT(expectedYUAN[i], resultYUAN[i]);
  41. }
  42. }
  43. #endif // TEST