Browse Source

Merge commit2?

main
Florian Baeseler 11 months ago
parent
commit
9cf30ffb5f
  1. 1
      build/test/dependencies/casualQuiz.d
  2. BIN
      build/test/out/c/casualQuiz.o
  3. 186
      src/casualQuiz.c
  4. 10
      src/casualQuiz.h
  5. 121
      test/test_casualQuiz.c

1
build/test/dependencies/casualQuiz.d

@ -0,0 +1 @@
build/test/out/c/casualQuiz.o: src/casualQuiz.c src/casualQuiz.h

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

186
src/casualQuiz.c

@ -7,81 +7,139 @@
void casualQuiz() { void casualQuiz() {
printf("Print aus der Funktion Casual Quiz"); printf("Print aus der Funktion Casual Quiz");
int index = 0;
int index = 0;
char* easy_fragen[] = { //eingabe der Fragen in ein Array char* easy_fragen[] = { //eingabe der Fragen in ein Array
"Which Disney character famously leaves a glass shoe behind at a royal ball?", "Which Disney character famously leaves a glass shoe behind at a royal ball?",
"The hammer and sickle are one of the most recognisable symbols of which political ideology?", "The hammer and sickle are one of the most recognisable symbols of which political ideology?",
"Which two words traditionally appear onscreen at the termination of a feature film?",
"A person with well-developed abdominal muscles is said to have a what?",
"A magnet would most likely attract which of the following?",
}; };
char* easy_antworten[][4] = { //Eingabe der zugehörigen Antworten in ein array char* easy_antworten[][4] = { //Eingabe der zugehörigen Antworten in ein array
{"Elsa", "Rapunzel", "Cinderella", "Pocahontas"}, {"Elsa", "Rapunzel", "Cinderella", "Pocahontas"},
{"Republicanism", "Liberalism", "Conservatism", "Communism"}, {"Republicanism", "Liberalism", "Conservatism", "Communism"},
};
int easy_richtigeAntworten[] = { 3,4}; // int, um die jeweils richtige antwort zu zeigen
{"The End", "The Termination", "Pizza's ready", "Hotdog Time"},
{"12-Pack", "6-Pack", "Family Pack", "One-Pack"},
{"Metal", "Plastic", "Humans", "Water"},
int length_frag_array = sizeof(easy_richtigeAntworten)/sizeof(int);
int correct = 0;
int answered = 0;
int *correctP = &correct;
int *answeredP = &answered;
};
int easy_richtigeAntworten[] = { 3,4,1,2,1 }; // int, um die jeweils richtige antwort zu zeigen
activePlaying(easy_fragen, *easy_antworten, easy_richtigeAntworten, length_frag_array, answeredP, correctP);
printf("%d", answered);
return;
int length_frag_array = sizeof(easy_richtigeAntworten) / sizeof(int);
int correct = 0;
int answered = 0;
int* correctP = &correct;
int* answeredP = &answered;
bool already_played = false;
bool end = false;
while (end == false) {
already_played = activePlaying(easy_fragen, *easy_antworten, easy_richtigeAntworten, length_frag_array, answeredP, correctP);
printf("korrekte Antworten: %d\n", correct);
printf("bei: %d beantworteten Fragen", answered);
correct = 0;
answered = 0;
if (already_played == true) {
int sure;
printf("Would you like to play again?\n");
printf("Input 1 to continue Gaming, input 0 to return to the main menu: ");
scanf_s("%d", &sure);
if (sure == 1) printf("Starting the program up again...");
else {
printf("Input not '1', returning to main menu...");
end = true;
}
}
}
return;
}
bool activePlaying(char* fragen[], char* antworten[], int richtige_antwort[], int size, int* answeredP, int* correctP) {
int eingabe;
bool richtig;
for (int i = 0; i < size; i++) {
eingabe = 5;
richtig = false;
FzeigeFragen(fragen, i);
FzeigeAntworten(antworten, i);
printf("Please type in your answer 1,2,3 or 4: ");
eingabe = FEingabeInteger();
richtig = FcheckaufRichtigkeit(eingabe, richtige_antwort, i);
FzaehlernachAuswahl(richtig, answeredP, correctP);
printf("Bool richtig / falsch: %d\n", richtig);
printf(" %d\n", richtige_antwort[i]);
}
return true;
}
void FzeigeFragen(char* fragen[], int index) {
printf("Question: %s\n", fragen[index]);
} }
void activePlaying(char *fragen[], char *antworten[], int richtige_antwort[], int size, int *answeredP, int *correctP ){
int eingabe;
int plus = *answeredP +1;
*answeredP = plus;
for (int i = 0; i < size; i++){
eingabe = 5;
FzeigeFragen(fragen, i);
FzeigeAntworten(antworten, i);
printf("Please type in your answer 1,2,3 or 4: ");
eingabe = FEingabeInteger();
switch(eingabe){
case 1:{
printf("Case 1\n");
if (richtige_antwort[i] == 1) printf("Right Answer, well done.\n");
else printf("Wrong answer.");
break;
}
case 2:{
printf("Case 2\n");
if (richtige_antwort[i] == 2) printf("Right Answer, well done.\n");
else printf("Wrong answer.");
break;
}
case 3:{
printf("Case 3\n");
if (richtige_antwort[i] == 3) printf("Right Answer, well done.\n");
else printf("Wrong answer.");
break;
}
case 4:{
printf("Case 4\n");
if (richtige_antwort[i] == 4) printf("Right Answer, well done.\n");
else printf("Wrong answer.");
break;
}
default:{
printf("Wrong Input!");
break;
}
}
printf(" %d\n", richtige_antwort[i]);
}
void FzeigeAntworten(char* antworten[], int index) {
printf("1) %s\n", antworten[4 * index + 0]);
printf("2) %s\n", antworten[4 * index + 1]);
printf("3) %s\n", antworten[4 * index + 2]);
printf("4) %s\n", antworten[4 * index + 3]);
} }
void FzeigeFragen(char *fragen[], int index){
printf("Question: %s\n", fragen[index]);
int FEingabeInteger() {
int eingabeInt;
scanf_s("%d", &eingabeInt);
return eingabeInt;
} }
void FzeigeAntworten(char *antworten[], int index){
printf("1) %s\n", antworten[4 * index + 0]);
printf("2) %s\n", antworten[4 * index + 1]);
printf("3) %s\n", antworten[4 * index + 2]);
printf("4) %s\n", antworten[4 * index + 3]);
bool FcheckaufRichtigkeit(int eingabe, int richtige_antwort[], int i) {
switch (eingabe) {
case 1: {
printf("Case 1\n");
if (richtige_antwort[i] == 1) {
printf("Right Answer, well done.\n");
return true;
}
else printf("Wrong answer.\n");
break;
}
case 2: {
printf("Case 2\n");
if (richtige_antwort[i] == 2) {
printf("Right Answer, well done.\n");
return true;
}
else printf("Wrong answer.\n");
break;
}
case 3: {
printf("Case 3\n");
if (richtige_antwort[i] == 3) {
printf("Right Answer, well done.\n");
return true;
}
else printf("Wrong answer.\n");
break;
}
case 4: {
printf("Case 4\n");
if (richtige_antwort[i] == 4) {
printf("Right Answer, well done.\n");
return true;
}
else printf("Wrong answer.\n");
break;
}
default: {
printf("Wrong Input!");
return false;
break;
}
}
return false;
} }
int FEingabeInteger(){
int eingabeInt;
scanf_s("%d", &eingabeInt);
return eingabeInt;
void FzaehlernachAuswahl(bool richtig, int* answeredP, int* correctP) {
if (richtig == true) {
int plus = *answeredP + 1;
*answeredP = plus;
int add = *correctP + 1;
*correctP = add;
}
else {
int plus = *answeredP + 1;
*answeredP = plus;
}
return;
} }

