Browse Source
merge feature/calculator-get-user-input to feature/display-menu-calculator and implement calculatorGetUserInput() to displayMenuCalculator()
remotes/origin/feature/display-menu-calculator
merge feature/calculator-get-user-input to feature/display-menu-calculator and implement calculatorGetUserInput() to displayMenuCalculator()
remotes/origin/feature/display-menu-calculator
fdai7514
2 years ago
5 changed files with 107 additions and 7 deletions
-
25src/calculatorGetUserInput.c
-
9src/calculatorGetUserInput.h
-
49src/displayMenuCalculator.c
-
4src/displayMenuCalculator.h
-
27tests/test_calculatorGetUserInput.c
@ -0,0 +1,25 @@ |
|||
#include "calculatorGetUserInput.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 allowOnly() //int allowOnly() is helpful for indirectly testing void calculatorGetUserInput(). |
|||
{ |
|||
if(a == 1) //Just a random constant which has a role in testing |
|||
{ |
|||
return 1; |
|||
} |
|||
} |
|||
|
|||
void calculatorGetUserInput(float *num1, float *num2) |
|||
{ |
|||
if (allowOnly() == 1) //only if int allowOnly() returns 1, void calculatorGetUserInput will display the desired output. |
|||
{ |
|||
printf("number1: "); |
|||
scanf("%f", num1); |
|||
printf("number2: "); |
|||
scanf("%f", num2); |
|||
} |
|||
} |
|||
|
|||
|
@ -0,0 +1,9 @@ |
|||
#ifndef CALCULATORGETUSERINPUT_H |
|||
#define CALCULATORGETUSERINPUT_H |
|||
#include<stdio.h> |
|||
#include<stdlib.h> |
|||
void calculatorGetUserInput(float *num1, float *num2); |
|||
int allowOnly(); |
|||
const int a = 1; //Just a random constant which has a role in testing |
|||
|
|||
#endif // CALCULATORGETUSERINPUT_H |
@ -1,31 +1,70 @@ |
|||
#include "displayMenuCalculator.h" |
|||
|
|||
#include "calculatorGetUserInput.c" |
|||
// 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 check() |
|||
{ |
|||
if(a == 1) |
|||
if(rConst == 1)// RandomConstant created for indirectly testing void displayMenuCalculator() |
|||
{ |
|||
return 1; |
|||
} |
|||
} |
|||
|
|||
|
|||
void displayMenuCalculator(char x) |
|||
void displayMenuCalculator(char x) //Displays the correct output, only when x is c. |
|||
{ |
|||
if(x == 'c') |
|||
float num1, num2, answer; //Created for storing numbers for addition, subtraction, multiplication and division and the final answer. |
|||
int choose; |
|||
if(x == 'c') //calculator can be activated by adding 'c' in void displayMenuCalculator() |
|||
{ |
|||
if(check() == 1) |
|||
{ |
|||
{ //The Main Menu of the calculator |
|||
printf(" %d. Add\n", operation1); |
|||
printf(" %d. Subtract\n", operation2); |
|||
printf(" %d. Multiply\n", operation3); |
|||
printf(" %d. Divide\n", operation4); |
|||
printf(" %d. Factorial\n", operation5); |
|||
|
|||
printf("Enter your choice: "); // Takes the choice of operations from the user |
|||
scanf("%d", &choose); // Saves the choice |
|||
|
|||
switch (choose) |
|||
{ //takes user's choice and calls operation-functions accordingly |
|||
case 1: |
|||
calculatorGetUserInput(&num1, &num2); |
|||
//NOT YET IMPLEMENTED |
|||
break; |
|||
|
|||
case 2: |
|||
calculatorGetUserInput(&num1, &num2); |
|||
//NOT YET IMPLEMENTED |
|||
break; |
|||
|
|||
case 3: |
|||
calculatorGetUserInput(&num1, &num2); |
|||
//NOT YET IMPLEMENTED |
|||
break; |
|||
|
|||
case 4: |
|||
calculatorGetUserInput(&num1, &num2); |
|||
//NOT YET IMPLEMENTED |
|||
break; |
|||
|
|||
case 5: |
|||
//NOT YET IMPLEMENTED |
|||
//NOT YET IMPLEMENTED |
|||
break; |
|||
|
|||
default: |
|||
//NOT YET IMPLEMENTED |
|||
return; |
|||
} |
|||
} |
|||
//NEED TO IMPLEMENT |
|||
} |
|||
} |
|||
|
|||
|
|||
|
@ -0,0 +1,27 @@ |
|||
#ifdef TEST |
|||
|
|||
#include "unity.h" |
|||
|
|||
#include "calculatorGetUserInput.c" |
|||
|
|||
// 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 test_calculatorGetUserInput_NeedToImplement(void) |
|||
{ |
|||
int actual, expected; //Arrange |
|||
expected = 1; |
|||
actual = allowOnly(); //Act |
|||
TEST_ASSERT_EQUAL_INT(expected, actual);//Assert |
|||
} |
|||
|
|||
#endif // TEST |
Write
Preview
Loading…
Cancel
Save
Reference in new issue