From fe311209d79b30b4882ae3856b1574aaf4ff13e7 Mon Sep 17 00:00:00 2001 From: fdai7057 Date: Sat, 4 Feb 2023 18:50:40 +0100 Subject: [PATCH] refactoring: rename stod to balanceToDouble and its internal variable. The purpose of this function is to convert the user input for the account balance into a double and the new names states this purpose better. --- src/helperFunctions.c | 16 ++++++++-------- src/helperFunctions.h | 3 ++- test/test_helperFunctions.c | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/helperFunctions.c b/src/helperFunctions.c index 28ec136..3b0fde0 100644 --- a/src/helperFunctions.c +++ b/src/helperFunctions.c @@ -117,22 +117,22 @@ char *generateCheckString(unsigned int customerID, char *customerPassword) return checkString; } -double stod(char *s) +double balanceToDouble(char *balanceAsString) { double result, power; int i=0, sign; - sign = (*(s) == '-') ? -1 : 1; - if(*(s)=='+'||*(s)=='-'){ + sign = (*(balanceAsString) == '-') ? -1 : 1; + if(*(balanceAsString)=='+'||*(balanceAsString)=='-'){ ++i; } - for(result = 0.0; *(s+i)!='.';++i){ - result = 10.0 * result + (*(s+i) - '0'); + for(result = 0.0; *(balanceAsString+i)!='.';++i){ + result = 10.0 * result + (*(balanceAsString+i) - '0'); } - if(*(s+i)=='.'){ + if(*(balanceAsString+i)=='.'){ ++i; } - for(power = 1.0;*(s+i)!='\0';++i){ - result = 10.0 * result + (*(s+i)- '0'); + for(power = 1.0;*(balanceAsString+i)!='\0';++i){ + result = 10.0 * result + (*(balanceAsString+i)- '0'); power *= 10.0; } return sign * result / power; diff --git a/src/helperFunctions.h b/src/helperFunctions.h index ef5383b..9656ab7 100644 --- a/src/helperFunctions.h +++ b/src/helperFunctions.h @@ -4,6 +4,7 @@ #include #include #include +#define UNITY_INCLUDE_CONFIG_H char *stringConcatenation(char *, char *); char *to_string(int); char *generateCheckString(unsigned int, char *); @@ -11,5 +12,5 @@ unsigned int toUnsignedInteger(char *); unsigned int power(unsigned int, unsigned int); bool everyCharacterIsDigit(char *); bool isLetterOfAlphabet(char *); -double stod(char *); +double balanceToDouble(char *); #endif diff --git a/test/test_helperFunctions.c b/test/test_helperFunctions.c index 57157b8..9287351 100644 --- a/test/test_helperFunctions.c +++ b/test/test_helperFunctions.c @@ -2,9 +2,9 @@ #include #include #include +#include "unity_config.h" #include "../src/helperFunctions.c" - void test_isLetterOfAlphabet() { /*test block 1*/