From 16c7498c3ac0d742d04db02ecece73b74b03604b Mon Sep 17 00:00:00 2001 From: Hendrik Sitzmann Date: Thu, 8 Feb 2024 11:53:13 +0100 Subject: [PATCH 01/15] added primzahl and primzahl.c --- src/primzahl/primzahl.c | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/primzahl/primzahl.c diff --git a/src/primzahl/primzahl.c b/src/primzahl/primzahl.c new file mode 100644 index 0000000..e69de29 From 763a29f6aac8951db18659738dca7782ac4f3010 Mon Sep 17 00:00:00 2001 From: Hendrik Sitzmann Date: Thu, 8 Feb 2024 12:05:26 +0100 Subject: [PATCH 02/15] added function to primzahl.c --- src/primzahl/primzahl.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/primzahl/primzahl.c b/src/primzahl/primzahl.c index e69de29..1d74d73 100644 --- a/src/primzahl/primzahl.c +++ b/src/primzahl/primzahl.c @@ -0,0 +1,13 @@ +#include +#include + +bool primzahl(int num) { + if (num <= 1) + return false; + + for (int i = 2; i < num; i++) { + if (num % i == 0) + return false; + } + return true; +} \ No newline at end of file From fdc93983b5e1b1dd1e60d35b65fe5ad1a8750ae0 Mon Sep 17 00:00:00 2001 From: Hendrik Sitzmann Date: Thu, 8 Feb 2024 12:09:57 +0100 Subject: [PATCH 03/15] refactoring: added comments --- src/primzahl/primzahl.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/primzahl/primzahl.c b/src/primzahl/primzahl.c index 1d74d73..a4b805d 100644 --- a/src/primzahl/primzahl.c +++ b/src/primzahl/primzahl.c @@ -2,12 +2,15 @@ #include bool primzahl(int num) { + //for the case zero or one if (num <= 1) return false; + //checking if there are any other divider for (int i = 2; i < num; i++) { if (num % i == 0) return false; } + //if none were found return true return true; } \ No newline at end of file From 71973511d839bf3a6e5821a4d4b86af6ec4dfb18 Mon Sep 17 00:00:00 2001 From: Hendrik Sitzmann Date: Thu, 8 Feb 2024 12:17:33 +0100 Subject: [PATCH 04/15] added primzahl.h --- src/primzahl/primzahl.h | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/primzahl/primzahl.h diff --git a/src/primzahl/primzahl.h b/src/primzahl/primzahl.h new file mode 100644 index 0000000..2d98817 --- /dev/null +++ b/src/primzahl/primzahl.h @@ -0,0 +1,6 @@ +#ifndef PRIMZAHL_H +#define PRIMZAHL_H + +bool primzahl(int num); + +#endif \ No newline at end of file From 06ea87116c6b93cf5f2ce446390ba941b471f6f4 Mon Sep 17 00:00:00 2001 From: Hendrik Sitzmann Date: Thu, 8 Feb 2024 12:20:31 +0100 Subject: [PATCH 05/15] added main.c --- src/primzahl/main.c | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/primzahl/main.c diff --git a/src/primzahl/main.c b/src/primzahl/main.c new file mode 100644 index 0000000..09c56a3 --- /dev/null +++ b/src/primzahl/main.c @@ -0,0 +1,5 @@ +int main() { + + + return 0; +} \ No newline at end of file From a99b22464599621c68f83f22a55a8d9897a2f653 Mon Sep 17 00:00:00 2001 From: Hendrik Sitzmann Date: Thu, 8 Feb 2024 12:28:33 +0100 Subject: [PATCH 06/15] included header files --- src/primzahl/main.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/primzahl/main.c b/src/primzahl/main.c index 09c56a3..61718d8 100644 --- a/src/primzahl/main.c +++ b/src/primzahl/main.c @@ -1,3 +1,8 @@ +#include "primzahl.h" +#include "../userinput.h" +#include +#include + int main() { From 2d9b1419a64d5b4a90fd9353c8d13acce5e7220a Mon Sep 17 00:00:00 2001 From: Hendrik Sitzmann Date: Thu, 8 Feb 2024 18:35:53 +0100 Subject: [PATCH 07/15] get user input from main --- src/primzahl/main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/primzahl/main.c b/src/primzahl/main.c index 61718d8..555fd74 100644 --- a/src/primzahl/main.c +++ b/src/primzahl/main.c @@ -4,7 +4,9 @@ #include int main() { + int minInput = 0; + int num = usergetd("Enter a positive number: ", minInput, NULL); - return 0; + return 0; } \ No newline at end of file From 0c9d284fc777cb3797314555cb9eb4f0cf2fca4e Mon Sep 17 00:00:00 2001 From: Hendrik Sitzmann Date: Thu, 8 Feb 2024 18:38:12 +0100 Subject: [PATCH 08/15] added function --- src/primzahl/main.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/primzahl/main.c b/src/primzahl/main.c index 555fd74..8bf3839 100644 --- a/src/primzahl/main.c +++ b/src/primzahl/main.c @@ -8,5 +8,10 @@ int main() { int num = usergetd("Enter a positive number: ", minInput, NULL); + if (primzahl(num)) + printf("%d is a prime number.\n", num); + else + printf("%d is not a prime number.\n", num); + return 0; } \ No newline at end of file From ce75fa25ce367f605941cf1bfd5cca36965d1f5e Mon Sep 17 00:00:00 2001 From: Hendrik Sitzmann Date: Thu, 8 Feb 2024 18:47:02 +0100 Subject: [PATCH 09/15] Create header for test_primzahl --- test/primzahl/test_primzahl.c | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 test/primzahl/test_primzahl.c diff --git a/test/primzahl/test_primzahl.c b/test/primzahl/test_primzahl.c new file mode 100644 index 0000000..a61662f --- /dev/null +++ b/test/primzahl/test_primzahl.c @@ -0,0 +1,2 @@ +#include "unity.h" +#include "fakultaet.h" \ No newline at end of file From 1b681bcd85df4838a4e8f66244c7adde15f8092c Mon Sep 17 00:00:00 2001 From: Hendrik Sitzmann Date: Thu, 8 Feb 2024 18:48:27 +0100 Subject: [PATCH 10/15] Corrected header --- test/primzahl/test_primzahl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/primzahl/test_primzahl.c b/test/primzahl/test_primzahl.c index a61662f..fa8aa2b 100644 --- a/test/primzahl/test_primzahl.c +++ b/test/primzahl/test_primzahl.c @@ -1,2 +1,2 @@ #include "unity.h" -#include "fakultaet.h" \ No newline at end of file +#include "primzahl.h" \ No newline at end of file From 5ece9a8b3e3574405aeb0259270b7d997ff951fa Mon Sep 17 00:00:00 2001 From: Hendrik Sitzmann Date: Thu, 8 Feb 2024 19:11:07 +0100 Subject: [PATCH 11/15] Changed bool to int --- src/primzahl/main.c | 1 - src/primzahl/primzahl.c | 9 ++++----- src/primzahl/primzahl.h | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/primzahl/main.c b/src/primzahl/main.c index 8bf3839..ecf8960 100644 --- a/src/primzahl/main.c +++ b/src/primzahl/main.c @@ -1,7 +1,6 @@ #include "primzahl.h" #include "../userinput.h" #include -#include int main() { int minInput = 0; diff --git a/src/primzahl/primzahl.c b/src/primzahl/primzahl.c index a4b805d..e8fd70b 100644 --- a/src/primzahl/primzahl.c +++ b/src/primzahl/primzahl.c @@ -1,16 +1,15 @@ #include -#include -bool primzahl(int num) { +int primzahl(int num) { //for the case zero or one if (num <= 1) - return false; + return 0; //checking if there are any other divider for (int i = 2; i < num; i++) { if (num % i == 0) - return false; + return 0; } //if none were found return true - return true; + return 1; } \ No newline at end of file diff --git a/src/primzahl/primzahl.h b/src/primzahl/primzahl.h index 2d98817..0f6cfc2 100644 --- a/src/primzahl/primzahl.h +++ b/src/primzahl/primzahl.h @@ -1,6 +1,6 @@ #ifndef PRIMZAHL_H #define PRIMZAHL_H -bool primzahl(int num); +int primzahl(int num); #endif \ No newline at end of file From 2314fb4048251529dd86b2d4ae9effa875ff2ee3 Mon Sep 17 00:00:00 2001 From: Hendrik Sitzmann Date: Thu, 8 Feb 2024 19:13:49 +0100 Subject: [PATCH 12/15] added test for true --- test/primzahl/test_primzahl.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/test/primzahl/test_primzahl.c b/test/primzahl/test_primzahl.c index fa8aa2b..e36a611 100644 --- a/test/primzahl/test_primzahl.c +++ b/test/primzahl/test_primzahl.c @@ -1,2 +1,15 @@ #include "unity.h" -#include "primzahl.h" \ No newline at end of file +#include "primzahl.h" + +void setUP(){} +void tearDown(){} + +void test_primzahl() { + TEST_ASSERT_TRUE(primzahl(2)); + TEST_ASSERT_TRUE(primzahl(3)); + TEST_ASSERT_TRUE(primzahl(5)); + TEST_ASSERT_TRUE(primzahl(7)); + + + +} \ No newline at end of file From 64064fe07c0135456f58952c2bd190a8e63e305d Mon Sep 17 00:00:00 2001 From: Hendrik Sitzmann Date: Thu, 8 Feb 2024 19:16:04 +0100 Subject: [PATCH 13/15] added test for case false --- test/primzahl/test_primzahl.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/primzahl/test_primzahl.c b/test/primzahl/test_primzahl.c index e36a611..5f77041 100644 --- a/test/primzahl/test_primzahl.c +++ b/test/primzahl/test_primzahl.c @@ -9,7 +9,9 @@ void test_primzahl() { TEST_ASSERT_TRUE(primzahl(3)); TEST_ASSERT_TRUE(primzahl(5)); TEST_ASSERT_TRUE(primzahl(7)); - - + TEST_ASSERT_FALSE(primzahl(1)); + TEST_ASSERT_FALSE(primzahl(4)); + TEST_ASSERT_FALSE(primzahl(6)); + TEST_ASSERT_FALSE(primzahl(9)); } \ No newline at end of file From e94d6c707caa1695870679a44a1451665363fdae Mon Sep 17 00:00:00 2001 From: Hendrik Sitzmann Date: Thu, 8 Feb 2024 19:19:43 +0100 Subject: [PATCH 14/15] refactoring: added test comments --- test/primzahl/test_primzahl.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/primzahl/test_primzahl.c b/test/primzahl/test_primzahl.c index 5f77041..2276ce9 100644 --- a/test/primzahl/test_primzahl.c +++ b/test/primzahl/test_primzahl.c @@ -5,13 +5,13 @@ void setUP(){} void tearDown(){} void test_primzahl() { - TEST_ASSERT_TRUE(primzahl(2)); - TEST_ASSERT_TRUE(primzahl(3)); - TEST_ASSERT_TRUE(primzahl(5)); - TEST_ASSERT_TRUE(primzahl(7)); - TEST_ASSERT_FALSE(primzahl(1)); - TEST_ASSERT_FALSE(primzahl(4)); - TEST_ASSERT_FALSE(primzahl(6)); - TEST_ASSERT_FALSE(primzahl(9)); + TEST_ASSERT_TRUE(primzahl(2)); // 2 is a prime number + TEST_ASSERT_TRUE(primzahl(3)); // 3 is a prime number + TEST_ASSERT_TRUE(primzahl(5)); // 5 is a prime number + TEST_ASSERT_TRUE(primzahl(7)); // 7 is a prime number + TEST_ASSERT_FALSE(primzahl(1)); // 1 is not a prime number + TEST_ASSERT_FALSE(primzahl(4)); // 4 is not a prime number + TEST_ASSERT_FALSE(primzahl(6)); // 6 is not a prime number + TEST_ASSERT_FALSE(primzahl(9)); // 9 is not a prime number } \ No newline at end of file From a98e9ecc1831e787019b251a3faa02356ce61eb5 Mon Sep 17 00:00:00 2001 From: Hendrik Sitzmann Date: Thu, 8 Feb 2024 19:22:18 +0100 Subject: [PATCH 15/15] refactoring: added comments in main --- src/primzahl/main.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/primzahl/main.c b/src/primzahl/main.c index ecf8960..8480010 100644 --- a/src/primzahl/main.c +++ b/src/primzahl/main.c @@ -3,10 +3,13 @@ #include int main() { + // set the smallest possible input int minInput = 0; + //get user input int num = usergetd("Enter a positive number: ", minInput, NULL); + //check if its a prime number or not if (primzahl(num)) printf("%d is a prime number.\n", num); else