Browse Source

Refactoring: Test work

remotes/origin/feature/loan-eligibility
fdlt3817 2 years ago
parent
commit
10d0cf2def
  1. 6
      build/test/cache/defines_dependency.yml
  2. 159
      build/test/cache/test_currentCustomerAccountBalance.c
  3. 76
      build/test/cache/test_updateCustomerAccountBalance.c
  4. 3
      build/test/dependencies/currentCustomerAccountBalance.d
  5. 5
      build/test/dependencies/test_currentCustomerAccountBalance.d
  6. 4
      build/test/dependencies/test_currentCustomerAccountBalance_runner.d
  7. 5
      build/test/dependencies/test_updateCustomerAccountBalance.d
  8. 5
      build/test/dependencies/updateCustomerAccountBalance.d
  9. BIN
      build/test/out/c/currentCustomerAccountBalance.o
  10. BIN
      build/test/out/c/test_currentCustomerAccountBalance.o
  11. BIN
      build/test/out/c/test_currentCustomerAccountBalance_runner.o
  12. BIN
      build/test/out/c/test_updateCustomerAccountBalance.o
  13. BIN
      build/test/out/c/test_updateCustomerAccountBalance_runner.o
  14. BIN
      build/test/out/c/updateCustomerAccountBalance.o
  15. BIN
      build/test/out/test_currentCustomerAccountBalance.out
  16. BIN
      build/test/out/test_updateCustomerAccountBalance.out
  17. 159
      build/test/preprocess/files/test_currentCustomerAccountBalance.c
  18. 76
      build/test/preprocess/files/test_updateCustomerAccountBalance.c
  19. 3
      build/test/preprocess/includes/test_currentCustomerAccountBalance.c
  20. 4
      build/test/preprocess/includes/test_updateCustomerAccountBalance.c
  21. 30
      build/test/results/test_currentCustomerAccountBalance.pass
  22. 14
      build/test/results/test_updateCustomerAccountBalance.pass
  23. 87
      build/test/runners/test_currentCustomerAccountBalance_runner.c
  24. 36
      build/test/runners/test_updateCustomerAccountBalance_runner.c
  25. 8
      src/updateCustomerAccountBalance.c
  26. 2
      src/updateCustomerAccountBalance.h
  27. 6
      tests/test_updateCustomerAccountBalance.c

6
build/test/cache/defines_dependency.yml

@ -1,5 +1 @@
---
src/currentCustomerAccountBalance.c:
- TEST
src/updateCustomerAccountBalance.c:
- TEST
--- {}

159
build/test/cache/test_currentCustomerAccountBalance.c

@ -1,159 +0,0 @@
#include "src/currentCustomerAccountBalance.h"
#include "/Library/Ruby/Gems/2.6.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h"
void setUp(void)
{
}
void tearDown(void)
{
}
void test_fetchBalanceFromBalanceString(void) {
char balanceString[5][100] = {
"balance=0",
"balance=100",
"balance=200",
"balance=300",
"balance=400"
};
float balance = 0;
float result[5];
float expected[5];
for (int i = 0; i < 5; i++) {
result[i] = fetchBalanceFromBalanceString(balanceString[i]);
}
for (int i = 0; i < 5; i++) {
expected[i] = balance;
balance += 100;
}
for (int i =0; i < 5; i++) {
UnityAssertFloatsWithin((UNITY_FLOAT)((UNITY_FLOAT)((expected[i])) * (UNITY_FLOAT)(0.00001f)), (UNITY_FLOAT)((UNITY_FLOAT)((expected[i]))), (UNITY_FLOAT)((UNITY_FLOAT)((result[i]))), ((((void*)0))), (UNITY_UINT)((UNITY_UINT)(45)));
}
}
void test_checkFileOpen(void) {
FILE *file = fopen("src/CustomerData.txt", "r");
do {if ((file)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(58)));}} while(0);
fclose(file);
}
void test_failOpenFile(void) {
FILE *file = fopen("false_file_name", "r");
do {if (!(file)) {} else {UnityFail( ((" Expected FALSE Was TRUE")), (UNITY_UINT)((UNITY_UINT)(69)));}} while(0);
}
void test_getAvailableAccountBalance(void) {
int user_id = 1234;
float max = 3.40282347e+38F;
int result = getAvailableAccountBalance(user_id);
do {if ((result < max)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(81)));}} while(0);
}

