From 1df729bb907c4d2b40bad1d04a0fa9a286cbeac9 Mon Sep 17 00:00:00 2001 From: Justin Trausch Date: Tue, 6 Feb 2024 13:13:00 +0100 Subject: [PATCH 01/13] Fakultaet file erstellt --- src/fakultaet.c | 5 +++++ src/fakultaet.h | 8 ++++++++ test/test_fakultaet.c | 15 +++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 src/fakultaet.c create mode 100644 src/fakultaet.h create mode 100644 test/test_fakultaet.c diff --git a/src/fakultaet.c b/src/fakultaet.c new file mode 100644 index 0000000..fe4c1df --- /dev/null +++ b/src/fakultaet.c @@ -0,0 +1,5 @@ +// +// Created by Justin Trausch on 06.02.2024. +// + +#include "fakultaet.h" diff --git a/src/fakultaet.h b/src/fakultaet.h new file mode 100644 index 0000000..d7030dd --- /dev/null +++ b/src/fakultaet.h @@ -0,0 +1,8 @@ +// +// Created by Justin Trausch on 06.02.2024. +// + +#ifndef LINKES_TWIX_FAKULTAET_H +#define LINKES_TWIX_FAKULTAET_H + +#endif //LINKES_TWIX_FAKULTAET_H diff --git a/test/test_fakultaet.c b/test/test_fakultaet.c new file mode 100644 index 0000000..fc0453a --- /dev/null +++ b/test/test_fakultaet.c @@ -0,0 +1,15 @@ +#ifdef TEST + +#include "unity.h" + +#include "fakultaet.h" +#include "fakultaet.h" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} +#endif //TEST \ No newline at end of file From b02582d6cc39b09f2fa4f51ee06df4f170c21949 Mon Sep 17 00:00:00 2001 From: Justin Trausch Date: Tue, 6 Feb 2024 21:21:10 +0100 Subject: [PATCH 02/13] Include headerfile fakultaet --- src/fakultaet.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/fakultaet.c b/src/fakultaet.c index fe4c1df..c626bde 100644 --- a/src/fakultaet.c +++ b/src/fakultaet.c @@ -1,5 +1 @@ -// -// Created by Justin Trausch on 06.02.2024. -// - #include "fakultaet.h" From 93cb247ec2089dc965c869a7eaee59c67c345067 Mon Sep 17 00:00:00 2001 From: Justin Trausch Date: Tue, 6 Feb 2024 21:26:39 +0100 Subject: [PATCH 03/13] Basisstruktur Fakultaet --- src/fakultaet.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/fakultaet.c b/src/fakultaet.c index c626bde..cc583b7 100644 --- a/src/fakultaet.c +++ b/src/fakultaet.c @@ -1 +1,5 @@ #include "fakultaet.h" + +int divisionInt(int a, int b) { + return 0; +} From 271851f28951128a81baacc9f8abbb9533bab293 Mon Sep 17 00:00:00 2001 From: Justin Trausch Date: Tue, 6 Feb 2024 21:33:02 +0100 Subject: [PATCH 04/13] refactoring: Basisstruktur Fakultaet --- src/fakultaet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fakultaet.c b/src/fakultaet.c index cc583b7..1f232bf 100644 --- a/src/fakultaet.c +++ b/src/fakultaet.c @@ -1,5 +1,5 @@ #include "fakultaet.h" -int divisionInt(int a, int b) { +int fakultaetInt(int a, int b) { return 0; } From a821a98cce5158763c0823c8a2ca7fb83c5e68ce Mon Sep 17 00:00:00 2001 From: Justin Trausch Date: Tue, 6 Feb 2024 21:35:11 +0100 Subject: [PATCH 05/13] Basisstruktur Gleitkomma-Fakultaet --- src/fakultaet.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/fakultaet.c b/src/fakultaet.c index 1f232bf..a8485bd 100644 --- a/src/fakultaet.c +++ b/src/fakultaet.c @@ -3,3 +3,6 @@ int fakultaetInt(int a, int b) { return 0; } +double fakultaetDouble(double a, double b) { + return 0; +} From 926228972f98d25fe24d0ab4eb98ec356b53475d Mon Sep 17 00:00:00 2001 From: Justin Trausch Date: Tue, 6 Feb 2024 21:38:49 +0100 Subject: [PATCH 06/13] =?UTF-8?q?Hinzuf=C3=BCgen=20Funktionsdefinition=20H?= =?UTF-8?q?eaderfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fakultaet.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/fakultaet.h b/src/fakultaet.h index d7030dd..21a53b4 100644 --- a/src/fakultaet.h +++ b/src/fakultaet.h @@ -5,4 +5,6 @@ #ifndef LINKES_TWIX_FAKULTAET_H #define LINKES_TWIX_FAKULTAET_H +int fakultaetInt(int a, int b); + #endif //LINKES_TWIX_FAKULTAET_H From 8baf9f43b442d3dd8d225c52ec01301a181cfa5e Mon Sep 17 00:00:00 2001 From: Justin Trausch Date: Tue, 6 Feb 2024 21:40:19 +0100 Subject: [PATCH 07/13] =?UTF-8?q?Hinzuf=C3=BCgen=20Funktionsdefinition=20H?= =?UTF-8?q?eaderfile=20Double?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fakultaet.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/fakultaet.h b/src/fakultaet.h index 21a53b4..c7f6460 100644 --- a/src/fakultaet.h +++ b/src/fakultaet.h @@ -7,4 +7,7 @@ int fakultaetInt(int a, int b); +double fakultaetDouble(double a, double b); + + #endif //LINKES_TWIX_FAKULTAET_H From 8a9258e0056177611e0217f9aa6831ec0e63ca3b Mon Sep 17 00:00:00 2001 From: Justin Trausch Date: Wed, 7 Feb 2024 20:20:53 +0100 Subject: [PATCH 08/13] =?UTF-8?q?refactoring:=20Variable=20=C3=A4ndern=20v?= =?UTF-8?q?on=20Int=20Fakultaet=20und=20Double=20Fakultaet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fakultaet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fakultaet.c b/src/fakultaet.c index a8485bd..2e81e16 100644 --- a/src/fakultaet.c +++ b/src/fakultaet.c @@ -1,8 +1,8 @@ #include "fakultaet.h" -int fakultaetInt(int a, int b) { +int berechneFakultaetInt(int zahl) { return 0; } -double fakultaetDouble(double a, double b) { +double berechneFakultaetDouble(double a, double b) { return 0; } From ec6a0686f9ed7b44726d0011535a80bcda875e11 Mon Sep 17 00:00:00 2001 From: Justin Trausch Date: Wed, 7 Feb 2024 20:31:43 +0100 Subject: [PATCH 09/13] Fakultaet Int Funktion implementiert --- src/fakultaet.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/fakultaet.c b/src/fakultaet.c index 2e81e16..e057620 100644 --- a/src/fakultaet.c +++ b/src/fakultaet.c @@ -1,8 +1,17 @@ #include "fakultaet.h" int berechneFakultaetInt(int zahl) { - return 0; + if (zahl == 0 || zahl == 1) { + return 1; + } else { + int fakultaet = 1; + for (int i = 2; i <= zahl; ++i) { + fakultaet *= i; + } + return fakultaet; + } } + double berechneFakultaetDouble(double a, double b) { return 0; } From 711bb63cf4225c0121f950401550604f0285182e Mon Sep 17 00:00:00 2001 From: Justin Trausch Date: Wed, 7 Feb 2024 20:34:06 +0100 Subject: [PATCH 10/13] Fakultaet Double Funktion implementiert --- src/fakultaet.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/fakultaet.c b/src/fakultaet.c index e057620..46d9f0f 100644 --- a/src/fakultaet.c +++ b/src/fakultaet.c @@ -12,6 +12,14 @@ int berechneFakultaetInt(int zahl) { } } -double berechneFakultaetDouble(double a, double b) { - return 0; +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; + } } From b8993e3f0458fa7b54a042924b9bf48813da1aba Mon Sep 17 00:00:00 2001 From: Justin Trausch Date: Wed, 7 Feb 2024 20:40:07 +0100 Subject: [PATCH 11/13] refactoring: fakulaet.c file zu test included --- test/test_fakultaet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fakultaet.c b/test/test_fakultaet.c index fc0453a..2e30f14 100644 --- a/test/test_fakultaet.c +++ b/test/test_fakultaet.c @@ -3,7 +3,7 @@ #include "unity.h" #include "fakultaet.h" -#include "fakultaet.h" +#include "fakultaet.c" void setUp(void) { From 9cba867ba50069c788e7c897c52e2db5ca5ecd8f Mon Sep 17 00:00:00 2001 From: Justin Trausch Date: Wed, 7 Feb 2024 20:44:12 +0100 Subject: [PATCH 12/13] test_fakultaet_1 Fakultaet von 4 = 24 --- test/test_fakultaet.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/test_fakultaet.c b/test/test_fakultaet.c index 2e30f14..37bb5c4 100644 --- a/test/test_fakultaet.c +++ b/test/test_fakultaet.c @@ -12,4 +12,13 @@ void setUp(void) void tearDown(void) { } + +void test_fakultaet_1(void) +{ + int result, expected = 24; + + result = berechneFakultaetInt(4); + + TEST_ASSERT_EQUAL_INT(expected, result); +} #endif //TEST \ No newline at end of file From cc3cf57441e6ee9ee78a761581c862b29429727c Mon Sep 17 00:00:00 2001 From: Justin Trausch Date: Wed, 7 Feb 2024 20:53:24 +0100 Subject: [PATCH 13/13] test_fakultaet_2 Fakultaet_Double von 4.0 = 24.0 --- test/test_fakultaet.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/test_fakultaet.c b/test/test_fakultaet.c index 37bb5c4..7db2fd4 100644 --- a/test/test_fakultaet.c +++ b/test/test_fakultaet.c @@ -21,4 +21,13 @@ void test_fakultaet_1(void) 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