diff --git a/src/calculatorGetUserInput.c b/src/calculatorGetUserInput.c new file mode 100644 index 0000000..8f39090 --- /dev/null +++ b/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); + } +} + + diff --git a/src/calculatorGetUserInput.h b/src/calculatorGetUserInput.h new file mode 100644 index 0000000..9ec1d32 --- /dev/null +++ b/src/calculatorGetUserInput.h @@ -0,0 +1,9 @@ +#ifndef CALCULATORGETUSERINPUT_H +#define CALCULATORGETUSERINPUT_H +#include +#include +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 diff --git a/src/displayMenuCalculator.c b/src/displayMenuCalculator.c index 872c724..ef34b25 100644 --- a/src/displayMenuCalculator.c +++ b/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 } } + diff --git a/src/displayMenuCalculator.h b/src/displayMenuCalculator.h index 1afbc55..355a3d2 100644 --- a/src/displayMenuCalculator.h +++ b/src/displayMenuCalculator.h @@ -4,8 +4,8 @@ #include #include 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; diff --git a/tests/test_calculatorGetUserInput.c b/tests/test_calculatorGetUserInput.c new file mode 100644 index 0000000..57b4e71 --- /dev/null +++ b/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