diff --git a/src/arithmeticDivision.c b/src/arithmeticDivision.c new file mode 100644 index 0000000..7cdfc7e --- /dev/null +++ b/src/arithmeticDivision.c @@ -0,0 +1,17 @@ +#include "arithmeticDivision.h" +#include +#include +#include + +int* division_integer(int dividend, int divisor) { + if(divisor == 0) { + return NULL; + } + // Overflow protection + if (dividend == INT_MIN && divisor == -1) { + return NULL; + } + int* result = malloc(sizeof(int)); + *result = dividend / divisor; + return result; +} \ No newline at end of file diff --git a/src/arithmeticDivision.h b/src/arithmeticDivision.h new file mode 100644 index 0000000..e4080b7 --- /dev/null +++ b/src/arithmeticDivision.h @@ -0,0 +1,6 @@ +#ifndef THEADMIRALS_ARITHMETICDIVISION_H +#define THEADMIRALS_ARITHMETICDIVISION_H + +int* division_integer(int, int); + +#endif //THEADMIRALS_ARITHMETICDIVISION_H diff --git a/src/arithmeticSubtraction.c b/src/arithmeticSubtraction.c new file mode 100644 index 0000000..f8a7eb5 --- /dev/null +++ b/src/arithmeticSubtraction.c @@ -0,0 +1,10 @@ + +#include "arithmeticSubtraction.h" + +#include + +int* subtraction_integer(int a, int b) { + int* result= malloc(sizeof (int)); + *result=a - b; + return result; +} diff --git a/src/arithmeticSubtraction.h b/src/arithmeticSubtraction.h new file mode 100644 index 0000000..5a36ba5 --- /dev/null +++ b/src/arithmeticSubtraction.h @@ -0,0 +1,7 @@ + +#ifndef THEADMIRALS_ARITHMETICSUBTRACTION_H +#define THEADMIRALS_ARITHMETICSUBTRACTION_H + +int* subtraction_integer(int a, int b); + +#endif //THEADMIRALS_ARITHMETICSUBTRACTION_H 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/team.md b/team.md index 9389aab..317f693 100644 --- a/team.md +++ b/team.md @@ -1,3 +1,4 @@ - Eric Bagus, fdai7812 - Leon Wolf, fdai7845 -- Sandro Welte, fdai7728 \ No newline at end of file +- Sandro Welte, fdai7728 +- Jonas Zitzmann, fdai7791 \ No newline at end of file diff --git a/test/test_arithmeticDivision.c b/test/test_arithmeticDivision.c new file mode 100644 index 0000000..6428ea0 --- /dev/null +++ b/test/test_arithmeticDivision.c @@ -0,0 +1,19 @@ +#include "../src/arithmeticDivision.h" +#include "unity.h" +#include "limits.h" + +void setUp(void) { + // set stuff up here +} + +void tearDown(void) { + // clean stuff up here +} + + +void test_arithmeticDivision_numberdividedbynumberequalsnumber(void) { + int expectedResult = 2; + int* result; + result = division_integer(14, 7); + TEST_ASSERT_EQUAL_INT(expectedResult, *result); +} diff --git a/test/test_arithmeticSubtraction.c b/test/test_arithmeticSubtraction.c new file mode 100644 index 0000000..26d05c4 --- /dev/null +++ b/test/test_arithmeticSubtraction.c @@ -0,0 +1,18 @@ +#include "../src/arithmeticSubtraction.h" +#include "unity.h" +#include "limits.h" + +void setUp(void) { + // set stuff up here +} + +void tearDown(void) { + // clean stuff up here +} +void test_arithmeticSubtraction_subractionoftwonumbers(void) { + int expectedResult = 7; + int* result; + result = subtraction_integer(14, 7); + TEST_ASSERT_EQUAL_INT(expectedResult, *result); +} + 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