From 29851db5619ae6e08e0c9cfeb0321b62e7a6d100 Mon Sep 17 00:00:00 2001 From: fdlt3817 Date: Fri, 10 Feb 2023 11:27:20 +0100 Subject: [PATCH] Create test for interestCalculator --- tests/test_interestCalculator.c | 50 +++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tests/test_interestCalculator.c diff --git a/tests/test_interestCalculator.c b/tests/test_interestCalculator.c new file mode 100644 index 0000000..04907ed --- /dev/null +++ b/tests/test_interestCalculator.c @@ -0,0 +1,50 @@ +#ifdef TEST + +#include "unity.h" +#include "interestCalculator.h" + +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 \ No newline at end of file