From 28465715bac5b4e7e9962d57edb08be22c7a6e1f Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Thu, 8 Feb 2024 15:39:29 +0000 Subject: [PATCH 01/10] Add new division directory --- src/division/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/division/.gitkeep diff --git a/src/division/.gitkeep b/src/division/.gitkeep new file mode 100644 index 0000000..e69de29 From bd099730794b2f37033b78bfa43674da4ca1ecca Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Thu, 8 Feb 2024 15:41:47 +0000 Subject: [PATCH 02/10] Add new division.c file --- src/division/division.c | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/division/division.c diff --git a/src/division/division.c b/src/division/division.c new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/division/division.c @@ -0,0 +1 @@ + From 1ad792bd014afd7cb5c3451a1a83b52cd25aba10 Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Thu, 8 Feb 2024 15:42:42 +0000 Subject: [PATCH 03/10] Update src/division/division.c --- src/division/division.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/division/division.c b/src/division/division.c index 8b13789..ee1e7cf 100644 --- a/src/division/division.c +++ b/src/division/division.c @@ -1 +1,8 @@ +#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. + } + return dividend / divisor; +} From 2daf8ea94fdc33286c00065e1eff60cb1037b238 Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Thu, 8 Feb 2024 15:43:28 +0000 Subject: [PATCH 04/10] Add new division.h file --- src/division/division.h | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/division/division.h diff --git a/src/division/division.h b/src/division/division.h new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/division/division.h @@ -0,0 +1 @@ + From 0d697c972fb1e7a073796c97eff6a5d8fff3997e Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Thu, 8 Feb 2024 15:48:25 +0000 Subject: [PATCH 05/10] Update src/division/division.h --- src/division/division.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/division/division.h b/src/division/division.h index 8b13789..bce87a4 100644 --- a/src/division/division.h +++ b/src/division/division.h @@ -1 +1,7 @@ +#ifndef division_H +#define division_H + +int divide(float dividend, float divisor); + +#endif From 211fd9945a6fdb82660c2daaf7dbd02f5237f9ea Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Thu, 8 Feb 2024 15:57:26 +0000 Subject: [PATCH 06/10] Add new division test directory --- test/division/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/division/.gitkeep diff --git a/test/division/.gitkeep b/test/division/.gitkeep new file mode 100644 index 0000000..e69de29 From c78a58c7befb3caae00dc34ae10c115db7b74d02 Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Thu, 8 Feb 2024 15:58:19 +0000 Subject: [PATCH 07/10] Add new test for division file --- test/division/test_division.c | 1 + 1 file changed, 1 insertion(+) create mode 100644 test/division/test_division.c diff --git a/test/division/test_division.c b/test/division/test_division.c new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/test/division/test_division.c @@ -0,0 +1 @@ + From 2ae9a6fd657792a2fd1044fcfd6e9a40e2b8303b Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Thu, 8 Feb 2024 16:18:45 +0000 Subject: [PATCH 08/10] Update test/division/test_division.c --- test/division/test_division.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/division/test_division.c b/test/division/test_division.c index 8b13789..0864f9e 100644 --- a/test/division/test_division.c +++ b/test/division/test_division.c @@ -1 +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 +} From 9ea7adab37a901057cbe44a3f4833d4ebf39bbab Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Thu, 8 Feb 2024 16:20:42 +0000 Subject: [PATCH 09/10] refactoring: if dividend is 0 return 0 without calculation --- src/division/division.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/division/division.c b/src/division/division.c index ee1e7cf..7cf98ef 100644 --- a/src/division/division.c +++ b/src/division/division.c @@ -4,5 +4,6 @@ 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. } - return dividend / divisor; + if (dividend == 0) return 0; + else return dividend / divisor; } From d6758cbe13bdc0dc807d27f37198bc082e98998b Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Thu, 8 Feb 2024 16:25:48 +0000 Subject: [PATCH 10/10] refactoring: if divident and divisor is the same return 1 --- src/division/division.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/division/division.c b/src/division/division.c index 7cf98ef..e0765f6 100644 --- a/src/division/division.c +++ b/src/division/division.c @@ -5,5 +5,6 @@ float divide(float dividend, float divisor) { 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; }