Browse Source

Added arithmetic division including unittest

remotes/origin/develop
Eric Bagus 11 months ago
parent
commit
84196e721e
  1. 17
      src/arithmeticDivision.c
  2. 6
      src/arithmeticDivision.h
  3. 19
      test/test_arithmeticDivision.c

17
src/arithmeticDivision.c

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

6
src/arithmeticDivision.h

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

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