From 9c16e0379956d590966f56f6b0d72abadd2fa2d8 Mon Sep 17 00:00:00 2001 From: fdlt3817 Date: Fri, 10 Feb 2023 22:47:26 +0100 Subject: [PATCH] Create unit test for failed deposits --- tests/test_depositMoney.c | 41 +++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/tests/test_depositMoney.c b/tests/test_depositMoney.c index 186ef28..2447ad9 100644 --- a/tests/test_depositMoney.c +++ b/tests/test_depositMoney.c @@ -12,25 +12,50 @@ void tearDown(void) } void test_depositSpecificAmount(void) { - + /* Arrange */ - + int length = 5; int userIDs[] = {1234,1235,1236,1237,1238}; float amountToDeposit[] = {200.5, 340, 244.5, 340, 1200}; - + bool result[length]; - + /* Act */ - + for (int i = 0; i < length; i++) { result[i] = depositSpecificAmount( userIDs[i], amountToDeposit[i] ); } - + /* Assert */ - + for (int i = 0; i < length; i++) { TEST_ASSERT_TRUE(result[i]); } +} + + void test_depositSpecificAmountFail(void) { + + /* Arrange */ + + int length = 5; + int userIDs[] = {1234,1235,1236,1237,1238}; + float amountToDeposit[] = {-23, -3, -234, -23, -400}; + + bool result[length]; + + /* Act */ + + for (int i = 0; i < length; i++) { + result[i] = depositSpecificAmount( userIDs[i], amountToDeposit[i] ); + } + + /* Assert */ + + for (int i = 0; i < length; i++) { + TEST_ASSERT_FALSE(result[i]); + } +} -} \ No newline at end of file + +