diff --git a/src/kgV/kgV.c b/src/kgV/kgV.c new file mode 100644 index 0000000..0bdb026 --- /dev/null +++ b/src/kgV/kgV.c @@ -0,0 +1,17 @@ +#include <stdio.h> +#include <stdlib.h> +#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 + 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 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 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 <stdio.h> + +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/test/kgV/test_kgV.c b/test/kgV/test_kgV.c new file mode 100644 index 0000000..39d5d4b --- /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_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)); +} + +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)); +}