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.

95 lines
1.9 KiB

  1. #ifdef TEST
  2. #include "unity.h"
  3. #include "currencyExchange.h"
  4. void setUp(void)
  5. {
  6. }
  7. void tearDown(void)
  8. {
  9. }
  10. //void test_toUSD(void) {
  11. //
  12. // /* Arrange */
  13. //
  14. // int length = 5;
  15. // float euro[] = {34, 233, 400, 100, 45};
  16. //
  17. // float expectedUSD[length];
  18. // float resultUSD[length];
  19. //
  20. // for (int i = 0; i < length; i++) {
  21. // resultUSD[i] = toUSD(euro[i]);
  22. // }
  23. //
  24. // /* Act */
  25. //
  26. // for (int i = 0; i < length; i++) {
  27. // expectedUSD[i] = euro[i] * CURRENT_USD_RATE_OF_ONE_EURO;
  28. // }
  29. //
  30. // /* Assert */
  31. //
  32. // for (int i = 0; i < length; i++) {
  33. // TEST_ASSERT_EQUAL_FLOAT(expectedUSD[i], resultUSD[i]);
  34. // }
  35. //
  36. //}
  37. //
  38. //void test_toGBP(void) {
  39. //
  40. // /* Arrange */
  41. //
  42. // int length = 5;
  43. // float euro[] = {34, 233, 400, 100, 45};
  44. //
  45. // float expectedGBP[length];
  46. // float resultGBP[length];
  47. //
  48. // for (int i = 0; i < length; i++) {
  49. // resultGBP[i] = toGBP(euro[i]);
  50. // }
  51. //
  52. // /* Act */
  53. //
  54. // for (int i = 0; i < length; i++) {
  55. // expectedGBP[i] = euro[i] * CURRENT_GBP_RATE_OF_ONE_EURO;
  56. // }
  57. //
  58. // /* Assert */
  59. //
  60. // for (int i = 0; i < length; i++) {
  61. // TEST_ASSERT_EQUAL_FLOAT(expectedGBP[i], resultGBP[i]);
  62. // }
  63. //
  64. //}
  65. void test_convert(void) {
  66. int length = 5;
  67. float euro[] = {34, 233, 400, 100, 45};
  68. float expectedUSD[length];
  69. float expectedGBP[length];
  70. float resultUSD[length];
  71. float resultGBP[length];
  72. for (int i = 0; i < length; i++) {
  73. expectedUSD[i] = euro[i] * CURRENT_USD_RATE_OF_ONE_EURO;
  74. expectedGBP[i] = euro[i] * CURRENT_GBP_RATE_OF_ONE_EURO;
  75. }
  76. for (int i = 0; i < length; i++) {
  77. resultUSD[i] = convert(euro[i], 1);
  78. resultGBP[i] = convert(euro[i], 2);
  79. }
  80. for (int i = 0; i < length; i++) {
  81. TEST_ASSERT_EQUAL_FLOAT(expectedUSD[i], resultUSD[i]);
  82. TEST_ASSERT_EQUAL_FLOAT(expectedGBP[i], resultGBP[i]);
  83. }
  84. }
  85. #endif // TEST