Browse Source
merge feature/calculator-factorial to feature/display-menu-calculator and implement calculatorFactorial() and default case in displayMenuCalculator()
remotes/origin/feature/display-menu-calculator
merge feature/calculator-factorial to feature/display-menu-calculator and implement calculatorFactorial() and default case in displayMenuCalculator()
remotes/origin/feature/display-menu-calculator
fdai7514
2 years ago
4 changed files with 114 additions and 2 deletions
-
18src/calculatorFactorial.c
-
8src/calculatorFactorial.h
-
6src/displayMenuCalculator.c
-
84tests/test_calculatorFactorial.c
@ -0,0 +1,18 @@ |
|||
#include "calculatorFactorial.h" |
|||
// Note: |
|||
/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. |
|||
If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ |
|||
|
|||
|
|||
int calculatorFactorial(int num) //implement recursion. The function calls itself so many times, till the breaking condition is fulfilled. |
|||
{ |
|||
if (num == 0) //breaking condition |
|||
{ |
|||
return 1; |
|||
} |
|||
else |
|||
{ |
|||
return num * calculatorFactorial(num - 1); //If its not breaking condition, then multiply the number with the same function implemented on the previous number. Eventually it will reach breaking condition. |
|||
} |
|||
} |
|||
|
@ -0,0 +1,8 @@ |
|||
#ifndef CALCULATORFACTORIAL_H |
|||
#define CALCULATORFACTORIAL_H |
|||
|
|||
#include<stdio.h> |
|||
#include<stdlib.h> |
|||
int calculatorFactorial(int num); |
|||
|
|||
#endif // CALCULATORFACTORIAL_H |
@ -0,0 +1,84 @@ |
|||
#ifdef TEST |
|||
|
|||
#include "unity.h" |
|||
|
|||
#include "calculatorFactorial.h" |
|||
|
|||
// Note: |
|||
/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. |
|||
If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ |
|||
|
|||
|
|||
void setUp(void) |
|||
{ |
|||
} |
|||
|
|||
void tearDown(void) |
|||
{ |
|||
} |
|||
|
|||
void test1_calculatorFactorial(void) |
|||
{ |
|||
int num, actual, expected; //Arrange |
|||
num = 1; |
|||
expected = 1; |
|||
actual = calculatorFactorial(num); //Act |
|||
TEST_ASSERT_EQUAL_INT(expected, actual); //Assert |
|||
} |
|||
|
|||
void test2_calculatorFactorial(void) |
|||
{ |
|||
int num, actual, expected; //Arrange |
|||
num = 0; |
|||
expected = 1; |
|||
actual = calculatorFactorial(num); //Act |
|||
TEST_ASSERT_EQUAL_INT(expected, actual); //Assert |
|||
} |
|||
|
|||
void test3_calculatorFactorial(void) |
|||
{ |
|||
int num, actual, expected; //Arrange |
|||
num = 3; |
|||
expected = 6; |
|||
actual = calculatorFactorial(num); //Act |
|||
TEST_ASSERT_EQUAL_INT(expected, actual); //Assert |
|||
} |
|||
|
|||
void test4_calculatorFactorial(void) |
|||
{ |
|||
int num, actual, expected; //Arrange |
|||
num = 5; |
|||
expected = 120; |
|||
actual = calculatorFactorial(num); //Act |
|||
TEST_ASSERT_EQUAL_INT(expected, actual); //Assert |
|||
} |
|||
|
|||
void test5_calculatorFactorial(void) |
|||
{ |
|||
int num, actual, expected; //Arrange |
|||
num = 8; |
|||
expected = 40320; |
|||
actual = calculatorFactorial(num); //Act |
|||
TEST_ASSERT_EQUAL_INT(expected, actual); //Assert |
|||
} |
|||
|
|||
void test6_calculatorFactorial(void) |
|||
{ |
|||
int num, actual, expected; //Arrange |
|||
num = 11; |
|||
expected = 39916800; |
|||
actual = calculatorFactorial(num); //Act |
|||
TEST_ASSERT_EQUAL_INT(expected, actual); //Assert |
|||
} |
|||
|
|||
void test7_calculatorFactorial(void) |
|||
{ |
|||
int num, actual, expected; //Arrange |
|||
num = 10; |
|||
expected = 3628800; |
|||
actual = calculatorFactorial(num); //Act |
|||
TEST_ASSERT_EQUAL_INT(expected, actual); //Assert |
|||
} |
|||
|
|||
|
|||
#endif // TEST |
Write
Preview
Loading…
Cancel
Save
Reference in new issue