Browse Source

Merge branch 'master' of https://gitlab.cs.hs-fulda.de/fdai8031/cstools101

remotes/origin/userinput
Laurin 11 months ago
parent
commit
c602ead0d5
  1. 20
      src/ggT/main.c
  2. 17
      src/kgV/kgV.c
  3. 6
      src/kgV/kgV.h
  4. 19
      src/kgV/main.c
  5. 1
      team.md
  6. 59
      test/ggT/test_ggT.c
  7. 45
      test/kgV/test_kgV.c

20
src/ggT/main.c

@ -0,0 +1,20 @@
#include "ggT.h"
#include "../userinput.h"
#include <stdio.h>
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;
}

17
src/kgV/kgV.c

@ -0,0 +1,17 @@
#include <stdio.h>
#include <stdlib.h>
#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;
}

6
src/kgV/kgV.h

@ -0,0 +1,6 @@
#ifndef KGV_H
#define KGV_H
int kgV(int firstNumber, int secondNumber);
#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;
}

1
team.md

@ -1,5 +1,6 @@
- TheUltimateOptimist, fdai8031 - TheUltimateOptimist, fdai8031
- cxnnqr, fdai7777 - cxnnqr, fdai7777
- fdai7777, fdai7777
- Laurin, fdai7858 - Laurin, fdai7858
- fdai7968, fdai7968 - fdai7968, fdai7968
- Hendrik, fdai7595 - Hendrik, fdai7595

59
test/ggT/test_ggT.c

@ -4,67 +4,30 @@
void setUp(){} void setUp(){}
void tearDown(){} 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(){ 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(){ 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));
} }

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