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.

50 lines
1.6 KiB

  1. #include <unity.h>
  2. #include <time.h>
  3. #include <stdlib.h>
  4. #include <Error.h>
  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. for(int i=0;i<bound;++i){
  19. /*1000 numbers in the range from 1 to 2000 */
  20. invalidErrorCodes_1[i] = rand() % 2000 + 1;
  21. /*1000 numbers in the range from 1000.000 to 100.999.999*/
  22. invalidErrorCodesLarge_2[i] = (rand() % 100000000) + 1000000;
  23. /*1000 numbers in the range from 1.000.000.000 to 2.000.000.000*/
  24. invalidErrorCodesLargest_3[i] = (rand() % 1000000001) + 1000000000 ;
  25. /*1000 times -1 in array*/
  26. validErrorCodeUnsuccessfulLogin[i] = -1;
  27. /*1000 times -2 in array*/
  28. validErrorCodeMaximumNumberOfAttempts[i] = -2;
  29. /*1000 times -3 in array*/
  30. validErrorCodeNoMenuEntryForNumber[i] = -3;
  31. }
  32. /*act and assertions for invalid error codes*/
  33. for(int i=0;i<bound;++i){
  34. TEST_ASSERT_EQUAL_INT(0,error(invalidErrorCodes_1[i]));
  35. TEST_ASSERT_EQUAL_INT(0,error(invalidErrorCodesLarge_2[i]));
  36. TEST_ASSERT_EQUAL_INT(0,error(invalidErrorCodesLargest_3[i]));
  37. }
  38. /*act and assertions for valid error codes*/
  39. for(int i=0;i<bound;++i){
  40. TEST_ASSERT_EQUAL_INT(-1, error(validErrorCodeUnsuccessfulLogin[i]));
  41. TEST_ASSERT_EQUAL_INT(-2, error(validErrorCodeMaximumNumberOfAttempts[i]));
  42. TEST_ASSERT_EQUAL_INT(-3, error(validErrorCodeNoMenuEntryForNumber[i]));
  43. }
  44. }