diff --git a/src/division/.gitkeep b/src/division/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/division/division.c b/src/division/division.c new file mode 100644 index 0000000..e0765f6 --- /dev/null +++ b/src/division/division.c @@ -0,0 +1,10 @@ +#include "division.h" + +float divide(float dividend, float divisor) { + if (divisor == 0) { + return 0; // Fehlerbehandlung: Division durch Null ist nicht definiert, daher geben wir einfach 0 zurück. + } + if (dividend == 0) return 0; + else if(dividend==divisor) return 1; + else return dividend / divisor; +} diff --git a/src/division/division.h b/src/division/division.h new file mode 100644 index 0000000..bce87a4 --- /dev/null +++ b/src/division/division.h @@ -0,0 +1,7 @@ +#ifndef division_H +#define division_H + +int divide(float dividend, float divisor); + +#endif + diff --git a/test/division/.gitkeep b/test/division/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/test/division/test_division.c b/test/division/test_division.c new file mode 100644 index 0000000..0864f9e --- /dev/null +++ b/test/division/test_division.c @@ -0,0 +1,10 @@ +#include "unity.h" +#include "division.h" +void setUp(void){} +void tearDown(void){} +void test_division() { + TEST_ASSERT_EQUAL_FLOAT(2.0f, divide(6.0f, 3.0f)); + TEST_ASSERT_EQUAL_FLOAT(-2.0f, divide(6.0f, -3.0f)); + TEST_ASSERT_EQUAL_FLOAT(0.0f, divide(0.0f, 5.0f)); + TEST_ASSERT_EQUAL_FLOAT(0.0f, divide(5.0f, 0.0f)); // Test für Division durch Null +}