Browse Source

refactoring: const in jede Datei hinzugefügt

remotes/origin/Pascal
Pascal Schneider 11 months ago
parent
commit
e031643563
  1. 20
      build/test/cache/test_timequiz.c
  2. BIN
      build/test/out/c/test_timequiz.o
  3. BIN
      build/test/out/c/timequiz.o
  4. BIN
      build/test/out/test_casualQuiz.out
  5. BIN
      build/test/out/test_quizduell.out
  6. BIN
      build/test/out/test_timequiz.out
  7. BIN
      build/test/out/test_wwm.out
  8. 20
      build/test/preprocess/files/test_timequiz.c
  9. 2
      build/test/results/test_casualQuiz.pass
  10. 2
      build/test/results/test_quizduell.pass
  11. 2
      build/test/results/test_timequiz.pass
  12. 2
      build/test/results/test_wwm.pass
  13. 10
      src/timequiz.c
  14. 20
      test/test_timequiz.c

20
build/test/cache/test_timequiz.c

@ -34,9 +34,9 @@ void test_getRandomQuestionIndex(void) {
void test_displayQuestion(void) {
char* question = "Test Question";
const char* question = "Test Question";
char* answers[] = {"A", "B", "C", "D"};
const char* answers[] = {"A", "B", "C", "D"};
int correctIndex = 0;
@ -66,7 +66,7 @@ void test_processUserAnswer_correct(void) {
int totalCorrectAnswers = 0;
char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
const char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
int correctIndex = 0;
@ -98,7 +98,7 @@ void test_processUserAnswer_wrong(void) {
int totalCorrectAnswers = 0;
char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
const char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
int correctIndex = 0;
@ -128,7 +128,7 @@ void test_processUserAnswer_correctAnswer_index3(void) {
int totalCorrectAnswers = 0;
char* answers[] = {"A", "B", "C", "D"};
const char* answers[] = {"A", "B", "C", "D"};
processUserAnswer(4, 3, &score, &totalCorrectAnswers, answers);
@ -154,7 +154,7 @@ void test_processUserAnswer_correctAnswer_index0(void) {
int totalCorrectAnswers = 0;
char* answers[] = {"A", "B", "C", "D"};
const char* answers[] = {"A", "B", "C", "D"};
processUserAnswer(1, 0, &score, &totalCorrectAnswers, answers);
@ -180,7 +180,7 @@ void test_processUserAnswer_wrongAnswer_index3(void) {
int totalCorrectAnswers = 0;
char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
const char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
int correctIndex = 0;
@ -210,7 +210,7 @@ void test_processUserAnswer_correctAnswer_index1(void) {
int totalCorrectAnswers = 0;
char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
const char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
int correctIndex = 1;
@ -240,7 +240,7 @@ void test_processUserAnswer_correctAnswer_index2(void) {
int totalCorrectAnswers = 0;
char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
const char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
int correctIndex = 2;
@ -270,7 +270,7 @@ void test_processUserAnswer_wrongAnswer_index1(void) {
int totalCorrectAnswers = 0;
char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
const char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
int correctIndex = 2;

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

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

BIN
build/test/out/test_casualQuiz.out

BIN
build/test/out/test_quizduell.out

BIN
build/test/out/test_timequiz.out

BIN
build/test/out/test_wwm.out

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

@ -34,9 +34,9 @@ void test_getRandomQuestionIndex(void) {
void test_displayQuestion(void) {
char* question = "Test Question";
const char* question = "Test Question";
char* answers[] = {"A", "B", "C", "D"};
const char* answers[] = {"A", "B", "C", "D"};
int correctIndex = 0;
@ -66,7 +66,7 @@ void test_processUserAnswer_correct(void) {
int totalCorrectAnswers = 0;
char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
const char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
int correctIndex = 0;
@ -98,7 +98,7 @@ void test_processUserAnswer_wrong(void) {
int totalCorrectAnswers = 0;
char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
const char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
int correctIndex = 0;
@ -128,7 +128,7 @@ void test_processUserAnswer_correctAnswer_index3(void) {
int totalCorrectAnswers = 0;
char* answers[] = {"A", "B", "C", "D"};
const char* answers[] = {"A", "B", "C", "D"};
processUserAnswer(4, 3, &score, &totalCorrectAnswers, answers);
@ -154,7 +154,7 @@ void test_processUserAnswer_correctAnswer_index0(void) {
int totalCorrectAnswers = 0;
char* answers[] = {"A", "B", "C", "D"};
const char* answers[] = {"A", "B", "C", "D"};
processUserAnswer(1, 0, &score, &totalCorrectAnswers, answers);
@ -180,7 +180,7 @@ void test_processUserAnswer_wrongAnswer_index3(void) {
int totalCorrectAnswers = 0;
char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
const char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
int correctIndex = 0;
@ -210,7 +210,7 @@ void test_processUserAnswer_correctAnswer_index1(void) {
int totalCorrectAnswers = 0;
char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
const char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
int correctIndex = 1;
@ -240,7 +240,7 @@ void test_processUserAnswer_correctAnswer_index2(void) {
int totalCorrectAnswers = 0;
char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
const char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
int correctIndex = 2;
@ -270,7 +270,7 @@ void test_processUserAnswer_wrongAnswer_index1(void) {
int totalCorrectAnswers = 0;
char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
const char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
int correctIndex = 2;

2
build/test/results/test_casualQuiz.pass

@ -11,4 +11,4 @@
:failed: 0
:ignored: 0
:stdout: []
:time: 1.3471671999996033
:time: 0.014675799999167793

2
build/test/results/test_quizduell.pass

@ -11,4 +11,4 @@
:failed: 0
:ignored: 0
:stdout: []
:time: 1.0948776999994152
:time: 0.014967400000386988

2
build/test/results/test_timequiz.pass

@ -74,4 +74,4 @@
- Correct!
- Correct!
- 'Wrong! The correct answer is: 3. Berlin'
:time: 0.9529290000009496
:time: 0.8400412000009965

2
build/test/results/test_wwm.pass

@ -11,4 +11,4 @@
:failed: 0
:ignored: 0
:stdout: []
:time: 0.7791643000000477
:time: 0.015467199998965953

10
src/timequiz.c

@ -12,9 +12,9 @@ void timequiz();
int getRandomQuestionIndex(int askedQuestions[], int totalQuestions);
void displayQuestion(char* question, char* answers[], int correctIndex);
void displayQuestion(const char* question,const char* answers[], int correctIndex);
void processUserAnswer(int userAnswer, int correctIndex, int* score, int* totalCorrectAnswers, char* answers[]);
void processUserAnswer(int userAnswer, int correctIndex, int* score, int* totalCorrectAnswers,const char* answers[]);
int isValidAnswer(int userAnswer);
@ -115,7 +115,7 @@ void timequiz() {
for (int i = 0; i < sizeof(questions) / sizeof(questions[0]); i++) {
int j = rand() % 4;
char* temp = answers[i][0];
const char* temp = answers[i][0];
answers[i][0] = answers[i][j];
answers[i][j] = temp;
@ -181,14 +181,14 @@ int getRandomQuestionIndex(int askedQuestions[], int totalQuestions) {
return questionIndex;
}
//Frage anzeigen
void displayQuestion(char* question, char* answers[], int correctIndex) {
void displayQuestion(const char* question,const char* answers[], int correctIndex) {
printf("\nQuestion: %s\n", question);
for (int i = 0; i < 4; i++) {
printf("%d. %s\n", i + 1, answers[i]);
}
}
//User-Eingabe Verarbeitung
void processUserAnswer(int userAnswer, int correctIndex, int* score, int* totalCorrectAnswers, char* answers[]) {
void processUserAnswer(int userAnswer, int correctIndex, int* score, int* totalCorrectAnswers,const char* answers[]) {
if (userAnswer == correctIndex + 1) {
printf("Correct!\n");
(*score)++;

20
test/test_timequiz.c

@ -17,8 +17,8 @@ void test_getRandomQuestionIndex(void) {
}
void test_displayQuestion(void) {
char* question = "Test Question";
char* answers[] = {"A", "B", "C", "D"};
const char* question = "Test Question";
const char* answers[] = {"A", "B", "C", "D"};
int correctIndex = 0;
printf("\nExpected Output:\n");
printf("Question: %s\n", question);
@ -33,7 +33,7 @@ void test_displayQuestion(void) {
void test_processUserAnswer_correct(void) {
int score = 0;
int totalCorrectAnswers = 0;
char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
const char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
int correctIndex = 0;
int userAnswer = 1;
@ -45,7 +45,7 @@ void test_processUserAnswer_correct(void) {
void test_processUserAnswer_wrong(void) {
int score = 0;
int totalCorrectAnswers = 0;
char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
const char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
int correctIndex = 0;
int userAnswer = 2; // Assuming user selects the second option
processUserAnswer(userAnswer, correctIndex, &score, &totalCorrectAnswers, answers);
@ -56,7 +56,7 @@ void test_processUserAnswer_wrong(void) {
void test_processUserAnswer_correctAnswer_index3(void) {
int score = 0;
int totalCorrectAnswers = 0;
char* answers[] = {"A", "B", "C", "D"};
const char* answers[] = {"A", "B", "C", "D"};
processUserAnswer(4, 3, &score, &totalCorrectAnswers, answers);
TEST_ASSERT_EQUAL_INT(1, score);
TEST_ASSERT_EQUAL_INT(1, totalCorrectAnswers);
@ -65,7 +65,7 @@ void test_processUserAnswer_correctAnswer_index3(void) {
void test_processUserAnswer_correctAnswer_index0(void) {
int score = 0;
int totalCorrectAnswers = 0;
char* answers[] = {"A", "B", "C", "D"};
const char* answers[] = {"A", "B", "C", "D"};
processUserAnswer(1, 0, &score, &totalCorrectAnswers, answers);
TEST_ASSERT_EQUAL_INT(1, score);
TEST_ASSERT_EQUAL_INT(1, totalCorrectAnswers);
@ -74,7 +74,7 @@ void test_processUserAnswer_correctAnswer_index0(void) {
void test_processUserAnswer_wrongAnswer_index3(void) {
int score = 0;
int totalCorrectAnswers = 0;
char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
const char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
int correctIndex = 0;
int userAnswer = 4; // Assuming user selects the fourth option
processUserAnswer(userAnswer, correctIndex, &score, &totalCorrectAnswers, answers);
@ -85,7 +85,7 @@ void test_processUserAnswer_wrongAnswer_index3(void) {
void test_processUserAnswer_correctAnswer_index1(void) {
int score = 0;
int totalCorrectAnswers = 0;
char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
const char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
int correctIndex = 1;
int userAnswer = 2; // Assuming user selects the second option
processUserAnswer(userAnswer, correctIndex, &score, &totalCorrectAnswers, answers);
@ -96,7 +96,7 @@ void test_processUserAnswer_correctAnswer_index1(void) {
void test_processUserAnswer_correctAnswer_index2(void) {
int score = 0;
int totalCorrectAnswers = 0;
char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
const char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
int correctIndex = 2;
int userAnswer = 3; // Assuming user selects the third option
processUserAnswer(userAnswer, correctIndex, &score, &totalCorrectAnswers, answers);
@ -107,7 +107,7 @@ void test_processUserAnswer_correctAnswer_index2(void) {
void test_processUserAnswer_wrongAnswer_index1(void) {
int score = 0;
int totalCorrectAnswers = 0;
char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
const char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
int correctIndex = 2;
int userAnswer = 2; // Assuming user selects the second option
processUserAnswer(userAnswer, correctIndex, &score, &totalCorrectAnswers, answers);

Loading…
Cancel
Save