diff --git a/src/fakultaet.c b/src/fakultaet.c new file mode 100644 index 0000000..46d9f0f --- /dev/null +++ b/src/fakultaet.c @@ -0,0 +1,25 @@ +#include "fakultaet.h" + +int berechneFakultaetInt(int zahl) { + if (zahl == 0 || zahl == 1) { + return 1; + } else { + int fakultaet = 1; + for (int i = 2; i <= zahl; ++i) { + fakultaet *= i; + } + return fakultaet; + } +} + +int berechneFakultaetDouble(double zahl) { + if (zahl == 0 || zahl == 1) { + return 1; + } else { + double fakultaet = 1; + for (double i = 2; i <= zahl; ++i) { + fakultaet *= i; + } + return fakultaet; + } +} diff --git a/src/fakultaet.h b/src/fakultaet.h new file mode 100644 index 0000000..c7f6460 --- /dev/null +++ b/src/fakultaet.h @@ -0,0 +1,13 @@ +// +// Created by Justin Trausch on 06.02.2024. +// + +#ifndef LINKES_TWIX_FAKULTAET_H +#define LINKES_TWIX_FAKULTAET_H + +int fakultaetInt(int a, int b); + +double fakultaetDouble(double a, double b); + + +#endif //LINKES_TWIX_FAKULTAET_H diff --git a/test/test_fakultaet.c b/test/test_fakultaet.c new file mode 100644 index 0000000..7db2fd4 --- /dev/null +++ b/test/test_fakultaet.c @@ -0,0 +1,33 @@ +#ifdef TEST + +#include "unity.h" + +#include "fakultaet.h" +#include "fakultaet.c" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_fakultaet_1(void) +{ + int result, expected = 24; + + result = berechneFakultaetInt(4); + + TEST_ASSERT_EQUAL_INT(expected, result); +} + +void test_fakultaet_2(void) +{ + double result, expected = 24.0; + + result = berechneFakultaetInt(4.0); + + TEST_ASSERT_EQUAL_DOUBLE(expected, result); +} +#endif //TEST \ No newline at end of file