Browse Source

Unittests, C und H Datei

remotes/origin/Pascal
Pascal Schneider 11 months ago
parent
commit
c35bb6f955
  1. 252
      build/test/cache/test_timequiz.c
  2. BIN
      build/test/out/c/test_timequiz.o
  3. BIN
      build/test/out/c/test_timequiz_runner.o
  4. BIN
      build/test/out/c/timequiz.o
  5. BIN
      build/test/out/test_timequiz.out
  6. 252
      build/test/preprocess/files/test_timequiz.c
  7. 2
      build/test/results/test_casualQuiz.pass
  8. 2
      build/test/results/test_quizduell.pass
  9. 50
      build/test/results/test_timequiz.pass
  10. 2
      build/test/results/test_wwm.pass
  11. 20
      build/test/runners/test_timequiz_runner.c

252
build/test/cache/test_timequiz.c

@ -6,22 +6,14 @@
void setUp(void) { void setUp(void) {
} }
void tearDown(void) { void tearDown(void) {
} }
@ -32,17 +24,9 @@ void test_getRandomQuestionIndex(void) {
int totalQuestions = 10; int totalQuestions = 10;
int index = getRandomQuestionIndex(askedQuestions, totalQuestions); int index = getRandomQuestionIndex(askedQuestions, totalQuestions);
do {if ((index >= 0 && index < totalQuestions)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(24)));}} while(0);
do {if ((index >= 0 && index < totalQuestions)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(16)));}} while(0);
} }
@ -73,3 +57,237 @@ void test_displayQuestion(void) {
displayQuestion(question, answers, correctIndex); displayQuestion(question, answers, correctIndex);
} }
void test_processUserAnswer_correct(void) {
int score = 0;
int totalCorrectAnswers = 0;
char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
int correctIndex = 0;
int userAnswer = 1;
processUserAnswer(userAnswer, correctIndex, &score, &totalCorrectAnswers, answers);
UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((score)), (
((void *)0)
), (UNITY_UINT)(41), UNITY_DISPLAY_STYLE_INT);
UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((totalCorrectAnswers)), (
((void *)0)
), (UNITY_UINT)(42), UNITY_DISPLAY_STYLE_INT);
}
void test_processUserAnswer_wrong(void) {
int score = 0;
int totalCorrectAnswers = 0;
char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
int correctIndex = 0;
int userAnswer = 2;
processUserAnswer(userAnswer, correctIndex, &score, &totalCorrectAnswers, answers);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((score)), (
((void *)0)
), (UNITY_UINT)(52), UNITY_DISPLAY_STYLE_INT);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((totalCorrectAnswers)), (
((void *)0)
), (UNITY_UINT)(53), UNITY_DISPLAY_STYLE_INT);
}
void test_processUserAnswer_correctAnswer_index3(void) {
int score = 0;
int totalCorrectAnswers = 0;
char* answers[] = {"A", "B", "C", "D"};
processUserAnswer(4, 3, &score, &totalCorrectAnswers, answers);
UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((score)), (
((void *)0)
), (UNITY_UINT)(61), UNITY_DISPLAY_STYLE_INT);
UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((totalCorrectAnswers)), (
((void *)0)
), (UNITY_UINT)(62), UNITY_DISPLAY_STYLE_INT);
}
void test_processUserAnswer_correctAnswer_index0(void) {
int score = 0;
int totalCorrectAnswers = 0;
char* answers[] = {"A", "B", "C", "D"};
processUserAnswer(1, 0, &score, &totalCorrectAnswers, answers);
UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((score)), (
((void *)0)
), (UNITY_UINT)(70), UNITY_DISPLAY_STYLE_INT);
UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((totalCorrectAnswers)), (
((void *)0)
), (UNITY_UINT)(71), UNITY_DISPLAY_STYLE_INT);
}
void test_processUserAnswer_wrongAnswer_index3(void) {
int score = 0;
int totalCorrectAnswers = 0;
char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
int correctIndex = 0;
int userAnswer = 4;
processUserAnswer(userAnswer, correctIndex, &score, &totalCorrectAnswers, answers);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((score)), (
((void *)0)
), (UNITY_UINT)(81), UNITY_DISPLAY_STYLE_INT);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((totalCorrectAnswers)), (
((void *)0)
), (UNITY_UINT)(82), UNITY_DISPLAY_STYLE_INT);
}
void test_processUserAnswer_correctAnswer_index1(void) {
int score = 0;
int totalCorrectAnswers = 0;
char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
int correctIndex = 1;
int userAnswer = 2;
processUserAnswer(userAnswer, correctIndex, &score, &totalCorrectAnswers, answers);
UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((score)), (
((void *)0)
), (UNITY_UINT)(92), UNITY_DISPLAY_STYLE_INT);
UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((totalCorrectAnswers)), (
((void *)0)
), (UNITY_UINT)(93), UNITY_DISPLAY_STYLE_INT);
}
void test_processUserAnswer_correctAnswer_index2(void) {
int score = 0;
int totalCorrectAnswers = 0;
char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
int correctIndex = 2;
int userAnswer = 3;
processUserAnswer(userAnswer, correctIndex, &score, &totalCorrectAnswers, answers);
UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((score)), (
((void *)0)
), (UNITY_UINT)(103), UNITY_DISPLAY_STYLE_INT);
UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((totalCorrectAnswers)), (
((void *)0)
), (UNITY_UINT)(104), UNITY_DISPLAY_STYLE_INT);
}
void test_processUserAnswer_wrongAnswer_index1(void) {
int score = 0;
int totalCorrectAnswers = 0;
char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
int correctIndex = 2;
int userAnswer = 2;
processUserAnswer(userAnswer, correctIndex, &score, &totalCorrectAnswers, answers);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((score)), (
((void *)0)
), (UNITY_UINT)(114), UNITY_DISPLAY_STYLE_INT);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((totalCorrectAnswers)), (
((void *)0)
), (UNITY_UINT)(115), UNITY_DISPLAY_STYLE_INT);
}

