|
|
#ifdef TEST
#include "unity.h"
#include "../src/interestCalculator.c"
void setUp(void) { }
void tearDown(void) { }
void test_initiateInterest(void) {
/* Arrange */
int length = 10; float startAmount[] = {34, 233, 4400, 1600, 245, 34544, 3767.32, 1422, 5435, 8199}; float yearlyInterest=12; float durationInYears=2.5;
float monthlyInterest=8; float durationInMonths=3.9;
float resultsYearly[length]; float resultsMonthly[length]; float expectedYearly[]={44.2,302.9,5720,2080,318.5,44907.2,4897.516,1848.6,7065.5,10658.7}; float expectedMonthly[]={44.608,305.696,5772.8,2099.2,321.44,45321.73,4942.724,1865.664,7130.72,10757.09};
/* Act */
for (int i = 0; i < length; i++) { resultsYearly[i]=initiateInterest(startAmount[i],yearlyInterest/100, durationInYears); } for (int i = 0; i < length; i++) { resultsMonthly[i]=initiateInterest(startAmount[i],monthlyInterest/100, durationInMonths); }
/* Assert*/
for (int i = 0; i < length; i++) { TEST_ASSERT_EQUAL_FLOAT(expectedYearly[i], resultsYearly[i]); TEST_ASSERT_EQUAL_FLOAT(expectedMonthly[i], resultsMonthly[i]); } }
#endif // TEST
|