From 8e6a9d1d5166dee4c574e6d2b83f29fc18e4b9e2 Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Fri, 2 Feb 2024 15:24:05 +0100 Subject: [PATCH 01/36] created kgV.h file --- src/kgV/kgV.h | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/kgV/kgV.h diff --git a/src/kgV/kgV.h b/src/kgV/kgV.h new file mode 100644 index 0000000..994b957 --- /dev/null +++ b/src/kgV/kgV.h @@ -0,0 +1,6 @@ +#ifndef KGV_H +#define KGV_H + +int kgV(int a, int b); + +#endif From 124ecff740bd6354700e589edc81c4f0c5770cd2 Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Fri, 2 Feb 2024 15:26:00 +0100 Subject: [PATCH 02/36] implemented prototype function kgV(int a, int b) --- src/kgV/kgV.c | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/kgV/kgV.c diff --git a/src/kgV/kgV.c b/src/kgV/kgV.c new file mode 100644 index 0000000..857de9c --- /dev/null +++ b/src/kgV/kgV.c @@ -0,0 +1,3 @@ +#include + +int kgV(int a, int b); \ No newline at end of file From 66f28def9243cbde640b675dea56489fdd228de7 Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Fri, 2 Feb 2024 15:37:44 +0100 Subject: [PATCH 03/36] added simple algorithm for getting the kgV --- src/kgV/kgV.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/kgV/kgV.c b/src/kgV/kgV.c index 857de9c..0fd539a 100644 --- a/src/kgV/kgV.c +++ b/src/kgV/kgV.c @@ -1,3 +1,19 @@ #include -int kgV(int a, int b); \ No newline at end of file +int ggT(int a, int b){ + // handles the zero cases + if(a == 0) return b; + if(b == 0) return a; + + // Euclidean algorithm with modulo for getting the ggT + while (b != 0) { + int temp = b; + b = a % b; + a = temp; + } + return a; +} + +int kgV(int a, int b){ + return a*b/ ggT(a, b); +} \ No newline at end of file From 08b43f0ba23f12e89fee1f4352bddd69e61f878c Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Fri, 2 Feb 2024 15:38:37 +0100 Subject: [PATCH 04/36] added simple test for input 6 and 8 --- test/kgV/test_kgV.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 test/kgV/test_kgV.c diff --git a/test/kgV/test_kgV.c b/test/kgV/test_kgV.c new file mode 100644 index 0000000..6c15e75 --- /dev/null +++ b/test/kgV/test_kgV.c @@ -0,0 +1,17 @@ +#include "unity.h" +#include "kgV.h" + +void setUp(void){} +void tearDown(void){} + +void test_kgV8And6(void) { + //arrange + int a = 8; + int b = 6; + int expected = 24; + + //act + int result = kgV(a, b); + + TEST_ASSERT_EQUAL_INT(expected, result); +} From 77b6fbc7043522f9c2237d36d7a50c4e09c705b8 Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Fri, 2 Feb 2024 15:48:27 +0100 Subject: [PATCH 05/36] refactoring: use ggT function from previous instead of new one --- src/kgV/kgV.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/kgV/kgV.c b/src/kgV/kgV.c index 0fd539a..a9e61e8 100644 --- a/src/kgV/kgV.c +++ b/src/kgV/kgV.c @@ -1,18 +1,5 @@ #include - -int ggT(int a, int b){ - // handles the zero cases - if(a == 0) return b; - if(b == 0) return a; - - // Euclidean algorithm with modulo for getting the ggT - while (b != 0) { - int temp = b; - b = a % b; - a = temp; - } - return a; -} +#include "ggT.h" int kgV(int a, int b){ return a*b/ ggT(a, b); From 6ad2f3dae75a26484f9066f427c8d108fdae202c Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Fri, 2 Feb 2024 15:50:47 +0100 Subject: [PATCH 06/36] implemented case if at least one input is zero --- src/kgV/kgV.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/kgV/kgV.c b/src/kgV/kgV.c index a9e61e8..2821d84 100644 --- a/src/kgV/kgV.c +++ b/src/kgV/kgV.c @@ -2,5 +2,6 @@ #include "ggT.h" int kgV(int a, int b){ + if(a == 0 || b == 0) return 0; return a*b/ ggT(a, b); } \ No newline at end of file From 6fd24960578b7077af54d2d4ef79df010ce37c3a Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Fri, 2 Feb 2024 15:52:15 +0100 Subject: [PATCH 07/36] added tests for zero cases --- test/kgV/test_kgV.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/test/kgV/test_kgV.c b/test/kgV/test_kgV.c index 6c15e75..6c63776 100644 --- a/test/kgV/test_kgV.c +++ b/test/kgV/test_kgV.c @@ -1,5 +1,6 @@ #include "unity.h" #include "kgV.h" +#include "ggT.h" void setUp(void){} void tearDown(void){} @@ -13,5 +14,45 @@ void test_kgV8And6(void) { //act int result = kgV(a, b); + //assert + TEST_ASSERT_EQUAL_INT(expected, result); +} + +void test_kgVOfFirstNumberZero(){ + //arrange + int a = 0; + int b = 5; + int expected = 0; + + //act + int result = kgV(a, b); + + //assert + TEST_ASSERT_EQUAL_INT(expected, result); +} + +void test_kgVOfSecondNumberZero(){ + //arrange + int a = 5; + int b = 0; + int expected = 0; + + //act + int result = kgV(a, b); + + //assert + TEST_ASSERT_EQUAL_INT(expected, result); +} + +void test_kgVOfBothNumbersZero(){ + //arrange + int a = 0; + int b = 0; + int expected = 0; + + //act + int result = kgV(a, b); + + //assert TEST_ASSERT_EQUAL_INT(expected, result); } From aadef721f647036e8887cfbb82775f5d9225c7b9 Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Fri, 2 Feb 2024 15:53:30 +0100 Subject: [PATCH 08/36] added test for common case --- test/kgV/test_kgV.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/kgV/test_kgV.c b/test/kgV/test_kgV.c index 6c63776..bc6ec47 100644 --- a/test/kgV/test_kgV.c +++ b/test/kgV/test_kgV.c @@ -56,3 +56,16 @@ void test_kgVOfBothNumbersZero(){ //assert TEST_ASSERT_EQUAL_INT(expected, result); } + +void test_kgVOf2And17(){ + //arrange + int a = 2; + int b = 17; + int expected = 34; + + //act + int result = kgV(a, b); + + //assert + TEST_ASSERT_EQUAL_INT(expected, result); +} From c8f94aa950e53f555327bbca69cd79c5535af91c Mon Sep 17 00:00:00 2001 From: fdai7777 Date: Tue, 6 Feb 2024 11:34:07 +0000 Subject: [PATCH 09/36] Update team.md --- team.md | 1 + 1 file changed, 1 insertion(+) diff --git a/team.md b/team.md index b864f93..60e2b5f 100644 --- a/team.md +++ b/team.md @@ -1,5 +1,6 @@ - TheUltimateOptimist, fdai8031 - cxnnqr, fdai7777 +- fdai7777, fdai7777 - Laurin, fdai7858 - fdai7968, fdai7968 - Hendrik, fdai7595 From 7cf436571ff31d519e2f9545a64e3e0bb60dfee0 Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Tue, 6 Feb 2024 12:40:46 +0100 Subject: [PATCH 10/36] added function to ensure that the value of kgV is always positive --- src/kgV/kgV.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/kgV/kgV.c b/src/kgV/kgV.c index 2821d84..e050d06 100644 --- a/src/kgV/kgV.c +++ b/src/kgV/kgV.c @@ -1,7 +1,10 @@ #include +#include #include "ggT.h" int kgV(int a, int b){ if(a == 0 || b == 0) return 0; - return a*b/ ggT(a, b); + int kgV = a*b/ ggT(a, b); + int absoluteKgV = abs(kgV); + return absoluteKgV; } \ No newline at end of file From f30003a54ecbcfe7c189306613182a668b354a8f Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Tue, 6 Feb 2024 12:42:08 +0100 Subject: [PATCH 11/36] added test for first number negative and second positive --- test/kgV/test_kgV.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/kgV/test_kgV.c b/test/kgV/test_kgV.c index bc6ec47..05f8b00 100644 --- a/test/kgV/test_kgV.c +++ b/test/kgV/test_kgV.c @@ -69,3 +69,16 @@ void test_kgVOf2And17(){ //assert TEST_ASSERT_EQUAL_INT(expected, result); } + +void test_kgVOfFirstNumberNegative(){ + //arrange + int a = -2; + int b = 17; + int expected = 34; + + //act + int result = kgV(a, b); + + //assert + TEST_ASSERT_EQUAL_INT(expected, result); +} From 7b276a14a3d87848df7419a18c06f860651a65b9 Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Tue, 6 Feb 2024 12:42:55 +0100 Subject: [PATCH 12/36] added test for second number negative --- test/kgV/test_kgV.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/kgV/test_kgV.c b/test/kgV/test_kgV.c index 05f8b00..2b1359f 100644 --- a/test/kgV/test_kgV.c +++ b/test/kgV/test_kgV.c @@ -82,3 +82,16 @@ void test_kgVOfFirstNumberNegative(){ //assert TEST_ASSERT_EQUAL_INT(expected, result); } + +void test_kgVOfSecondNumberNegative(){ + //arrange + int a = 2; + int b = -17; + int expected = 34; + + //act + int result = kgV(a, b); + + //assert + TEST_ASSERT_EQUAL_INT(expected, result); +} From 99a7f7d00684cd082674852e7dcf2b4803ce7cf9 Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Tue, 6 Feb 2024 12:43:36 +0100 Subject: [PATCH 13/36] added test for both numbers negative --- test/kgV/test_kgV.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/kgV/test_kgV.c b/test/kgV/test_kgV.c index 2b1359f..95918dc 100644 --- a/test/kgV/test_kgV.c +++ b/test/kgV/test_kgV.c @@ -95,3 +95,16 @@ void test_kgVOfSecondNumberNegative(){ //assert TEST_ASSERT_EQUAL_INT(expected, result); } + +void test_kgVOfBothNumbersNegative(){ + //arrange + int a = -2; + int b = -17; + int expected = 34; + + //act + int result = kgV(a, b); + + //assert + TEST_ASSERT_EQUAL_INT(expected, result); +} From a8b6e1ea279dfa072dfecad469a119d1b2a5e43e Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Tue, 6 Feb 2024 12:45:22 +0100 Subject: [PATCH 14/36] refactoring: refactored negative number handling into one line --- src/kgV/kgV.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/kgV/kgV.c b/src/kgV/kgV.c index e050d06..64983ee 100644 --- a/src/kgV/kgV.c +++ b/src/kgV/kgV.c @@ -4,7 +4,5 @@ int kgV(int a, int b){ if(a == 0 || b == 0) return 0; - int kgV = a*b/ ggT(a, b); - int absoluteKgV = abs(kgV); - return absoluteKgV; + return abs(a*b/ ggT(a, b)); } \ No newline at end of file From a843597a7bfb1b555020cfc468bf58850e72fb2d Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Tue, 6 Feb 2024 12:51:56 +0100 Subject: [PATCH 15/36] refactoring: summarized tests --- test/kgV/test_kgV.c | 88 +++++---------------------------------------- 1 file changed, 8 insertions(+), 80 deletions(-) diff --git a/test/kgV/test_kgV.c b/test/kgV/test_kgV.c index 95918dc..7c9c100 100644 --- a/test/kgV/test_kgV.c +++ b/test/kgV/test_kgV.c @@ -6,105 +6,33 @@ void setUp(void){} void tearDown(void){} void test_kgV8And6(void) { - //arrange - int a = 8; - int b = 6; - int expected = 24; - - //act - int result = kgV(a, b); - - //assert - TEST_ASSERT_EQUAL_INT(expected, result); + TEST_ASSERT_EQUAL_INT(24, kgV(8, 6)); } void test_kgVOfFirstNumberZero(){ - //arrange - int a = 0; - int b = 5; - int expected = 0; - - //act - int result = kgV(a, b); - - //assert - TEST_ASSERT_EQUAL_INT(expected, result); + TEST_ASSERT_EQUAL_INT(0, kgV(0, 5)); } void test_kgVOfSecondNumberZero(){ - //arrange - int a = 5; - int b = 0; - int expected = 0; - - //act - int result = kgV(a, b); - - //assert - TEST_ASSERT_EQUAL_INT(expected, result); + TEST_ASSERT_EQUAL_INT(0, kgV(5, 0)); } void test_kgVOfBothNumbersZero(){ - //arrange - int a = 0; - int b = 0; - int expected = 0; - - //act - int result = kgV(a, b); - - //assert - TEST_ASSERT_EQUAL_INT(expected, result); + TEST_ASSERT_EQUAL_INT(0, kgV(0, 0)); } void test_kgVOf2And17(){ - //arrange - int a = 2; - int b = 17; - int expected = 34; - - //act - int result = kgV(a, b); - - //assert - TEST_ASSERT_EQUAL_INT(expected, result); + TEST_ASSERT_EQUAL_INT(34, kgV(2, 17)); } void test_kgVOfFirstNumberNegative(){ - //arrange - int a = -2; - int b = 17; - int expected = 34; - - //act - int result = kgV(a, b); - - //assert - TEST_ASSERT_EQUAL_INT(expected, result); + TEST_ASSERT_EQUAL_INT(34, kgV(-2, 17)); } void test_kgVOfSecondNumberNegative(){ - //arrange - int a = 2; - int b = -17; - int expected = 34; - - //act - int result = kgV(a, b); - - //assert - TEST_ASSERT_EQUAL_INT(expected, result); + TEST_ASSERT_EQUAL_INT(34, kgV(2, -17)); } void test_kgVOfBothNumbersNegative(){ - //arrange - int a = -2; - int b = -17; - int expected = 34; - - //act - int result = kgV(a, b); - - //assert - TEST_ASSERT_EQUAL_INT(expected, result); + TEST_ASSERT_EQUAL_INT(34, kgV(-2, -17)); } From 7b82e04292b59bcaa1ed93f97cc63d11aa17a943 Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Tue, 6 Feb 2024 12:54:28 +0100 Subject: [PATCH 16/36] refactoring: summarized tests --- test/ggT/test_ggT.c | 55 +++++---------------------------------------- 1 file changed, 5 insertions(+), 50 deletions(-) diff --git a/test/ggT/test_ggT.c b/test/ggT/test_ggT.c index 6c14258..7e4beec 100644 --- a/test/ggT/test_ggT.c +++ b/test/ggT/test_ggT.c @@ -5,66 +5,21 @@ void setUp(){} void tearDown(){} void test_ggTOf5And10(){ - //arrange - int a = 5; - int b = 10; - int expected = 5; - - //act - int result = ggT(a,b); - - //assert - TEST_ASSERT_EQUAL_INT(expected, result); + TEST_ASSERT_EQUAL_INT(5, ggT(5, 10)); } void test_ggTOfFirstNumberZero(){ - //arrange - int a = 0; - int b = 5; - int expected = 5; - - //act - int result = ggT(a,b); - - //assert - TEST_ASSERT_EQUAL_INT(expected, result); + TEST_ASSERT_EQUAL_INT(5, ggT(0, 5)); } void test_ggTOfSecondNumberZero(){ - //arrange - int a = 10; - int b = 0; - int expected = 10; - - //act - int result = ggT(a,b); - - //assert - TEST_ASSERT_EQUAL_INT(expected, result); + TEST_ASSERT_EQUAL_INT(10, ggT(10, 0)); } void test_ggTOfBothNumbersZero(){ - //arrange - int a = 0; - int b = 0; - int expected = 0; - - //act - int result = ggT(a,b); - - //assert - TEST_ASSERT_EQUAL_INT(expected,result); + TEST_ASSERT_EQUAL_INT(0, ggT(0, 0)); } void test_ggTOfCoprimes(){ - //arrange - int a = 13; - int b = 27; - int expected = 1; - - //act - int result = ggT(a,b); - - //assert - TEST_ASSERT_EQUAL_INT(expected,result); + TEST_ASSERT_EQUAL_INT(1, ggT(13, 27)); } \ No newline at end of file From 7ddc4b2251cfa91f7c999afc394cd8658c66571b Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Tue, 6 Feb 2024 13:15:04 +0100 Subject: [PATCH 17/36] added main.c for ggT --- src/ggT/main.c | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/ggT/main.c diff --git a/src/ggT/main.c b/src/ggT/main.c new file mode 100644 index 0000000..a02ee74 --- /dev/null +++ b/src/ggT/main.c @@ -0,0 +1,6 @@ +int main(){ + + + return 0; +} + From fda5883b0c053a2d26e2cc652bd5915aaeffc18f Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Tue, 6 Feb 2024 13:15:56 +0100 Subject: [PATCH 18/36] added functions to get the two numbers by the user --- src/ggT/main.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ggT/main.c b/src/ggT/main.c index a02ee74..f6334b2 100644 --- a/src/ggT/main.c +++ b/src/ggT/main.c @@ -1,5 +1,11 @@ -int main(){ +#include "ggT.h" +#include "../userinput.h" +#include +int main(){ + printf("add two numbers:\n"); + int firstNum = usergetd("first number: ", 0, NULL); + int secondNum = usergetd("second number: ", 0, NULL); return 0; } From 9d410dc9f2f887c59926ff25b863ce6efacd4b4c Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Tue, 6 Feb 2024 13:17:22 +0100 Subject: [PATCH 19/36] added ggT function to get the result --- src/ggT/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ggT/main.c b/src/ggT/main.c index f6334b2..fd29c99 100644 --- a/src/ggT/main.c +++ b/src/ggT/main.c @@ -6,6 +6,7 @@ int main(){ printf("add two numbers:\n"); int firstNum = usergetd("first number: ", 0, NULL); int secondNum = usergetd("second number: ", 0, NULL); + int result = ggT(firstNum, secondNum); return 0; } From e783ed4f25b40527ae377befac9dd3be078bd95d Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Tue, 6 Feb 2024 13:18:08 +0100 Subject: [PATCH 20/36] print the ggT of those two numbers --- src/ggT/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ggT/main.c b/src/ggT/main.c index fd29c99..b40637a 100644 --- a/src/ggT/main.c +++ b/src/ggT/main.c @@ -7,6 +7,7 @@ int main(){ int firstNum = usergetd("first number: ", 0, NULL); int secondNum = usergetd("second number: ", 0, NULL); int result = ggT(firstNum, secondNum); + printf("The ggT is: %d\n", result); return 0; } From 1db5c0ef757dd10746e3de45531e1b4589f9db82 Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Tue, 6 Feb 2024 13:19:58 +0100 Subject: [PATCH 21/36] refactoring: changed print messages --- src/ggT/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ggT/main.c b/src/ggT/main.c index b40637a..e9bc365 100644 --- a/src/ggT/main.c +++ b/src/ggT/main.c @@ -3,11 +3,11 @@ #include int main(){ - printf("add two numbers:\n"); + printf("Please add the two numbers you want the ggT of:\n"); int firstNum = usergetd("first number: ", 0, NULL); int secondNum = usergetd("second number: ", 0, NULL); int result = ggT(firstNum, secondNum); - printf("The ggT is: %d\n", result); + printf("The ggT of %d and %d is: %d\n", firstNum, secondNum, result); return 0; } From 533ab40c6f61b06b78bd75da6c51e22dc4b2c388 Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Tue, 6 Feb 2024 13:23:57 +0100 Subject: [PATCH 22/36] added main.c --- src/kgV/main.c | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/kgV/main.c diff --git a/src/kgV/main.c b/src/kgV/main.c new file mode 100644 index 0000000..7ce5e1a --- /dev/null +++ b/src/kgV/main.c @@ -0,0 +1,4 @@ +int main(){ + + return 0; +} \ No newline at end of file From b9a89c98f258ecf748e32c4c407101eda4887997 Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Tue, 6 Feb 2024 13:24:58 +0100 Subject: [PATCH 23/36] included needed header files --- src/kgV/main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/kgV/main.c b/src/kgV/main.c index 7ce5e1a..f5a256c 100644 --- a/src/kgV/main.c +++ b/src/kgV/main.c @@ -1,3 +1,7 @@ +#include "kgV.h" +#include "../userinput.h" +#include + int main(){ return 0; From a8ecd84db884e018813cb720341b6af2a2a6c0c7 Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Tue, 6 Feb 2024 13:26:21 +0100 Subject: [PATCH 24/36] added functions to get two numbers by user --- src/kgV/main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/kgV/main.c b/src/kgV/main.c index f5a256c..7d4eaf4 100644 --- a/src/kgV/main.c +++ b/src/kgV/main.c @@ -3,6 +3,10 @@ #include int main(){ + printf("add two numbers:\n"); + int firstNum = usergetd("first number: ", 0, NULL); + int secondNum = usergetd("second number: ", 0, NULL); + return 0; } \ No newline at end of file From d9ad37c8d1f7cb7234550ca8411c34447cd778d7 Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Tue, 6 Feb 2024 13:27:07 +0100 Subject: [PATCH 25/36] added function to get the kgV of the given numbers --- src/kgV/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/kgV/main.c b/src/kgV/main.c index 7d4eaf4..46410bd 100644 --- a/src/kgV/main.c +++ b/src/kgV/main.c @@ -6,6 +6,7 @@ int main(){ printf("add two numbers:\n"); int firstNum = usergetd("first number: ", 0, NULL); int secondNum = usergetd("second number: ", 0, NULL); + int result = kgV(firstNum, secondNum); return 0; From de0b5f1b094b2e5948951414d4fe89d8693105e3 Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Tue, 6 Feb 2024 13:27:43 +0100 Subject: [PATCH 26/36] print the kgV --- src/kgV/main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/kgV/main.c b/src/kgV/main.c index 46410bd..198b263 100644 --- a/src/kgV/main.c +++ b/src/kgV/main.c @@ -7,6 +7,8 @@ int main(){ int firstNum = usergetd("first number: ", 0, NULL); int secondNum = usergetd("second number: ", 0, NULL); int result = kgV(firstNum, secondNum); + printf("The result is: %d\n", result); + return 0; From 7afe7b42308041951400748cca3a5e0b309edc66 Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Tue, 6 Feb 2024 13:28:21 +0100 Subject: [PATCH 27/36] Changed min Numbers to NULL because negative numbers can be handled too --- src/kgV/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/kgV/main.c b/src/kgV/main.c index 198b263..e32341d 100644 --- a/src/kgV/main.c +++ b/src/kgV/main.c @@ -4,8 +4,8 @@ int main(){ printf("add two numbers:\n"); - int firstNum = usergetd("first number: ", 0, NULL); - int secondNum = usergetd("second number: ", 0, NULL); + int firstNum = usergetd("first number: ", NULL, NULL); + int secondNum = usergetd("second number: ", NULL, NULL); int result = kgV(firstNum, secondNum); printf("The result is: %d\n", result); From 550371fc9b1fe89e403523fbb8b63bbf5c3b37a1 Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Tue, 6 Feb 2024 13:29:45 +0100 Subject: [PATCH 28/36] refactoring: changed print messages --- src/kgV/main.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/kgV/main.c b/src/kgV/main.c index e32341d..d18e516 100644 --- a/src/kgV/main.c +++ b/src/kgV/main.c @@ -3,13 +3,11 @@ #include int main(){ - printf("add two numbers:\n"); + printf("Please add the two numbers you want the kgV of:\n"); int firstNum = usergetd("first number: ", NULL, NULL); int secondNum = usergetd("second number: ", NULL, NULL); int result = kgV(firstNum, secondNum); - printf("The result is: %d\n", result); - - + printf("The kgV of %d and %d is: %d\n", firstNum, secondNum, result); return 0; } \ No newline at end of file From edf2d874429627b5ef9ff94f0a0bf6914340b412 Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Tue, 6 Feb 2024 13:30:52 +0100 Subject: [PATCH 29/36] refactoring: added comments --- src/kgV/main.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/kgV/main.c b/src/kgV/main.c index d18e516..fe7b6a0 100644 --- a/src/kgV/main.c +++ b/src/kgV/main.c @@ -3,10 +3,16 @@ #include int main(){ + + // User input for the two numbers. No matter of positive or negative printf("Please add the two numbers you want the kgV of:\n"); int firstNum = usergetd("first number: ", NULL, NULL); int secondNum = usergetd("second number: ", NULL, NULL); + + // Calculation of the kgV int result = kgV(firstNum, secondNum); + + // Print the result printf("The kgV of %d and %d is: %d\n", firstNum, secondNum, result); return 0; From 5cf4056435cccb209a1e27facf5e7980540bddbf Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Tue, 6 Feb 2024 13:32:09 +0100 Subject: [PATCH 30/36] refactoring: added comments --- src/kgV/kgV.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/kgV/kgV.c b/src/kgV/kgV.c index 64983ee..6c6ae52 100644 --- a/src/kgV/kgV.c +++ b/src/kgV/kgV.c @@ -3,6 +3,10 @@ #include "ggT.h" int kgV(int a, int b){ + + // Case for at least one number is Zero if(a == 0 || b == 0) return 0; + + // Regular case of calculating the kgV return abs(a*b/ ggT(a, b)); } \ No newline at end of file From 36035dbc001ea380c7f911af5c04750c8201e4c1 Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Tue, 6 Feb 2024 13:35:25 +0100 Subject: [PATCH 31/36] refactoring: changed back to longer version for better overview and understanding --- src/kgV/kgV.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/kgV/kgV.c b/src/kgV/kgV.c index 6c6ae52..0bdb026 100644 --- a/src/kgV/kgV.c +++ b/src/kgV/kgV.c @@ -8,5 +8,10 @@ int kgV(int a, int b){ if(a == 0 || b == 0) return 0; // Regular case of calculating the kgV - return abs(a*b/ ggT(a, b)); + int kgV = a*b/ ggT(a, b); + + // Getting the absolute value of the kgV + int absoluteKgV = abs(kgV); + + return absoluteKgV; } \ No newline at end of file From bd68e4032492d1392ca97dd75c713f8a17e58258 Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Tue, 6 Feb 2024 13:42:31 +0100 Subject: [PATCH 32/36] refactoring: added comments --- test/kgV/test_kgV.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/test/kgV/test_kgV.c b/test/kgV/test_kgV.c index 7c9c100..39d5d4b 100644 --- a/test/kgV/test_kgV.c +++ b/test/kgV/test_kgV.c @@ -5,10 +5,18 @@ void setUp(void){} void tearDown(void){} +// Tests for common Cases: void test_kgV8And6(void) { TEST_ASSERT_EQUAL_INT(24, kgV(8, 6)); } +void test_kgVOf2And17(){ + TEST_ASSERT_EQUAL_INT(34, kgV(2, 17)); +} + + + +// Tests for Cases with Zero in input: void test_kgVOfFirstNumberZero(){ TEST_ASSERT_EQUAL_INT(0, kgV(0, 5)); } @@ -21,10 +29,9 @@ void test_kgVOfBothNumbersZero(){ TEST_ASSERT_EQUAL_INT(0, kgV(0, 0)); } -void test_kgVOf2And17(){ - TEST_ASSERT_EQUAL_INT(34, kgV(2, 17)); -} + +// Tests for Cases with negative numbers void test_kgVOfFirstNumberNegative(){ TEST_ASSERT_EQUAL_INT(34, kgV(-2, 17)); } From 14a59e865e271f400c9084eb534fd94acecf74f6 Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Tue, 6 Feb 2024 13:44:20 +0100 Subject: [PATCH 33/36] refactoring: added comments --- src/ggT/main.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ggT/main.c b/src/ggT/main.c index e9bc365..e32be86 100644 --- a/src/ggT/main.c +++ b/src/ggT/main.c @@ -3,10 +3,16 @@ #include int main(){ + + // Getting user input for the two numbers printf("Please add the two numbers you want the ggT of:\n"); int firstNum = usergetd("first number: ", 0, NULL); int secondNum = usergetd("second number: ", 0, NULL); + + // Calculating the ggT of those two numbers int result = ggT(firstNum, secondNum); + + // Print the result printf("The ggT of %d and %d is: %d\n", firstNum, secondNum, result); return 0; From 3bf80b712704a8420f4d224e267e578eac651514 Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Tue, 6 Feb 2024 13:46:17 +0100 Subject: [PATCH 34/36] refactoring: added comments --- test/ggT/test_ggT.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/ggT/test_ggT.c b/test/ggT/test_ggT.c index 7e4beec..3f76bcd 100644 --- a/test/ggT/test_ggT.c +++ b/test/ggT/test_ggT.c @@ -4,10 +4,15 @@ void setUp(){} void tearDown(){} + +// Test for Common Case void test_ggTOf5And10(){ TEST_ASSERT_EQUAL_INT(5, ggT(5, 10)); } + + +// Tests for Cases with Zero in input void test_ggTOfFirstNumberZero(){ TEST_ASSERT_EQUAL_INT(5, ggT(0, 5)); } @@ -20,6 +25,9 @@ void test_ggTOfBothNumbersZero(){ TEST_ASSERT_EQUAL_INT(0, ggT(0, 0)); } + + +// Test for edge Case - Coprime Numbers void test_ggTOfCoprimes(){ TEST_ASSERT_EQUAL_INT(1, ggT(13, 27)); } \ No newline at end of file From d954780e2d239b4817738e1797e1215040818183 Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Tue, 6 Feb 2024 14:05:57 +0100 Subject: [PATCH 35/36] refactoring: standardized the test naming --- test/kgV/test_kgV.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/kgV/test_kgV.c b/test/kgV/test_kgV.c index 39d5d4b..454b7f0 100644 --- a/test/kgV/test_kgV.c +++ b/test/kgV/test_kgV.c @@ -6,7 +6,7 @@ void setUp(void){} void tearDown(void){} // Tests for common Cases: -void test_kgV8And6(void) { +void test_kgVOf8And6(void) { TEST_ASSERT_EQUAL_INT(24, kgV(8, 6)); } From fd14664ff1907e68bf579505092a565b88ae5b10 Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Tue, 6 Feb 2024 14:12:34 +0100 Subject: [PATCH 36/36] refactoring: better variable naming --- src/kgV/kgV.c | 8 ++++---- src/kgV/kgV.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/kgV/kgV.c b/src/kgV/kgV.c index 0bdb026..6c37f8f 100644 --- a/src/kgV/kgV.c +++ b/src/kgV/kgV.c @@ -2,16 +2,16 @@ #include #include "ggT.h" -int kgV(int a, int b){ +int kgV(int fistNumber, int secondNumber){ // Case for at least one number is Zero - if(a == 0 || b == 0) return 0; + if(fistNumber == 0 || secondNumber == 0) return 0; // Regular case of calculating the kgV - int kgV = a*b/ ggT(a, b); + int kgVResult = fistNumber*secondNumber/ ggT(fistNumber, secondNumber); // Getting the absolute value of the kgV - int absoluteKgV = abs(kgV); + int absoluteKgV = abs(kgVResult); return absoluteKgV; } \ No newline at end of file diff --git a/src/kgV/kgV.h b/src/kgV/kgV.h index 994b957..d1f51f1 100644 --- a/src/kgV/kgV.h +++ b/src/kgV/kgV.h @@ -1,6 +1,6 @@ #ifndef KGV_H #define KGV_H -int kgV(int a, int b); +int kgV(int firstNumber, int secondNumber); #endif