76
build/test/cache/test_updateCustomerAccountBalance.c

@ -1,77 +1 @@
#include "src/updateCustomerAccountBalance.h"
#include "/Library/Ruby/Gems/2.6.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h"
void setUp(void)
{
}
void tearDown(void)
{
}
void test_updateAvailableAccountBalanceSuccess(void){
int length = 10;
float amountToUpdate[] = {200.5, 340, 244.5, 340, 1200, 3232, 1123, 460.5, 900, 1005};
float userIDs[] = {1001,1002,1003,1004,1005,1006,1007,1008,1009};
float expectedValue[length];
float result[length];
for (int i = 0; i < length; i++) {
result[i] = updateAvailableAccountBalance(userIDs[i],amountToUpdate[i]);
}
for (int i = 0; i < length; i++) {
expectedValue[i] = 0;
}
for (int i = 0; i < length; i++) {
UnityAssertFloatsWithin((UNITY_FLOAT)((UNITY_FLOAT)((expectedValue[i])) * (UNITY_FLOAT)(0.00001f)), (UNITY_FLOAT)((UNITY_FLOAT)((expectedValue[i]))), (UNITY_FLOAT)((UNITY_FLOAT)((result[i]))), ((((void*)0))), (UNITY_UINT)((UNITY_UINT)(58)));
}
}

3
build/test/dependencies/currentCustomerAccountBalance.d

@ -1,3 +0,0 @@
build/test/out/c/currentCustomerAccountBalance.o: \
src/currentCustomerAccountBalance.c \
src/currentCustomerAccountBalance.h src/_file_information.h

5
build/test/dependencies/test_currentCustomerAccountBalance.d

@ -1,5 +0,0 @@
build/test/out/c/test_currentCustomerAccountBalance.o: \
tests/test_currentCustomerAccountBalance.c \
/Library/Ruby/Gems/2.6.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \
/Library/Ruby/Gems/2.6.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h \
src/currentCustomerAccountBalance.h src/_file_information.h

4
build/test/dependencies/test_currentCustomerAccountBalance_runner.d

@ -1,4 +0,0 @@
build/test/out/c/test_currentCustomerAccountBalance_runner.o: \
build/test/runners/test_currentCustomerAccountBalance_runner.c \
/Library/Ruby/Gems/2.6.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \
/Library/Ruby/Gems/2.6.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h

5
build/test/dependencies/test_updateCustomerAccountBalance.d

@ -1,5 +1,2 @@
build/test/out/c/test_updateCustomerAccountBalance.o: \ build/test/out/c/test_updateCustomerAccountBalance.o: \
tests/test_updateCustomerAccountBalance.c \
/Library/Ruby/Gems/2.6.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \
/Library/Ruby/Gems/2.6.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h \
src/updateCustomerAccountBalance.h
tests/test_updateCustomerAccountBalance.c

5
build/test/dependencies/updateCustomerAccountBalance.d

@ -1,5 +0,0 @@
build/test/out/c/updateCustomerAccountBalance.o: \
src/updateCustomerAccountBalance.c src/updateCustomerAccountBalance.h \
src/currentCustomerAccountBalance.c \
src/currentCustomerAccountBalance.h src/_file_information.h \
src/lineReplacer.h

BIN
build/test/out/c/currentCustomerAccountBalance.o

BIN
build/test/out/c/test_currentCustomerAccountBalance.o

BIN
build/test/out/c/test_currentCustomerAccountBalance_runner.o

BIN
build/test/out/c/test_updateCustomerAccountBalance.o

BIN
build/test/out/c/test_updateCustomerAccountBalance_runner.o

BIN
build/test/out/c/updateCustomerAccountBalance.o

BIN
build/test/out/test_currentCustomerAccountBalance.out

BIN
build/test/out/test_updateCustomerAccountBalance.out

159
build/test/preprocess/files/test_currentCustomerAccountBalance.c

