Browse Source

Added arithmetic addition including unittest

remotes/origin/develop
Eric Bagus 11 months ago
parent
commit
fccee6873c
  1. 13
      src/arithmeticAddition.c
  2. 6
      src/arithmeticAddition.h
  3. 24
      test/test_arithmeticAddition.c

13
src/arithmeticAddition.c

@ -0,0 +1,13 @@
#include "arithmeticAddition.h"
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
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;
}

6
src/arithmeticAddition.h

@ -0,0 +1,6 @@
#ifndef THEADMIRALS_ARITHMETICADDITION_H
#define THEADMIRALS_ARITHMETICADDITION_H
int* addition_integer(int, int);
#endif //THEADMIRALS_ARITHMETICADDITION_H

24
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);
}
Loading…
Cancel
Save