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.

49 lines
1.2 KiB

  1. #ifdef TEST
  2. #include "unity.h"
  3. #include "../src/interestCalculator.c"
  4. void setUp(void)
  5. {
  6. }
  7. void tearDown(void)
  8. {
  9. }
  10. void test_initiateInterest(void) {
  11. /* Arrange */
  12. int length = 10;
  13. float startAmount[] = {34, 233, 4400, 1600, 245, 34544, 3767.32, 1422, 5435, 8199};
  14. float yearlyInterest=12;
  15. float durationInYears=2.5;
  16. float monthlyInterest=8;
  17. float durationInMonths=3.9;
  18. float resultsYearly[length];
  19. float resultsMonthly[length];
  20. float expectedYearly[]={44.2,302.9,5720,2080,318.5,44907.2,4897.516,1848.6,7065.5,10658.7};
  21. float expectedMonthly[]={44.608,305.696,5772.8,2099.2,321.44,45321.73,4942.724,1865.664,7130.72,10757.09};
  22. /* Act */
  23. for (int i = 0; i < length; i++) {
  24. resultsYearly[i]=initiateInterest(startAmount[i],yearlyInterest/100, durationInYears);
  25. }
  26. for (int i = 0; i < length; i++) {
  27. resultsMonthly[i]=initiateInterest(startAmount[i],monthlyInterest/100, durationInMonths);
  28. }
  29. /* Assert*/
  30. for (int i = 0; i < length; i++) {
  31. TEST_ASSERT_EQUAL_FLOAT(expectedYearly[i], resultsYearly[i]);
  32. TEST_ASSERT_EQUAL_FLOAT(expectedMonthly[i], resultsMonthly[i]);
  33. }
  34. }
  35. #endif // TEST