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/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); +}