Browse Source

Merge branch 'master' into conversionOfNumbers

remotes/origin/conversionOfNumbers
Laurin 11 months ago
parent
commit
d47ebc5e7b
  1. 16
      src/ggT/ggT.c
  2. 6
      src/ggT/ggT.h
  3. 4
      team.md
  4. 70
      test/ggT/test_ggT.c

16
src/ggT/ggT.c

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

6
src/ggT/ggT.h

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

4
team.md

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

70
test/ggT/test_ggT.c

@ -0,0 +1,70 @@
#include "unity.h"
#include "ggT.h"
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);
}
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);
}
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);
}
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);
}
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);
}
Loading…
Cancel
Save