From 336ab0aea98871e2d04eba551f4e12641ff03c8f Mon Sep 17 00:00:00 2001 From: fdlt3817 Date: Fri, 10 Feb 2023 22:52:54 +0100 Subject: [PATCH] Create test for invalid interests --- tests/test_interestCalculator.c | 37 ++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/tests/test_interestCalculator.c b/tests/test_interestCalculator.c index 1aa11ca..410f723 100644 --- a/tests/test_interestCalculator.c +++ b/tests/test_interestCalculator.c @@ -46,5 +46,40 @@ void test_initiateInterest(void) { } } +void test_initiateInterestFalse(void) { -#endif // TEST \ No newline at end of file + /* 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[]={0,0,0,0,0,0,0,0,0,0}; + float expectedMonthly[]={0,0,0,0,0,0,0,0,0,0}; + + /* 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_FALSE(expectedYearly[i] == resultsYearly[i]); + TEST_ASSERT_FALSE(expectedMonthly[i] == resultsMonthly[i]); + } +} + + +#endif // TEST