Browse Source

refactoring: Modified unit test for function error(). Replaced variables with arras and consecutive execution of assertion calls with for-loops and added test cases for valid error codes.

remotes/origin/feature/error-handling
fdai7057 2 years ago
parent
commit
41f0b11f71
  1. 74
      tests/build/test/cache/test_Error.c
  2. BIN
      tests/build/test/out/c/test_Error.o
  3. BIN
      tests/build/test/out/test_Error.out
  4. 74
      tests/build/test/preprocess/files/test_Error.c
  5. 5992
      tests/build/test/results/test_Error.pass
  6. 56
      tests/test/test_Error.c

74
tests/build/test/cache/test_Error.c

@ -20,94 +20,98 @@ void test_error()
int bound = 1000;
int val1,val2,val3,val4,val5,val6,val7,val8,val9,val10;
int invalidErrorCodes_1[bound];
int invalidErrorCodesLarge_2[bound];
int invalidErrorCodesLargest_3[bound];
val1 = rand() % 1000 + 1;
int validErrorCodeUnsuccessfulLogin[bound];
val2 = rand() % 1000 + 1;
int validErrorCodeMaximumNumberOfAttempts[bound];
val3 = rand() % 1000 + 1;
int validErrorCodeNoMenuEntryForNumber[bound];
val4 = rand() % 1000 + 1;
val5 = rand() % 1000 + 1;
val6 = rand() % 1000 + 1;
for(int i=0;i<bound;++i){
val7 = rand() % 1000 + 1;
val8 = rand() % 1000 + 1;
val9 = rand() % 1000 + 1;
invalidErrorCodes_1[i] = rand() % 2000 + 1;
val10 = rand() % 1000 + 1;
invalidErrorCodesLarge_2[i] = (rand() % 100000000) + 1000000;
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((error(val1))), (
invalidErrorCodesLargest_3[i] = (rand() % 1000000001) + 1000000000 ;
((void *)0)
), (UNITY_UINT)(30), UNITY_DISPLAY_STYLE_INT);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((error(val2))), (
validErrorCodeUnsuccessfulLogin[i] = -1;
((void *)0)
), (UNITY_UINT)(31), UNITY_DISPLAY_STYLE_INT);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((error(val3))), (
validErrorCodeMaximumNumberOfAttempts[i] = -2;
((void *)0)
), (UNITY_UINT)(32), UNITY_DISPLAY_STYLE_INT);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((error(val4))), (
validErrorCodeNoMenuEntryForNumber[i] = -3;
}
((void *)0)
), (UNITY_UINT)(33), UNITY_DISPLAY_STYLE_INT);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((error(val5))), (
for(int i=0;i<bound;++i){
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((error(invalidErrorCodes_1[i]))), (
((void *)0)
), (UNITY_UINT)(34), UNITY_DISPLAY_STYLE_INT);
), (UNITY_UINT)(40), UNITY_DISPLAY_STYLE_INT);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((error(val6))), (
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((error(invalidErrorCodesLarge_2[i]))), (
((void *)0)
), (UNITY_UINT)(35), UNITY_DISPLAY_STYLE_INT);
), (UNITY_UINT)(41), UNITY_DISPLAY_STYLE_INT);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((error(val7))), (
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((error(invalidErrorCodesLargest_3[i]))), (
((void *)0)
), (UNITY_UINT)(36), UNITY_DISPLAY_STYLE_INT);
), (UNITY_UINT)(42), UNITY_DISPLAY_STYLE_INT);
}
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((error(val8))), (
for(int i=0;i<bound;++i){
UnityAssertEqualNumber((UNITY_INT)((-1)), (UNITY_INT)((error(validErrorCodeUnsuccessfulLogin[i]))), (
((void *)0)
), (UNITY_UINT)(37), UNITY_DISPLAY_STYLE_INT);
), (UNITY_UINT)(46), UNITY_DISPLAY_STYLE_INT);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((error(val9))), (
UnityAssertEqualNumber((UNITY_INT)((-2)), (UNITY_INT)((error(validErrorCodeMaximumNumberOfAttempts[i]))), (
((void *)0)
), (UNITY_UINT)(38), UNITY_DISPLAY_STYLE_INT);
), (UNITY_UINT)(47), UNITY_DISPLAY_STYLE_INT);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((error(val10))), (
UnityAssertEqualNumber((UNITY_INT)((-3)), (UNITY_INT)((error(validErrorCodeNoMenuEntryForNumber[i]))), (
((void *)0)
), (UNITY_UINT)(39), UNITY_DISPLAY_STYLE_INT);
), (UNITY_UINT)(48), UNITY_DISPLAY_STYLE_INT);
}
}

BIN
tests/build/test/out/c/test_Error.o

BIN
tests/build/test/out/test_Error.out

74
tests/build/test/preprocess/files/test_Error.c

