Browse Source

Merge branch 'ggT' into 'master'

ggT

See merge request fdai8031/cstools101!5
remotes/origin/userinput
fdai7777 11 months ago
parent
commit
8135ae714e
  1. 6
      src/ggT/main.c
  2. 8
      test/ggT/test_ggT.c

6
src/ggT/main.c

@ -3,10 +3,16 @@
#include <stdio.h> #include <stdio.h>
int main(){ int main(){
// Getting user input for the two numbers
printf("Please add the two numbers you want the ggT of:\n"); printf("Please add the two numbers you want the ggT of:\n");
int firstNum = usergetd("first number: ", 0, NULL); int firstNum = usergetd("first number: ", 0, NULL);
int secondNum = usergetd("second number: ", 0, NULL); int secondNum = usergetd("second number: ", 0, NULL);
// Calculating the ggT of those two numbers
int result = ggT(firstNum, secondNum); int result = ggT(firstNum, secondNum);
// Print the result
printf("The ggT of %d and %d is: %d\n", firstNum, secondNum, result); printf("The ggT of %d and %d is: %d\n", firstNum, secondNum, result);
return 0; return 0;

8
test/ggT/test_ggT.c

@ -4,10 +4,15 @@
void setUp(){} void setUp(){}
void tearDown(){} void tearDown(){}
// Test for Common Case
void test_ggTOf5And10(){ void test_ggTOf5And10(){
TEST_ASSERT_EQUAL_INT(5, ggT(5, 10)); TEST_ASSERT_EQUAL_INT(5, ggT(5, 10));
} }
// Tests for Cases with Zero in input
void test_ggTOfFirstNumberZero(){ void test_ggTOfFirstNumberZero(){
TEST_ASSERT_EQUAL_INT(5, ggT(0, 5)); TEST_ASSERT_EQUAL_INT(5, ggT(0, 5));
} }
@ -20,6 +25,9 @@ void test_ggTOfBothNumbersZero(){
TEST_ASSERT_EQUAL_INT(0, ggT(0, 0)); TEST_ASSERT_EQUAL_INT(0, ggT(0, 0));
} }
// Test for edge Case - Coprime Numbers
void test_ggTOfCoprimes(){ void test_ggTOfCoprimes(){
TEST_ASSERT_EQUAL_INT(1, ggT(13, 27)); TEST_ASSERT_EQUAL_INT(1, ggT(13, 27));
} }
Loading…
Cancel
Save