You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

237 lines
3.8 KiB

  1. #ifdef TEST
  2. #include "unity.h"
  3. #include "../src/mainMenu.c"
  4. #include "../src/error.c"
  5. #include "../src/loginCustomer.c"
  6. #include "../src/helperFunctions.c"
  7. #include "../src/createCustomer.c"
  8. #include "../src/employeeLogin.c"
  9. #include "../src/createEmployeeAccount.c"
  10. #include "../src/customerMenu.c"
  11. #include "../src/showGeneralInfoEmployee.c"
  12. #include "../src/calculatorAdd.c"
  13. #include "../src/calculatorDivide.c"
  14. #include "../src/calculatorFactorial.c"
  15. #include "../src/calculatorGetUserInput.c"
  16. #include "../src/calculatorGetUserInputFactorial.c"
  17. #include "../src/calculatorMultiply.c"
  18. #include "../src/calculatorSubtract.c"
  19. #include "../src/displayMenuCalculator.c"
  20. void setUp(void)
  21. {
  22. }
  23. void tearDown(void)
  24. {
  25. }
  26. void test_agePermissionValidAge(void)
  27. {
  28. //Test case : 0
  29. /*Arrange*/
  30. int Age = 18;
  31. bool validAgeResult[83];
  32. /*Act*/
  33. for(int i =0; i < 83; i++){
  34. validAgeResult[i]= agePermission(Age + i);
  35. }
  36. /*Assert*/
  37. for(int i=0; i < 83; i++){
  38. TEST_ASSERT_TRUE(validAgeResult[i]);
  39. }
  40. }
  41. void test_agePermissionInvalidAge(void)
  42. {
  43. //Test case : 1
  44. /*Arrange*/
  45. int invalidAge[117];
  46. bool invalidAgeResult[117];
  47. for(int i =-100; i < 18; i++)
  48. {
  49. invalidAge[i+100]= i;
  50. }
  51. /*Act*/
  52. for(int i=0; i < 117; i++)
  53. {
  54. invalidAgeResult[i] = agePermission(invalidAge[i]);
  55. }
  56. /*Assert*/
  57. for(int i=0; i < 117; i++)
  58. {
  59. TEST_ASSERT_FALSE(invalidAgeResult[i]);
  60. }
  61. }
  62. void test_IsInteger(void)
  63. {
  64. //test case 0
  65. /*Arrange*/
  66. char* inputIsInteger[] = {"-10000000","-2000000","-354698","-66667","-7878","-987","-64","-5","0","1","2","10","201","333","4321","56974","698751","7878989","88954621" };
  67. bool inputIsIntegerExpected = true;
  68. /*Act and Assert*/
  69. for(int i=0; i < 19; i++)
  70. {
  71. bool inputIsIntegerResult = checkIfInteger(inputIsInteger[i]);
  72. TEST_ASSERT_EQUAL(inputIsIntegerExpected,inputIsIntegerResult);
  73. }
  74. }
  75. void test_IsNotInteger(void)
  76. {
  77. //test case 1
  78. /*Arrange*/
  79. char* inputIsNotInteger[] = {"0.15","3.141592653589793238","5.3254f","-6.264","-7878.3261","foo","Bar","FIZZ","buzZ","joHN","jAnE","foo-bar","3,15","2k13",""," ","-","+","/*-+.,/=" };
  80. bool inputIsNotIntegerExpected = false;
  81. /*Act and Assert*/
  82. for(int i=0; i<19; i++)
  83. {
  84. bool inputIsNotIntegerResult = checkIfInteger(inputIsNotInteger[i]);
  85. TEST_ASSERT_EQUAL(inputIsNotIntegerExpected,inputIsNotIntegerResult);
  86. }
  87. }
  88. void test_validChoiceInput(void)
  89. {
  90. //test case 0
  91. /*Arrange*/
  92. int validInput[6];
  93. bool validInputExpected = true;
  94. for(int i = 0; i < 6; i++)
  95. {
  96. validInput[i] = i + 1;
  97. }
  98. /*Act and Asssert*/
  99. for(int i = 0; i < 6; i++)
  100. {
  101. bool validInputResult = chooseOption(validInput[i]);
  102. TEST_ASSERT_EQUAL(validInputExpected,validInputResult);
  103. }
  104. }
  105. void test_invalidChoiceInput_firstCase(void)
  106. {
  107. // test case 1
  108. /*Arrange*/
  109. int invalidInput[100];
  110. bool invalidInputExpected = false;
  111. for(int i = -100; i < 1; i++)
  112. {
  113. invalidInput[i+100] = i;
  114. }
  115. /*Act and Assert*/
  116. for(int i = 0; i < 100; i++)
  117. {
  118. bool invalidInputResult = chooseOption(invalidInput[i]);
  119. TEST_ASSERT_EQUAL(invalidInputExpected,invalidInputResult);
  120. }
  121. }
  122. void test_invalidChoiceInput_secondCase(void)
  123. {
  124. // test case 2
  125. /*Arrange*/
  126. int invalidInput[100];
  127. bool invalidInputExpected = false;
  128. for(int i = 0; i < 100; i++)
  129. {
  130. invalidInput[i] = i + 7;
  131. }
  132. /*Act and Assert*/
  133. for(int i = 0; i < 100; i++)
  134. {
  135. bool invalidInputResult = chooseOption(invalidInput[i]);
  136. TEST_ASSERT_EQUAL(invalidInputExpected,invalidInputResult);
  137. }
  138. }
  139. #endif // TEST