From 83b4f6496ecac263025dce446959d7a492fee700 Mon Sep 17 00:00:00 2001 From: Sandro Welte Date: Thu, 8 Feb 2024 16:55:10 +0100 Subject: [PATCH] added arithmetic Multiplication --- src/arithmeticMultiplication_Int.c | 17 +++++++++++++++++ src/arithmeticMultiplication_Int.h | 8 ++++++++ test/test_arithmeticMultiplication_Int.c | 21 +++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 src/arithmeticMultiplication_Int.c create mode 100644 src/arithmeticMultiplication_Int.h create mode 100644 test/test_arithmeticMultiplication_Int.c diff --git a/src/arithmeticMultiplication_Int.c b/src/arithmeticMultiplication_Int.c new file mode 100644 index 0000000..6fff2ec --- /dev/null +++ b/src/arithmeticMultiplication_Int.c @@ -0,0 +1,17 @@ + + +#include "arithmeticMultiplication_Int.h" +#include + +int* multiplication_integer(int num1, int num2) { + int *result = (int*)malloc(sizeof(int)); + if (result == NULL) { + // Handle memory allocation failure + return NULL; + } + + *result = num1 * num2; + + return result; +} + diff --git a/src/arithmeticMultiplication_Int.h b/src/arithmeticMultiplication_Int.h new file mode 100644 index 0000000..4222d1f --- /dev/null +++ b/src/arithmeticMultiplication_Int.h @@ -0,0 +1,8 @@ + + +#ifndef THEADMIRALS_ARITHMETICMULTIPLICATION_INT_H +#define THEADMIRALS_ARITHMETICMULTIPLICATION_INT_H + +int* multiplication_integer(int, int); + +#endif //THEADMIRALS_ARITHMETICMULTIPLICATION_INT_H diff --git a/test/test_arithmeticMultiplication_Int.c b/test/test_arithmeticMultiplication_Int.c new file mode 100644 index 0000000..b5fb385 --- /dev/null +++ b/test/test_arithmeticMultiplication_Int.c @@ -0,0 +1,21 @@ +#include "../src/arithmeticMultiplication_Int.h" +#include "unity.h" +#include "limits.h" + +void setUp(void) { + // set stuff up here +} + +void tearDown(void) { + // clean stuff up here +} + +void test_arithmeticMultiplication_numbertimesnumberequalsnumber(void) { + int expectedResult = 10; + int* result; + result = multiplication_integer(2,5); + TEST_ASSERT_EQUAL_INT(expectedResult, *result); +} + + +