diff --git a/src/arithmeticAddition.c b/src/arithmeticAddition.c new file mode 100644 index 0000000..d75b63f --- /dev/null +++ b/src/arithmeticAddition.c @@ -0,0 +1,13 @@ +#include "arithmeticAddition.h" +#include +#include +#include + +int* addition_integer(int num1, int num2) { + if ((num2 > 0 && num1 > INT_MAX - num2) || (num2 < 0 && num1 < INT_MIN - num2)) { + return NULL; + } + int* result = malloc(sizeof(int)); + *result = num1 + num2; + return result; +} \ No newline at end of file diff --git a/src/arithmeticAddition.h b/src/arithmeticAddition.h new file mode 100644 index 0000000..92907ff --- /dev/null +++ b/src/arithmeticAddition.h @@ -0,0 +1,6 @@ +#ifndef THEADMIRALS_ARITHMETICADDITION_H +#define THEADMIRALS_ARITHMETICADDITION_H + +int* addition_integer(int, int); + +#endif //THEADMIRALS_ARITHMETICADDITION_H diff --git a/test/test_arithmeticAddition.c b/test/test_arithmeticAddition.c new file mode 100644 index 0000000..a7089a6 --- /dev/null +++ b/test/test_arithmeticAddition.c @@ -0,0 +1,24 @@ +#include "../src/arithmeticAddition.h" +#include "unity.h" +#include "limits.h" + +void setUp(void) { + // set stuff up here +} + +void tearDown(void) { + // clean stuff up here +} + +void test_arithmeticAddition_numberplusnumberequalsnumber(void) { + int expectedResult = 8; + int* result; + result = addition_integer(5, 3); + TEST_ASSERT_EQUAL_INT(expectedResult, *result); +} + +void test_arithmeticAddition_numberplusmaxintegervalueequalsnull(void) { + int* result; + result = addition_integer(INT_MAX, 1); + TEST_ASSERT_NULL(result); +} \ No newline at end of file