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.

226 lines
3.2 KiB

  1. #ifdef TEST
  2. #include "unity.h"
  3. #include "mainMenu.h"
  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 validInputResult[4];
  78. /*Act*/
  79. for(int i = 0; i < 4; i++)
  80. {
  81. validInput[i] = i + 1;
  82. }
  83. for(int i = 0; i < 4; i++)
  84. {
  85. validInputResult[i] = chooseOption(validInput[i]);
  86. }
  87. /*Assert*/
  88. for(int i = 0; i < 4; i++)
  89. {
  90. TEST_ASSERT_TRUE(validInputResult[i]);
  91. }
  92. }
  93. void test_invalidChoiceInput_firstCase(void)
  94. {
  95. // test case 1
  96. /*Arrange*/
  97. int invalidInput[100];
  98. bool invalidInputResult[100];
  99. /*Act*/
  100. for(int i = -100; i < 0; i++)
  101. {
  102. invalidInput[i+100] = i;
  103. }
  104. for(int i = 0; i < 100; i++)
  105. {
  106. invalidInputResult[i] = chooseOption(invalidInput[i]);
  107. }
  108. /*Assert*/
  109. for(int i = 0; i < 100; i++)
  110. {
  111. TEST_ASSERT_FALSE(invalidInputResult[i]);
  112. }
  113. }
  114. void test_invalidChoiceInput_secondCase(void)
  115. {
  116. // test case 2
  117. /*Arrange*/
  118. int invalidInput[100];
  119. bool invalidInputResult[100];
  120. /*Act*/
  121. for(int i = 0; i < 100; i++)
  122. {
  123. invalidInput[i] = i + 5;
  124. }
  125. for(int i = 0; i < 100; i++)
  126. {
  127. invalidInputResult[i] = chooseOption(invalidInput[i]);
  128. }
  129. /*Assert*/
  130. for(int i = 0; i < 100; i++)
  131. {
  132. TEST_ASSERT_FALSE(invalidInputResult[i]);
  133. }
  134. }
  135. #endif // TEST