10
src/casualQuiz.h

@ -2,9 +2,11 @@
#define CASUALQUIZ_H #define CASUALQUIZ_H
void casualQuiz(); void casualQuiz();
void activePlaying(char *fragen[], char *antworten[], int richtige_antwort[], int size, int *answeredP, int *correctP );
void FzeigeFragen(char *fragen[], int index);
void FzeigeAntworten(char *antworten[], int index);
bool activePlaying(char* fragen[], char* antworten[], int richtige_antwort[], int size, int* answeredP, int* correctP);
void FzeigeFragen(char* fragen[], int index);
void FzeigeAntworten(char* antworten[], int index);
int FEingabeInteger(); int FEingabeInteger();
bool FcheckaufRichtigkeit(int eingabe, int richtige_antwort[], int i);
void FzaehlernachAuswahl(bool richtig, int* answeredP, int* correctP);
#endif // ende CASUALQUIZ_H
#endif // ende CASUALQUIZ_H

121
test/test_casualQuiz.c

@ -0,0 +1,121 @@
#ifdef TEST
#include <stdbool.h>
#include <stdio.h>
#include "unity.h"
#include "casualQuiz.h"
// Test setup function
void setUp(void) {
}
// Test teardown function
void tearDown(void) {
}
void test_FcheckaufRichtigkeit_correct_answer_atIndex1(void){
int TESTeingabe = 1;
int TESTindex = 0;
int TESTrichtige_antwort[]={1};
bool testfall;
testfall = FcheckaufRichtigkeit(TESTeingabe, TESTrichtige_antwort, TESTindex);
TEST_ASSERT_TRUE(testfall == true);
}
void test_FcheckaufRichtigkeit_correct_answer_atIndex2(void){
int TESTeingabe = 2;
int TESTindex = 0;
int TESTrichtige_antwort[]={2};
bool testfall;
testfall = FcheckaufRichtigkeit(TESTeingabe, TESTrichtige_antwort, TESTindex);
TEST_ASSERT_TRUE(testfall == true);
}
void test_FcheckaufRichtigkeit_correct_answer_atIndex3(void){
int TESTeingabe = 3;
int TESTindex = 0;
int TESTrichtige_antwort[]={3};
bool testfall;
testfall = FcheckaufRichtigkeit(TESTeingabe, TESTrichtige_antwort, TESTindex);
TEST_ASSERT_TRUE(testfall == true);
}void test_FcheckaufRichtigkeit_correct_answer_atIndex4(void){
int TESTeingabe = 4;
int TESTindex = 0;
int TESTrichtige_antwort[]={4};
bool testfall;
testfall = FcheckaufRichtigkeit(TESTeingabe, TESTrichtige_antwort, TESTindex);
TEST_ASSERT_TRUE(testfall == true);
}
void test_FcheckaufRichtigkeit_incorrect_input_higher(void){
int TESTeingabe = 5;
int TESTindex = 0;
int TESTrichtige_antwort[]={3};
bool testfall;
testfall = FcheckaufRichtigkeit(TESTeingabe, TESTrichtige_antwort, TESTindex);
TEST_ASSERT_TRUE(testfall != true);
}
void test_FcheckaufRichtigkeit_incorrect_input_lower(void){
int TESTeingabe = -1;
int TESTindex = 0;
int TESTrichtige_antwort[]={3};
bool testfall;
testfall = FcheckaufRichtigkeit(TESTeingabe, TESTrichtige_antwort, TESTindex);
TEST_ASSERT_TRUE(testfall != true);
}
void test_FzaehlernachAuswahl(void){
bool richtig = true;
int correct = 0;
int answered = 0;
int* correctP = &correct;
int* answeredP = &answered;
FzaehlernachAuswahl(richtig, answeredP, correctP);
TEST_ASSERT_EQUAL_INT(1, correct);
TEST_ASSERT_EQUAL_INT(1, answered);
}
void test_FzaehlernachAuswahl_bei1(void){
bool richtig = true;
int correct = 1;
int answered = 1;
int* correctP = &correct;
int* answeredP = &answered;
FzaehlernachAuswahl(richtig, answeredP, correctP);
TEST_ASSERT_EQUAL_INT(2, correct);
TEST_ASSERT_EQUAL_INT(2, answered);
}
void test_FzaehlernachAuswahl_falsch_bei_0(void){
bool richtig = false;
int correct = 0;
int answered = 0;
int* correctP = &correct;
int* answeredP = &answered;
FzaehlernachAuswahl(richtig, answeredP, correctP);
TEST_ASSERT_EQUAL_INT(0, correct);
TEST_ASSERT_EQUAL_INT(1, answered);
}
void test_FzaehlernachAuswahl_falsch_bei_1(void){
bool richtig = false;
int correct = 1;
int answered = 1;
int* correctP = &correct;
int* answeredP = &answered;
FzaehlernachAuswahl(richtig, answeredP, correctP);
TEST_ASSERT_EQUAL_INT(1, correct);
TEST_ASSERT_EQUAL_INT(2, answered);
}
#endif //Test
Loading…
Cancel
Save