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.

212 lines
3.2 KiB

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