diff --git a/src/logarithmicFunctions.c b/src/logarithmicFunctions.c new file mode 100644 index 0000000..e940cb5 --- /dev/null +++ b/src/logarithmicFunctions.c @@ -0,0 +1,18 @@ +#include "logarithmicFunctions.h" +#include +#include +#include + +double* logarithm_two_integer(int base, int num){ + if(base <= 1 || num <= 0){ + return NULL; + } + + double* result = (double*)malloc(sizeof(double)); + if (result == NULL) { + return NULL; + } + + *result = log(num) / log(base); + return result; +} diff --git a/src/logarithmicFunctions.h b/src/logarithmicFunctions.h new file mode 100644 index 0000000..c13f29d --- /dev/null +++ b/src/logarithmicFunctions.h @@ -0,0 +1,6 @@ +#ifndef THEADMIRALS_LOGARITHMICFUNCTIONS_H +#define THEADMIRALS_LOGARITHMICFUNCTIONS_H + +double* logarithm_two_integer(int base, int num); + +#endif //THEADMIRALS_LOGARITHMICFUNCTIONS_H diff --git a/test/test_logarithmicFunctions.c b/test/test_logarithmicFunctions.c new file mode 100644 index 0000000..512696e --- /dev/null +++ b/test/test_logarithmicFunctions.c @@ -0,0 +1,18 @@ +#include "../src/logarithmicFunctions.h" +#include "unity.h" +#include "limits.h" + +void setUp(void) { + // set stuff up here +} + +void tearDown(void) { + // clean stuff up here +} + +void test_logarithmicFunctions_logarithmiccalculation(void){ + double expectedResult = 3.000000; + double* result; + result = logarithm_two_integer(2,8); + TEST_ASSERT_EQUAL_DOUBLE(expectedResult, *result); +} \ No newline at end of file