@ -1,159 +0,0 @@
#include "src/currentCustomerAccountBalance.h"
#include "/Library/Ruby/Gems/2.6.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h"
void setUp(void)
{
}
void tearDown(void)
{
}
void test_fetchBalanceFromBalanceString(void) {
char balanceString[5][100] = {
"balance=0",
"balance=100",
"balance=200",
"balance=300",
"balance=400"
};
float balance = 0;
float result[5];
float expected[5];
for (int i = 0; i < 5; i++) {
result[i] = fetchBalanceFromBalanceString(balanceString[i]);
}
for (int i = 0; i < 5; i++) {
expected[i] = balance;
balance += 100;
}
for (int i =0; i < 5; i++) {
UnityAssertFloatsWithin((UNITY_FLOAT)((UNITY_FLOAT)((expected[i])) * (UNITY_FLOAT)(0.00001f)), (UNITY_FLOAT)((UNITY_FLOAT)((expected[i]))), (UNITY_FLOAT)((UNITY_FLOAT)((result[i]))), ((((void*)0))), (UNITY_UINT)((UNITY_UINT)(45)));
}
}
void test_checkFileOpen(void) {
FILE *file = fopen("src/CustomerData.txt", "r");
do {if ((file)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(58)));}} while(0);
fclose(file);
}
void test_failOpenFile(void) {
FILE *file = fopen("false_file_name", "r");
do {if (!(file)) {} else {UnityFail( ((" Expected FALSE Was TRUE")), (UNITY_UINT)((UNITY_UINT)(69)));}} while(0);
}
void test_getAvailableAccountBalance(void) {
int user_id = 1234;
float max = 3.40282347e+38F;
int result = getAvailableAccountBalance(user_id);
do {if ((result < max)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(81)));}} while(0);
}

76
build/test/preprocess/files/test_updateCustomerAccountBalance.c

@ -1,77 +1 @@
#include "src/updateCustomerAccountBalance.h"
#include "/Library/Ruby/Gems/2.6.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h"
void setUp(void)
{
}
void tearDown(void)
{
}
void test_updateAvailableAccountBalanceSuccess(void){
int length = 10;
float amountToUpdate[] = {200.5, 340, 244.5, 340, 1200, 3232, 1123, 460.5, 900, 1005};
float userIDs[] = {1001,1002,1003,1004,1005,1006,1007,1008,1009};
float expectedValue[length];
float result[length];
for (int i = 0; i < length; i++) {
result[i] = updateAvailableAccountBalance(userIDs[i],amountToUpdate[i]);
}
for (int i = 0; i < length; i++) {
expectedValue[i] = 0;
}
for (int i = 0; i < length; i++) {
UnityAssertFloatsWithin((UNITY_FLOAT)((UNITY_FLOAT)((expectedValue[i])) * (UNITY_FLOAT)(0.00001f)), (UNITY_FLOAT)((UNITY_FLOAT)((expectedValue[i]))), (UNITY_FLOAT)((UNITY_FLOAT)((result[i]))), ((((void*)0))), (UNITY_UINT)((UNITY_UINT)(58)));
}
}

3
build/test/preprocess/includes/test_currentCustomerAccountBalance.c

@ -1,3 +0,0 @@
---
- "/Library/Ruby/Gems/2.6.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h"
- src/currentCustomerAccountBalance.h

4
build/test/preprocess/includes/test_updateCustomerAccountBalance.c

@ -1,3 +1 @@
---
- "/Library/Ruby/Gems/2.6.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h"
- src/updateCustomerAccountBalance.h
--- []

30
build/test/results/test_currentCustomerAccountBalance.pass

@ -1,30 +0,0 @@
---
:source:
:path: tests
:file: test_currentCustomerAccountBalance.c
:successes:
- :test: test_fetchBalanceFromBalanceString
:line: 15
:message: ''
:unity_test_time: 0
- :test: test_checkFileOpen
:line: 52
:message: ''
:unity_test_time: 0
- :test: test_failOpenFile
:line: 63
:message: ''
:unity_test_time: 0
- :test: test_getAvailableAccountBalance
:line: 73
:message: ''
:unity_test_time: 0
:failures: []
:ignores: []
:counts:
:total: 4
:passed: 4
:failed: 0
:ignored: 0
:stdout: []
:time: 0.006680999998934567

