From ea42bf7367a6bfd44151de14e989a7013795b3da Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 17:39:55 +0100 Subject: [PATCH] Added exponentials including unittest --- src/exponentials.c | 9 +++++++++ src/exponentials.h | 6 ++++++ test/test_exponentials.c | 18 ++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 src/exponentials.c create mode 100644 src/exponentials.h create mode 100644 test/test_exponentials.c diff --git a/src/exponentials.c b/src/exponentials.c new file mode 100644 index 0000000..389997b --- /dev/null +++ b/src/exponentials.c @@ -0,0 +1,9 @@ +#include "exponentials.h" +#include +#include + +double* exponentials_double(int base, int exponent) { + double* result = malloc(sizeof(double)); + *result = pow(base, exponent); + return result; +} \ No newline at end of file diff --git a/src/exponentials.h b/src/exponentials.h new file mode 100644 index 0000000..49ab5b9 --- /dev/null +++ b/src/exponentials.h @@ -0,0 +1,6 @@ +#ifndef THEADMIRALS_EXPONENTIALS_H +#define THEADMIRALS_EXPONENTIALS_H + +double* exponentials_double(int, int); + +#endif //THEADMIRALS_EXPONENTIALS_H diff --git a/test/test_exponentials.c b/test/test_exponentials.c new file mode 100644 index 0000000..6266ac7 --- /dev/null +++ b/test/test_exponentials.c @@ -0,0 +1,18 @@ +#include "../src/exponentials.h" +#include "unity.h" +#include "limits.h" + +void setUp(void) { + // set stuff up here +} + +void tearDown(void) { + // clean stuff up here +} + +void test_exponentials_calculatenumfrombaseandexponent(void) { + double expectedResult = 32.000000; + double* result; + result = exponentials_double(2, 5); + TEST_ASSERT_EQUAL_DOUBLE(expectedResult, *result); +} \ No newline at end of file