Browse Source

Merge branch 'kgV' into 'master'

kgV

See merge request fdai8031/cstools101!6
remotes/origin/userinput
fdai7777 11 months ago
parent
commit
7bfedc342c
  1. 17
      src/kgV/kgV.c
  2. 6
      src/kgV/kgV.h
  3. 19
      src/kgV/main.c
  4. 45
      test/kgV/test_kgV.c

17
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;
}

6
src/kgV/kgV.h

@ -0,0 +1,6 @@
#ifndef KGV_H
#define KGV_H
int kgV(int a, int b);
#endif

19
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;
}

45
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));
}
Loading…
Cancel
Save