BIN
build/test/out/c/test_timequiz.o

BIN
build/test/out/c/test_timequiz_runner.o

BIN
build/test/out/c/timequiz.o

BIN
build/test/out/test_timequiz.out

252
build/test/preprocess/files/test_timequiz.c

@ -6,22 +6,14 @@
void setUp(void) { void setUp(void) {
} }
void tearDown(void) { void tearDown(void) {
} }
@ -32,17 +24,9 @@ void test_getRandomQuestionIndex(void) {
int totalQuestions = 10; int totalQuestions = 10;
int index = getRandomQuestionIndex(askedQuestions, totalQuestions); int index = getRandomQuestionIndex(askedQuestions, totalQuestions);
do {if ((index >= 0 && index < totalQuestions)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(24)));}} while(0);
do {if ((index >= 0 && index < totalQuestions)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(16)));}} while(0);
} }
@ -73,3 +57,237 @@ void test_displayQuestion(void) {
displayQuestion(question, answers, correctIndex); displayQuestion(question, answers, correctIndex);
} }
void test_processUserAnswer_correct(void) {
int score = 0;
int totalCorrectAnswers = 0;
char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
int correctIndex = 0;
int userAnswer = 1;
processUserAnswer(userAnswer, correctIndex, &score, &totalCorrectAnswers, answers);
UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((score)), (
((void *)0)
), (UNITY_UINT)(41), UNITY_DISPLAY_STYLE_INT);
UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((totalCorrectAnswers)), (
((void *)0)
), (UNITY_UINT)(42), UNITY_DISPLAY_STYLE_INT);
}
void test_processUserAnswer_wrong(void) {
int score = 0;
int totalCorrectAnswers = 0;
char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
int correctIndex = 0;
int userAnswer = 2;
processUserAnswer(userAnswer, correctIndex, &score, &totalCorrectAnswers, answers);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((score)), (
((void *)0)
), (UNITY_UINT)(52), UNITY_DISPLAY_STYLE_INT);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((totalCorrectAnswers)), (
((void *)0)
), (UNITY_UINT)(53), UNITY_DISPLAY_STYLE_INT);
}
void test_processUserAnswer_correctAnswer_index3(void) {
int score = 0;
int totalCorrectAnswers = 0;
char* answers[] = {"A", "B", "C", "D"};
processUserAnswer(4, 3, &score, &totalCorrectAnswers, answers);
UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((score)), (
((void *)0)
), (UNITY_UINT)(61), UNITY_DISPLAY_STYLE_INT);
UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((totalCorrectAnswers)), (
((void *)0)
), (UNITY_UINT)(62), UNITY_DISPLAY_STYLE_INT);
}
void test_processUserAnswer_correctAnswer_index0(void) {
int score = 0;
int totalCorrectAnswers = 0;
char* answers[] = {"A", "B", "C", "D"};
processUserAnswer(1, 0, &score, &totalCorrectAnswers, answers);
UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((score)), (
((void *)0)
), (UNITY_UINT)(70), UNITY_DISPLAY_STYLE_INT);
UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((totalCorrectAnswers)), (
((void *)0)
), (UNITY_UINT)(71), UNITY_DISPLAY_STYLE_INT);
}
void test_processUserAnswer_wrongAnswer_index3(void) {
int score = 0;
int totalCorrectAnswers = 0;
char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
int correctIndex = 0;
int userAnswer = 4;
processUserAnswer(userAnswer, correctIndex, &score, &totalCorrectAnswers, answers);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((score)), (
((void *)0)
), (UNITY_UINT)(81), UNITY_DISPLAY_STYLE_INT);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((totalCorrectAnswers)), (
((void *)0)
), (UNITY_UINT)(82), UNITY_DISPLAY_STYLE_INT);
}
void test_processUserAnswer_correctAnswer_index1(void) {
int score = 0;
int totalCorrectAnswers = 0;
char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
int correctIndex = 1;
int userAnswer = 2;
processUserAnswer(userAnswer, correctIndex, &score, &totalCorrectAnswers, answers);
UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((score)), (
((void *)0)
), (UNITY_UINT)(92), UNITY_DISPLAY_STYLE_INT);
UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((totalCorrectAnswers)), (
((void *)0)
), (UNITY_UINT)(93), UNITY_DISPLAY_STYLE_INT);
}
void test_processUserAnswer_correctAnswer_index2(void) {
int score = 0;
int totalCorrectAnswers = 0;
char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
int correctIndex = 2;
int userAnswer = 3;
processUserAnswer(userAnswer, correctIndex, &score, &totalCorrectAnswers, answers);
UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((score)), (
((void *)0)
), (UNITY_UINT)(103), UNITY_DISPLAY_STYLE_INT);
UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((totalCorrectAnswers)), (
((void *)0)
), (UNITY_UINT)(104), UNITY_DISPLAY_STYLE_INT);
}
void test_processUserAnswer_wrongAnswer_index1(void) {
int score = 0;
int totalCorrectAnswers = 0;
char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
int correctIndex = 2;
int userAnswer = 2;
processUserAnswer(userAnswer, correctIndex, &score, &totalCorrectAnswers, answers);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((score)), (
((void *)0)
), (UNITY_UINT)(114), UNITY_DISPLAY_STYLE_INT);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((totalCorrectAnswers)), (
((void *)0)
), (UNITY_UINT)(115), UNITY_DISPLAY_STYLE_INT);
}

