Browse Source

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
parent
commit
082806d359
  1. 25
      src/calculatorGetUserInput.c
  2. 9
      src/calculatorGetUserInput.h
  3. 49
      src/displayMenuCalculator.c
  4. 4
      src/displayMenuCalculator.h
  5. 27
      tests/test_calculatorGetUserInput.c

25
src/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);
}
}

9
src/calculatorGetUserInput.h

@ -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

49
src/displayMenuCalculator.c

@ -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
}
}

4
src/displayMenuCalculator.h

@ -4,8 +4,8 @@
#include<stdio.h>
#include<stdlib.h>
int check(); //int check() is helpful for indirectly testing void displayMenuCalculator()
const int a = 1; // Variable for indirectly testing void displayMenuCalculator()
void displayMenuCalculator(char x);
const int rConst = 1; // RandomConstant created for indirectly testing void displayMenuCalculator()
void displayMenuCalculator(char x); //Displays the correct output, only when x is c.
int operation1 = 1;
int operation2 = 2;

27
tests/test_calculatorGetUserInput.c

@ -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
Loading…
Cancel
Save