14
build/test/results/test_updateCustomerAccountBalance.pass

@ -0,0 +1,14 @@
---
:source:
:path: tests
:file: test_updateCustomerAccountBalance.c
:successes: []
:failures: []
:ignores: []
:counts:
:total: 0
:passed: 0
:failed: 0
:ignored: 0
:stdout: []
:time: 0.006540999980643392

87
build/test/runners/test_currentCustomerAccountBalance_runner.c

@ -1,87 +0,0 @@
/* AUTOGENERATED FILE. DO NOT EDIT. */
/*=======Automagically Detected Files To Include=====*/
#include "unity.h"
int GlobalExpectCount;
int GlobalVerifyOrder;
char* GlobalOrderError;
/*=======External Functions This Runner Calls=====*/
extern void setUp(void);
extern void tearDown(void);
extern void test_fetchBalanceFromBalanceString(void);
extern void test_checkFileOpen(void);
extern void test_failOpenFile(void);
extern void test_getAvailableAccountBalance(void);
/*=======Mock Management=====*/
static void CMock_Init(void)
{
GlobalExpectCount = 0;
GlobalVerifyOrder = 0;
GlobalOrderError = NULL;
}
static void CMock_Verify(void)
{
}
static void CMock_Destroy(void)
{
}
/*=======Test Reset Options=====*/
void resetTest(void);
void resetTest(void)
{
tearDown();
CMock_Verify();
CMock_Destroy();
CMock_Init();
setUp();
}
void verifyTest(void);
void verifyTest(void)
{
CMock_Verify();
}
/*=======Test Runner Used To Run Each Test=====*/
static void run_test(UnityTestFunction func, const char* name, UNITY_LINE_TYPE line_num)
{
Unity.CurrentTestName = name;
Unity.CurrentTestLineNumber = line_num;
#ifdef UNITY_USE_COMMAND_LINE_ARGS
if (!UnityTestMatches())
return;
#endif
Unity.NumberOfTests++;
UNITY_CLR_DETAILS();
UNITY_EXEC_TIME_START();
CMock_Init();
if (TEST_PROTECT())
{
setUp();
func();
}
if (TEST_PROTECT())
{
tearDown();
CMock_Verify();
}
CMock_Destroy();
UNITY_EXEC_TIME_STOP();
UnityConcludeTest();
}
/*=======MAIN=====*/
int main(void)
{
UnityBegin("test_currentCustomerAccountBalance.c");
run_test(test_fetchBalanceFromBalanceString, "test_fetchBalanceFromBalanceString", 15);
run_test(test_checkFileOpen, "test_checkFileOpen", 52);
run_test(test_failOpenFile, "test_failOpenFile", 63);
run_test(test_getAvailableAccountBalance, "test_getAvailableAccountBalance", 73);
return UnityEnd();
}

36
build/test/runners/test_updateCustomerAccountBalance_runner.c

@ -10,7 +10,6 @@ char* GlobalOrderError;
/*=======External Functions This Runner Calls=====*/ /*=======External Functions This Runner Calls=====*/
extern void setUp(void); extern void setUp(void);
extern void tearDown(void); extern void tearDown(void);
extern void test_updateAvailableAccountBalanceSuccess(void);
/*=======Mock Management=====*/ /*=======Mock Management=====*/
@ -27,6 +26,12 @@ static void CMock_Destroy(void)
{ {
} }
/*=======Setup (stub)=====*/
void setUp(void) {}
/*=======Teardown (stub)=====*/
void tearDown(void) {}
/*=======Test Reset Options=====*/ /*=======Test Reset Options=====*/
void resetTest(void); void resetTest(void);
void resetTest(void) void resetTest(void)
@ -43,39 +48,10 @@ void verifyTest(void)
CMock_Verify(); CMock_Verify();
} }
/*=======Test Runner Used To Run Each Test=====*/
static void run_test(UnityTestFunction func, const char* name, UNITY_LINE_TYPE line_num)
{
Unity.CurrentTestName = name;
Unity.CurrentTestLineNumber = line_num;
#ifdef UNITY_USE_COMMAND_LINE_ARGS
if (!UnityTestMatches())
return;
#endif
Unity.NumberOfTests++;
UNITY_CLR_DETAILS();
UNITY_EXEC_TIME_START();
CMock_Init();
if (TEST_PROTECT())
{
setUp();
func();
}
if (TEST_PROTECT())
{
tearDown();
CMock_Verify();
}
CMock_Destroy();
UNITY_EXEC_TIME_STOP();
UnityConcludeTest();
}
/*=======MAIN=====*/ /*=======MAIN=====*/
int main(void) int main(void)
{ {
UnityBegin("test_updateCustomerAccountBalance.c"); UnityBegin("test_updateCustomerAccountBalance.c");
run_test(test_updateAvailableAccountBalanceSuccess, "test_updateAvailableAccountBalanceSuccess", 15);
return UnityEnd(); return UnityEnd();
} }