2
build/test/results/test_casualQuiz.pass

@ -11,4 +11,4 @@
:failed: 0 :failed: 0
:ignored: 0 :ignored: 0
:stdout: [] :stdout: []
:time: 0.01952290000008361
:time: 0.015700600000855047

2
build/test/results/test_quizduell.pass

@ -11,4 +11,4 @@
:failed: 0 :failed: 0
:ignored: 0 :ignored: 0
:stdout: [] :stdout: []
:time: 0.016257900000709924
:time: 0.015422999998918385

50
build/test/results/test_timequiz.pass

@ -4,18 +4,50 @@
:file: test_timequiz.c :file: test_timequiz.c
:successes: :successes:
- :test: test_getRandomQuestionIndex - :test: test_getRandomQuestionIndex
:line: 16
:line: 12
:message: '' :message: ''
:unity_test_time: 0 :unity_test_time: 0
- :test: test_displayQuestion - :test: test_displayQuestion
:line: 27
:line: 19
:message: ''
:unity_test_time: 0
- :test: test_processUserAnswer_correct
:line: 33
:message: ''
:unity_test_time: 0
- :test: test_processUserAnswer_wrong
:line: 45
:message: ''
:unity_test_time: 0
- :test: test_processUserAnswer_correctAnswer_index3
:line: 56
:message: ''
:unity_test_time: 0
- :test: test_processUserAnswer_correctAnswer_index0
:line: 65
:message: ''
:unity_test_time: 0
- :test: test_processUserAnswer_wrongAnswer_index3
:line: 74
:message: ''
:unity_test_time: 0
- :test: test_processUserAnswer_correctAnswer_index1
:line: 85
:message: ''
:unity_test_time: 0
- :test: test_processUserAnswer_correctAnswer_index2
:line: 96
:message: ''
:unity_test_time: 0
- :test: test_processUserAnswer_wrongAnswer_index1
:line: 107
:message: '' :message: ''
:unity_test_time: 0 :unity_test_time: 0
:failures: [] :failures: []
:ignores: [] :ignores: []
:counts: :counts:
:total: 2
:passed: 2
:total: 10
:passed: 10
:failed: 0 :failed: 0
:ignored: 0 :ignored: 0
:stdout: :stdout:
@ -34,4 +66,12 @@
- 2. B - 2. B
- 3. C - 3. C
- 4. D - 4. D
:time: 0.03188090000003285
- Correct!
- 'Wrong! The correct answer is: 1. Paris'
- Correct!
- Correct!
- 'Wrong! The correct answer is: 1. Paris'
- Correct!
- Correct!
- 'Wrong! The correct answer is: 3. Berlin'
:time: 0.033077699999921606