@ -20,94 +20,98 @@ void test_error()
int bound = 1000;
int val1,val2,val3,val4,val5,val6,val7,val8,val9,val10;
int invalidErrorCodes_1[bound];
int invalidErrorCodesLarge_2[bound];
int invalidErrorCodesLargest_3[bound];
val1 = rand() % 1000 + 1;
int validErrorCodeUnsuccessfulLogin[bound];
val2 = rand() % 1000 + 1;
int validErrorCodeMaximumNumberOfAttempts[bound];
val3 = rand() % 1000 + 1;
int validErrorCodeNoMenuEntryForNumber[bound];
val4 = rand() % 1000 + 1;
val5 = rand() % 1000 + 1;
val6 = rand() % 1000 + 1;
for(int i=0;i<bound;++i){
val7 = rand() % 1000 + 1;
val8 = rand() % 1000 + 1;
val9 = rand() % 1000 + 1;
invalidErrorCodes_1[i] = rand() % 2000 + 1;
val10 = rand() % 1000 + 1;
invalidErrorCodesLarge_2[i] = (rand() % 100000000) + 1000000;
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((error(val1))), (
invalidErrorCodesLargest_3[i] = (rand() % 1000000001) + 1000000000 ;
((void *)0)
), (UNITY_UINT)(30), UNITY_DISPLAY_STYLE_INT);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((error(val2))), (
validErrorCodeUnsuccessfulLogin[i] = -1;
((void *)0)
), (UNITY_UINT)(31), UNITY_DISPLAY_STYLE_INT);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((error(val3))), (
validErrorCodeMaximumNumberOfAttempts[i] = -2;
((void *)0)
), (UNITY_UINT)(32), UNITY_DISPLAY_STYLE_INT);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((error(val4))), (
validErrorCodeNoMenuEntryForNumber[i] = -3;
}
((void *)0)
), (UNITY_UINT)(33), UNITY_DISPLAY_STYLE_INT);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((error(val5))), (
for(int i=0;i<bound;++i){
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((error(invalidErrorCodes_1[i]))), (
((void *)0)
), (UNITY_UINT)(34), UNITY_DISPLAY_STYLE_INT);
), (UNITY_UINT)(40), UNITY_DISPLAY_STYLE_INT);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((error(val6))), (
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((error(invalidErrorCodesLarge_2[i]))), (
((void *)0)
), (UNITY_UINT)(35), UNITY_DISPLAY_STYLE_INT);
), (UNITY_UINT)(41), UNITY_DISPLAY_STYLE_INT);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((error(val7))), (
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((error(invalidErrorCodesLargest_3[i]))), (
((void *)0)
), (UNITY_UINT)(36), UNITY_DISPLAY_STYLE_INT);
), (UNITY_UINT)(42), UNITY_DISPLAY_STYLE_INT);
}
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((error(val8))), (
for(int i=0;i<bound;++i){
UnityAssertEqualNumber((UNITY_INT)((-1)), (UNITY_INT)((error(validErrorCodeUnsuccessfulLogin[i]))), (
((void *)0)
), (UNITY_UINT)(37), UNITY_DISPLAY_STYLE_INT);
), (UNITY_UINT)(46), UNITY_DISPLAY_STYLE_INT);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((error(val9))), (
UnityAssertEqualNumber((UNITY_INT)((-2)), (UNITY_INT)((error(validErrorCodeMaximumNumberOfAttempts[i]))), (
((void *)0)
), (UNITY_UINT)(38), UNITY_DISPLAY_STYLE_INT);
), (UNITY_UINT)(47), UNITY_DISPLAY_STYLE_INT);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((error(val10))), (
UnityAssertEqualNumber((UNITY_INT)((-3)), (UNITY_INT)((error(validErrorCodeNoMenuEntryForNumber[i]))), (
((void *)0)
), (UNITY_UINT)(39), UNITY_DISPLAY_STYLE_INT);
), (UNITY_UINT)(48), UNITY_DISPLAY_STYLE_INT);
}
}

5992
tests/build/test/results/test_Error.pass
File diff suppressed because it is too large
View File

56
tests/test/test_Error.c

@ -12,29 +12,39 @@ void test_error()
/*arrange*/
srand(time(0));
int bound = 1000;
int val1,val2,val3,val4,val5,val6,val7,val8,val9,val10;
int invalidErrorCodes_1[bound];
int invalidErrorCodesLarge_2[bound];
int invalidErrorCodesLargest_3[bound];
/*act*/
val1 = rand() % 1000 + 1;
val2 = rand() % 1000 + 1;
val3 = rand() % 1000 + 1;
val4 = rand() % 1000 + 1;
val5 = rand() % 1000 + 1;
val6 = rand() % 1000 + 1;
val7 = rand() % 1000 + 1;
val8 = rand() % 1000 + 1;
val9 = rand() % 1000 + 1;
val10 = rand() % 1000 + 1;
int validErrorCodeUnsuccessfulLogin[bound];
int validErrorCodeMaximumNumberOfAttempts[bound];
int validErrorCodeNoMenuEntryForNumber[bound];
/*assertions*/
TEST_ASSERT_EQUAL_INT(0,error(val1));
TEST_ASSERT_EQUAL_INT(0,error(val2));
TEST_ASSERT_EQUAL_INT(0,error(val3));
TEST_ASSERT_EQUAL_INT(0,error(val4));
TEST_ASSERT_EQUAL_INT(0,error(val5));
TEST_ASSERT_EQUAL_INT(0,error(val6));
TEST_ASSERT_EQUAL_INT(0,error(val7));
TEST_ASSERT_EQUAL_INT(0,error(val8));
TEST_ASSERT_EQUAL_INT(0,error(val9));
TEST_ASSERT_EQUAL_INT(0,error(val10));
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]));
}
}
Loading…
Cancel
Save