diff --git a/src/ggT/main.c b/src/ggT/main.c new file mode 100644 index 0000000..e32be86 --- /dev/null +++ b/src/ggT/main.c @@ -0,0 +1,20 @@ +#include "ggT.h" +#include "../userinput.h" +#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; +} + diff --git a/src/kgV/kgV.c b/src/kgV/kgV.c new file mode 100644 index 0000000..6c37f8f --- /dev/null +++ b/src/kgV/kgV.c @@ -0,0 +1,17 @@ +#include +#include +#include "ggT.h" + +int kgV(int fistNumber, int secondNumber){ + + // Case for at least one number is Zero + if(fistNumber == 0 || secondNumber == 0) return 0; + + // Regular case of calculating the kgV + int kgVResult = fistNumber*secondNumber/ ggT(fistNumber, secondNumber); + + // Getting the absolute value of the 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 new file mode 100644 index 0000000..d1f51f1 --- /dev/null +++ b/src/kgV/kgV.h @@ -0,0 +1,6 @@ +#ifndef KGV_H +#define KGV_H + +int kgV(int firstNumber, int secondNumber); + +#endif diff --git a/src/kgV/main.c b/src/kgV/main.c new file mode 100644 index 0000000..fe7b6a0 --- /dev/null +++ b/src/kgV/main.c @@ -0,0 +1,19 @@ +#include "kgV.h" +#include "../userinput.h" +#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; +} \ No newline at end of file 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 diff --git a/test/ggT/test_ggT.c b/test/ggT/test_ggT.c index 6c14258..3f76bcd 100644 --- a/test/ggT/test_ggT.c +++ b/test/ggT/test_ggT.c @@ -4,67 +4,30 @@ 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 for Common Case +void test_ggTOf5And10(){ + 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); +// Tests for Cases with Zero in input +void test_ggTOfFirstNumberZero(){ + 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 for edge Case - Coprime Numbers +void test_ggTOfCoprimes(){ + TEST_ASSERT_EQUAL_INT(1, ggT(13, 27)); } \ No newline at end of file diff --git a/test/kgV/test_kgV.c b/test/kgV/test_kgV.c new file mode 100644 index 0000000..454b7f0 --- /dev/null +++ b/test/kgV/test_kgV.c @@ -0,0 +1,45 @@ +#include "unity.h" +#include "kgV.h" +#include "ggT.h" + +void setUp(void){} +void tearDown(void){} + +// Tests for common Cases: +void test_kgVOf8And6(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)); +} + +void test_kgVOfSecondNumberZero(){ + TEST_ASSERT_EQUAL_INT(0, kgV(5, 0)); +} + +void test_kgVOfBothNumbersZero(){ + TEST_ASSERT_EQUAL_INT(0, kgV(0, 0)); +} + + + +// Tests for Cases with negative numbers +void test_kgVOfFirstNumberNegative(){ + TEST_ASSERT_EQUAL_INT(34, kgV(-2, 17)); +} + +void test_kgVOfSecondNumberNegative(){ + TEST_ASSERT_EQUAL_INT(34, kgV(2, -17)); +} + +void test_kgVOfBothNumbersNegative(){ + TEST_ASSERT_EQUAL_INT(34, kgV(-2, -17)); +}