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
50 lines
1.6 KiB
#include <unity.h>
|
|
#include <time.h>
|
|
#include <stdlib.h>
|
|
#include <Error.h>
|
|
|
|
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];
|
|
|
|
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;
|
|
}
|
|
|
|
/*act and assertions for invalid error codes*/
|
|
for(int i=0;i<bound;++i){
|
|
TEST_ASSERT_EQUAL_INT(0,error(invalidErrorCodes_1[i]));
|
|
TEST_ASSERT_EQUAL_INT(0,error(invalidErrorCodesLarge_2[i]));
|
|
TEST_ASSERT_EQUAL_INT(0,error(invalidErrorCodesLargest_3[i]));
|
|
}
|
|
/*act and assertions for valid error codes*/
|
|
for(int i=0;i<bound;++i){
|
|
TEST_ASSERT_EQUAL_INT(-1, error(validErrorCodeUnsuccessfulLogin[i]));
|
|
TEST_ASSERT_EQUAL_INT(-2, error(validErrorCodeMaximumNumberOfAttempts[i]));
|
|
TEST_ASSERT_EQUAL_INT(-3, error(validErrorCodeNoMenuEntryForNumber[i]));
|
|
}
|
|
}
|