diff --git a/src/arithmeticAddition.c b/src/arithmeticAddition.c index 173c438..46a2e37 100644 --- a/src/arithmeticAddition.c +++ b/src/arithmeticAddition.c @@ -3,6 +3,7 @@ #include #include +// addition for two integer inputs (no decimal number) int* addition_integer(int num1, int num2) { if ((num2 > 0 && num1 > INT_MAX - num2) || (num2 < 0 && num1 < INT_MIN - num2)) { return NULL; @@ -12,18 +13,21 @@ int* addition_integer(int num1, int num2) { return result; } +// addition for two double inputs (decimal number) double* addition_double(double num1, double num2) { double* result = malloc(sizeof(double)); *result = num1+num2; return result; } +// addition for two float inputs (decimal number) float* addition_float(float num1, float num2) { float* result = malloc(sizeof(float)); *result = num1+num2; return result; } +// addition for two long inputs (no decimal number) long* addition_long(long num1, long num2) { long* result = malloc(sizeof(long)); *result = num1+num2; diff --git a/src/arithmeticSubtraction.c b/src/arithmeticSubtraction.c index bbabad9..339431b 100644 --- a/src/arithmeticSubtraction.c +++ b/src/arithmeticSubtraction.c @@ -2,21 +2,21 @@ #include -// arithmetic subtraction integer +// arithmetic subtraction for integer int* subtraction_integer(int a, int b) { int* result= malloc(sizeof (int)); *result=a - b; return result; } -// arithmetic subtraction float +// arithmetic subtraction for float float* subtraction_float(float a, float b) { float* result= malloc(sizeof (float)); *result=a - b; return result; } -// arithmetic subtraction double +// arithmetic subtraction for double double* subtraction_double(double a, double b) { double* result= malloc(sizeof (double)); *result=a - b; diff --git a/src/convert_M_in_KM.c b/src/convert_M_in_KM.c index bf56016..4980a96 100644 --- a/src/convert_M_in_KM.c +++ b/src/convert_M_in_KM.c @@ -1,6 +1,6 @@ #include "convert_M_in_KM.h" -// convert length for double metre into kilometre +//convert length for double metre into kilometre double meter_to_kilometer(double meter) { return meter / 1000.0; } diff --git a/src/convert_kg_to_ton.h b/src/convert_kg_to_ton.h index cc38ea6..032dc7f 100644 --- a/src/convert_kg_to_ton.h +++ b/src/convert_kg_to_ton.h @@ -1,19 +1,7 @@ - #ifndef THEADMIRALS_CONVERT_KG_TO_TON_H #define THEADMIRALS_CONVERT_KG_TO_TON_H - - - // Convert kilograms to tons -// Parameters: -// kilograms: weight in kilograms -// Returns: -// The equivalent weight in tons - double kg_to_tons(double kilograms); - - - #endif //THEADMIRALS_CONVERT_KG_TO_TON_H diff --git a/src/convert_time.c b/src/convert_time.c index 2114697..40a9403 100644 --- a/src/convert_time.c +++ b/src/convert_time.c @@ -14,32 +14,32 @@ double converter_min_to_sec(double min){ // Converts Hours to Minutes double converter_hour_to_min(double hour){ - double time = hour * 60; - return time; + double min = hour * 60; + return min; } // Converts Minutes To Hours double converter_min_to_hour(double min){ - double time = min / 60; - return time; + double hours = min / 60; + return hours; } // Converts Hours in Seconds double converter_hour_in_sec(double hour){ - double time = hour * 60 * 60; - return time; + double secs = hour * 60 * 60; + return secs; } // Converts Seconds in Hours double converter_sec_in_hour(double sec){ - double time = sec / 60 / 60; - return time; + double hours = sec / 60 / 60; + return hours; } // Converts Days in Years double converter_days_to_years(double days){ - double time = days / 365; - return time; + double years = days / 365; + return years; } // convert Years in days diff --git a/src/trigonometricFunctions.c b/src/trigonometricFunctions.c index 6dbdfaf..db262a0 100644 --- a/src/trigonometricFunctions.c +++ b/src/trigonometricFunctions.c @@ -4,21 +4,19 @@ #include #include //function for trigonometric -//Function 1 double +//Function 1 for double double* calculate_sin_double(double angle) { double* result= malloc(sizeof (double)); *result=sin(angle); return result; } -//Function 2 double - +//Function 2 for double double* calculate_cos_double(double angle) { double* result= malloc(sizeof (double)); *result=cos(angle); return result; } -//Function 3 double - +//Function 3 for double double* calculate_tan_double(double angle) { double* result= malloc(sizeof (double)); *result=tan(angle); diff --git a/test/test_arithmeticAddition.c b/test/test_arithmeticAddition.c index a7089a6..5e261b2 100644 --- a/test/test_arithmeticAddition.c +++ b/test/test_arithmeticAddition.c @@ -21,4 +21,25 @@ void test_arithmeticAddition_numberplusmaxintegervalueequalsnull(void) { int* result; result = addition_integer(INT_MAX, 1); TEST_ASSERT_NULL(result); -} \ No newline at end of file +} + +void test_arithmeticAddition_doublenumbercalculationequalscorrectdoublenumber(void) { + double expectedResult = 5.500000; + double* result; + result = addition_double(3.5, 2.0); + TEST_ASSERT_EQUAL_DOUBLE(expectedResult, *result); +} + +void test_arithmeticAddition_longnumbercalculationequalscorrectlong(void) { + long expectedResult = 10; + long* result; + result = addition_long(5, 5); + TEST_ASSERT_EQUAL_INT(expectedResult, *result); +} + +void test_arithmeticAddition_floatnumbercalculationequalsfloat(void) { + float expectedResult = 5.5; + float* result; + result = addition_float(3.5, 2.0); + TEST_ASSERT_EQUAL_FLOAT(expectedResult, *result); +} diff --git a/test/test_arithmeticDivision.c b/test/test_arithmeticDivision.c index 6428ea0..0ae60eb 100644 --- a/test/test_arithmeticDivision.c +++ b/test/test_arithmeticDivision.c @@ -17,3 +17,24 @@ void test_arithmeticDivision_numberdividedbynumberequalsnumber(void) { result = division_integer(14, 7); TEST_ASSERT_EQUAL_INT(expectedResult, *result); } + +void test_arithmeticDivision_longdividedbylongequalscorrectlong(void) { + long expectedResult = 5; + long* result; + result = division_long(10, 2); + TEST_ASSERT_EQUAL_INT(expectedResult, *result); +} + +void test_arithmeticDivsion_floatdividedbyfloatequalscorrectfloat(void) { + float expectedResult = 5.0; + float* result; + result = division_float(10.0, 2.0); + TEST_ASSERT_EQUAL_FLOAT(expectedResult, *result); +} + +void test_arithmeticDivision_doubledividedbydoublequalscorrectdouble(void) { + double expectedResult = 5.0; + double* result; + result = division_double(10.0, 2.0); + TEST_ASSERT_EQUAL_DOUBLE(expectedResult, *result); +} diff --git a/test/test_inputHandler.c b/test/test_inputHandler.c new file mode 100644 index 0000000..4b4f874 --- /dev/null +++ b/test/test_inputHandler.c @@ -0,0 +1,39 @@ +#include "../src/inputHandler.h" +#include "unity.h" + +void setUp(void) { + // set stuff up here +} + +void tearDown(void) { + // clean stuff up here +} + + +void test_inputHandler_returntwoforinputminus(void) { + int expectedResult = 2; + int result; + result = getOperationIdBySymbol('-'); + TEST_ASSERT_EQUAL_INT(expectedResult, result); +} + +void test_inputHandler_returnoneforinputplus(void) { + int expectedResult = 1; + int result; + result = getOperationIdBySymbol('+'); + TEST_ASSERT_EQUAL_INT(expectedResult, result); +} + +void test_inputHandler_returnzeroforinvalidinput(void) { + int expectedResult = 0; + int result; + result = isOperationIdValid(0); + TEST_ASSERT_EQUAL_INT(expectedResult, result); +} + +void test_inputHandler_returnoneifinputtoobig(void) { + int expectedResult = 1; + int result; + result = isNumberTooBig(300); + TEST_ASSERT_EQUAL_INT(expectedResult, result); +} \ No newline at end of file