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.

81 lines
3.1 KiB

  1. #include <unity.h>
  2. #include <time.h>
  3. #include <stdlib.h>
  4. #include "../src/error.c"
  5. void setUp(){}
  6. void tearDown(){}
  7. void test_error()
  8. {
  9. /*arrange*/
  10. srand(time(0));
  11. int bound = 1000;
  12. int invalidErrorCodes_1[bound];
  13. int invalidErrorCodesLarge_2[bound];
  14. int invalidErrorCodesLargest_3[bound];
  15. int validErrorCodeUnsuccessfulLogin[bound];
  16. int validErrorCodeMaximumNumberOfAttempts[bound];
  17. int validErrorCodeNoMenuEntryForNumber[bound];
  18. /*new test cases*/
  19. int validErrorCodeNoCustomerDataFile[bound];
  20. int validErrorCodeTooYoung[bound];
  21. int validErrorCodeCreatingFile[bound];
  22. int validErrorCodeForenameTooLong[bound];
  23. int validErrorCodeSurnameTooLong[bound];
  24. int validErrorCodePasswordTooLong[bound];
  25. int validErrorCodeInvalidCharacterForename[bound];
  26. int validErrorCodeInvalidCharacterSurname[bound];
  27. int validErrorCodeTooManyDigits[bound];
  28. for(int i=0;i<bound;++i){
  29. /*1000 numbers in the range from 1 to 2000 */
  30. invalidErrorCodes_1[i] = rand() % 2000 + 1;
  31. /*1000 numbers in the range from 1000.000 to 100.999.999*/
  32. invalidErrorCodesLarge_2[i] = (rand() % 100000000) + 1000000;
  33. /*1000 numbers in the range from 1.000.000.000 to 2.000.000.000*/
  34. invalidErrorCodesLargest_3[i] = (rand() % 1000000001) + 1000000000 ;
  35. /*1000 times -1 in array*/
  36. validErrorCodeUnsuccessfulLogin[i] = -1;
  37. /*1000 times -2 in array*/
  38. validErrorCodeMaximumNumberOfAttempts[i] = -2;
  39. /*1000 times -3 in array*/
  40. validErrorCodeNoMenuEntryForNumber[i] = -3;
  41. validErrorCodeNoCustomerDataFile[i] = -4;
  42. validErrorCodeTooYoung[i] = -5;
  43. validErrorCodeCreatingFile[i] = -6;
  44. validErrorCodeForenameTooLong[i] = -7;
  45. validErrorCodeSurnameTooLong[i] = -8;
  46. validErrorCodePasswordTooLong[i] = -9;
  47. validErrorCodeInvalidCharacterForename[i] = -10;
  48. validErrorCodeInvalidCharacterSurname[i] = -11;
  49. validErrorCodeTooManyDigits[i] = -12;
  50. }
  51. /*act and assertions for invalid error codes*/
  52. for(int i=0;i<bound;++i){
  53. TEST_ASSERT_EQUAL_INT(0,errorMessage(invalidErrorCodes_1[i]));
  54. TEST_ASSERT_EQUAL_INT(0,errorMessage(invalidErrorCodesLarge_2[i]));
  55. TEST_ASSERT_EQUAL_INT(0,errorMessage(invalidErrorCodesLargest_3[i]));
  56. }
  57. /*act and assertions for valid error codes*/
  58. for(int i=0;i<bound;++i){
  59. TEST_ASSERT_EQUAL_INT(-1, errorMessage(validErrorCodeUnsuccessfulLogin[i]));
  60. TEST_ASSERT_EQUAL_INT(-2, errorMessage(validErrorCodeMaximumNumberOfAttempts[i]));
  61. TEST_ASSERT_EQUAL_INT(-3, errorMessage(validErrorCodeNoMenuEntryForNumber[i]));
  62. /*new test cases*/
  63. TEST_ASSERT_EQUAL_INT(-4, errorMessage(validErrorCodeNoCustomerDataFile[i]));
  64. TEST_ASSERT_EQUAL_INT(-5, errorMessage(validErrorCodeTooYoung[i]));
  65. TEST_ASSERT_EQUAL_INT(-6, errorMessage(validErrorCodeCreatingFile[i]));
  66. TEST_ASSERT_EQUAL_INT(-7, errorMessage(validErrorCodeForenameTooLong[i]));
  67. TEST_ASSERT_EQUAL_INT(-8, errorMessage(validErrorCodeSurnameTooLong[i]));
  68. TEST_ASSERT_EQUAL_INT(-9, errorMessage(validErrorCodePasswordTooLong[i]));
  69. TEST_ASSERT_EQUAL_INT(-10, errorMessage(validErrorCodeInvalidCharacterForename[i]));
  70. TEST_ASSERT_EQUAL_INT(-11, errorMessage(validErrorCodeInvalidCharacterSurname[i]));
  71. TEST_ASSERT_EQUAL_INT(-12, errorMessage(validErrorCodeTooManyDigits[i]));
  72. }
  73. }