8
src/updateCustomerAccountBalance.c

@ -33,7 +33,7 @@ void replaceLineInFile(const char* file_name, int line, const char* new_line){
char current_string[100]; char current_string[100];
int current_line = 1; int current_line = 1;
char *temp_file_name = calloc(8+1, sizeof(char)); char *temp_file_name = calloc(8+1, sizeof(char));
temp_file_name = "temp.txt";
temp_file_name = "src/temp.txt";
FILE* temp_file = fopen(temp_file_name, "w"); FILE* temp_file = fopen(temp_file_name, "w");
if (temp_file == NULL) { if (temp_file == NULL) {
troubleShoot(1); troubleShoot(1);
@ -67,7 +67,7 @@ void replaceBalanceInString(float replacementBalance, int currentLine) {
replaceLineInFile(CUSTOMER_DATA_FILE,currentLine,newBalanceLine); replaceLineInFile(CUSTOMER_DATA_FILE,currentLine,newBalanceLine);
} }
bool updateAvailableAccountBalance(int user_id, float newBalance){
float updateAvailableAccountBalance(int user_id, float newBalance){
bool keep_reading = true; bool keep_reading = true;
bool foundCustomer = false; bool foundCustomer = false;
@ -105,9 +105,11 @@ bool updateAvailableAccountBalance(int user_id, float newBalance){
if(foundCustomer){ if(foundCustomer){
replaceBalanceInString(newBalance,currentLine); replaceBalanceInString(newBalance,currentLine);
return newBalance;
}else{ }else{
troubleShoot(4); troubleShoot(4);
return -1;
} }
return true;
} }

2
src/updateCustomerAccountBalance.h

@ -6,6 +6,6 @@
#define MAX_LENGTH 100 #define MAX_LENGTH 100
bool updateAvailableAccountBalance(int user_id, float newBalance);
float updateAvailableAccountBalance(int user_id, float newBalance);
void replaceBalanceInString(float replacementBalance, int currentLine); void replaceBalanceInString(float replacementBalance, int currentLine);

6
tests/test_updateCustomerAccountBalance.c

@ -1,4 +1,4 @@
#ifdef TEST
#ifndef TEST
#include "unity.h" #include "unity.h"
@ -37,7 +37,7 @@ void test_updateAvailableAccountBalanceSuccess(void){
int length = 10; int length = 10;
float amountToUpdate[] = {200.5, 340, 244.5, 340, 1200, 3232, 1123, 460.5, 900, 1005}; float amountToUpdate[] = {200.5, 340, 244.5, 340, 1200, 3232, 1123, 460.5, 900, 1005};
float userIDs[] = {1001,1002,1003,1004,1005,1006,1007,1008,1009};
float userIDs[] = {1001,1002,1003,1004,1005,1006,1007,1008,1009,1010};
float expectedValue[length]; float expectedValue[length];
float result[length]; float result[length];
@ -51,7 +51,7 @@ void test_updateAvailableAccountBalanceSuccess(void){
/* Assert */ /* Assert */
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
expectedValue[i] = 0;
expectedValue[i] = amountToUpdate[i];
} }
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {

Loading…
Cancel
Save