2
build/test/results/test_wwm.pass

@ -11,4 +11,4 @@
:failed: 0 :failed: 0
:ignored: 0 :ignored: 0
:stdout: [] :stdout: []
:time: 0.016452499999104475
:time: 0.015287000000171247

20
build/test/runners/test_timequiz_runner.c

@ -12,6 +12,14 @@ extern void setUp(void);
extern void tearDown(void); extern void tearDown(void);
extern void test_getRandomQuestionIndex(void); extern void test_getRandomQuestionIndex(void);
extern void test_displayQuestion(void); extern void test_displayQuestion(void);
extern void test_processUserAnswer_correct(void);
extern void test_processUserAnswer_wrong(void);
extern void test_processUserAnswer_correctAnswer_index3(void);
extern void test_processUserAnswer_correctAnswer_index0(void);
extern void test_processUserAnswer_wrongAnswer_index3(void);
extern void test_processUserAnswer_correctAnswer_index1(void);
extern void test_processUserAnswer_correctAnswer_index2(void);
extern void test_processUserAnswer_wrongAnswer_index1(void);
/*=======Mock Management=====*/ /*=======Mock Management=====*/
@ -76,8 +84,16 @@ static void run_test(UnityTestFunction func, const char* name, UNITY_LINE_TYPE l
int main(void) int main(void)
{ {
UnityBegin("test_timequiz.c"); UnityBegin("test_timequiz.c");
run_test(test_getRandomQuestionIndex, "test_getRandomQuestionIndex", 16);
run_test(test_displayQuestion, "test_displayQuestion", 27);
run_test(test_getRandomQuestionIndex, "test_getRandomQuestionIndex", 12);
run_test(test_displayQuestion, "test_displayQuestion", 19);
run_test(test_processUserAnswer_correct, "test_processUserAnswer_correct", 33);
run_test(test_processUserAnswer_wrong, "test_processUserAnswer_wrong", 45);
run_test(test_processUserAnswer_correctAnswer_index3, "test_processUserAnswer_correctAnswer_index3", 56);
run_test(test_processUserAnswer_correctAnswer_index0, "test_processUserAnswer_correctAnswer_index0", 65);
run_test(test_processUserAnswer_wrongAnswer_index3, "test_processUserAnswer_wrongAnswer_index3", 74);
run_test(test_processUserAnswer_correctAnswer_index1, "test_processUserAnswer_correctAnswer_index1", 85);
run_test(test_processUserAnswer_correctAnswer_index2, "test_processUserAnswer_correctAnswer_index2", 96);
run_test(test_processUserAnswer_wrongAnswer_index1, "test_processUserAnswer_wrongAnswer_index1", 107);
return UnityEnd(); return UnityEnd();
} }
Loading…
Cancel
Save