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.

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