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

#include <unity.h>
#include <time.h>
#include <stdlib.h>
#include "../src/error.c"
void setUp(){}
void tearDown(){}
void test_error()
{
/*arrange*/
srand(time(0));
int bound = 1000;
int invalidErrorCodes_1[bound];
int invalidErrorCodesLarge_2[bound];
int invalidErrorCodesLargest_3[bound];
int validErrorCodeUnsuccessfulLogin[bound];
int validErrorCodeMaximumNumberOfAttempts[bound];
int validErrorCodeNoMenuEntryForNumber[bound];
/*new test cases*/
int validErrorCodeNoCustomerDataFile[bound];
int validErrorCodeTooYoung[bound];
int validErrorCodeCreatingFile[bound];
int validErrorCodeForenameTooLong[bound];
int validErrorCodeSurnameTooLong[bound];
int validErrorCodePasswordTooLong[bound];
int validErrorCodeInvalidCharacterForename[bound];
int validErrorCodeInvalidCharacterSurname[bound];
int validErrorCodeTooManyDigits[bound];
for(int i=0;i<bound;++i){
/*1000 numbers in the range from 1 to 2000 */
invalidErrorCodes_1[i] = rand() % 2000 + 1;
/*1000 numbers in the range from 1000.000 to 100.999.999*/
invalidErrorCodesLarge_2[i] = (rand() % 100000000) + 1000000;
/*1000 numbers in the range from 1.000.000.000 to 2.000.000.000*/
invalidErrorCodesLargest_3[i] = (rand() % 1000000001) + 1000000000 ;
/*1000 times -1 in array*/
validErrorCodeUnsuccessfulLogin[i] = -1;
/*1000 times -2 in array*/
validErrorCodeMaximumNumberOfAttempts[i] = -2;
/*1000 times -3 in array*/
validErrorCodeNoMenuEntryForNumber[i] = -3;
validErrorCodeNoCustomerDataFile[i] = -4;
validErrorCodeTooYoung[i] = -5;
validErrorCodeCreatingFile[i] = -6;
validErrorCodeForenameTooLong[i] = -7;
validErrorCodeSurnameTooLong[i] = -8;
validErrorCodePasswordTooLong[i] = -9;
validErrorCodeInvalidCharacterForename[i] = -10;
validErrorCodeInvalidCharacterSurname[i] = -11;
validErrorCodeTooManyDigits[i] = -12;
}
/*act and assertions for invalid error codes*/
for(int i=0;i<bound;++i){
TEST_ASSERT_EQUAL_INT(0,errorMessage(invalidErrorCodes_1[i]));
TEST_ASSERT_EQUAL_INT(0,errorMessage(invalidErrorCodesLarge_2[i]));
TEST_ASSERT_EQUAL_INT(0,errorMessage(invalidErrorCodesLargest_3[i]));
}
/*act and assertions for valid error codes*/
for(int i=0;i<bound;++i){
TEST_ASSERT_EQUAL_INT(-1, errorMessage(validErrorCodeUnsuccessfulLogin[i]));
TEST_ASSERT_EQUAL_INT(-2, errorMessage(validErrorCodeMaximumNumberOfAttempts[i]));
TEST_ASSERT_EQUAL_INT(-3, errorMessage(validErrorCodeNoMenuEntryForNumber[i]));
/*new test cases*/
TEST_ASSERT_EQUAL_INT(-4, errorMessage(validErrorCodeNoCustomerDataFile[i]));
TEST_ASSERT_EQUAL_INT(-5, errorMessage(validErrorCodeTooYoung[i]));
TEST_ASSERT_EQUAL_INT(-6, errorMessage(validErrorCodeCreatingFile[i]));
TEST_ASSERT_EQUAL_INT(-7, errorMessage(validErrorCodeForenameTooLong[i]));
TEST_ASSERT_EQUAL_INT(-8, errorMessage(validErrorCodeSurnameTooLong[i]));
TEST_ASSERT_EQUAL_INT(-9, errorMessage(validErrorCodePasswordTooLong[i]));
TEST_ASSERT_EQUAL_INT(-10, errorMessage(validErrorCodeInvalidCharacterForename[i]));
TEST_ASSERT_EQUAL_INT(-11, errorMessage(validErrorCodeInvalidCharacterSurname[i]));
TEST_ASSERT_EQUAL_INT(-12, errorMessage(validErrorCodeTooManyDigits[i]));
}
}