Browse Source

Merge branch 'ggT' into 'master'

ggT

See merge request fdai8031/cstools101!4
remotes/origin/userinput
fdai7777 11 months ago
parent
commit
21ae855d74
  1. 14
      src/ggT/main.c
  2. 55
      test/ggT/test_ggT.c

14
src/ggT/main.c

@ -0,0 +1,14 @@
#include "ggT.h"
#include "../userinput.h"
#include <stdio.h>
int main(){
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);
int result = ggT(firstNum, secondNum);
printf("The ggT of %d and %d is: %d\n", firstNum, secondNum, result);
return 0;
}

55
test/ggT/test_ggT.c

@ -5,66 +5,21 @@ void setUp(){}
void tearDown(){} void tearDown(){}
void test_ggTOf5And10(){ 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_ASSERT_EQUAL_INT(5, ggT(5, 10));
} }
void test_ggTOfFirstNumberZero(){ 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);
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(){ 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_ASSERT_EQUAL_INT(1, ggT(13, 27));
} }
Loading…
Cancel
Save