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.
142 lines
7.4 KiB
142 lines
7.4 KiB
#ifdef TEST
|
|
|
|
#include <stdlib.h>
|
|
#include "unity.h"
|
|
#include "quizduell.h"
|
|
|
|
void setUp(void) {}
|
|
|
|
void tearDown(void) {}
|
|
|
|
void test_erstelleFrage(void) {
|
|
QuizFrage testFrage = erstelleFrage("Testfrage", "AntwortA", "AntwortB", "AntwortC", "AntwortD", 'A');
|
|
|
|
TEST_ASSERT_EQUAL_STRING("Testfrage", testFrage.frage);
|
|
TEST_ASSERT_EQUAL_STRING("AntwortA", testFrage.antwortA);
|
|
TEST_ASSERT_EQUAL_STRING("AntwortB", testFrage.antwortB);
|
|
TEST_ASSERT_EQUAL_STRING("AntwortC", testFrage.antwortC);
|
|
TEST_ASSERT_EQUAL_STRING("AntwortD", testFrage.antwortD);
|
|
TEST_ASSERT_EQUAL_CHAR('A', testFrage.korrekteAntwort);
|
|
}
|
|
|
|
void test_CookingFragen(void) {
|
|
Kategorie kategorien[MAX_CATEGORIES];
|
|
|
|
kategorien[1].fragen = (QuizFrage*)malloc(MAX_QUESTIONS_PER_CATEGORY * sizeof(QuizFrage));
|
|
|
|
kategorien[1].fragen[0] = erstelleFrage("Which Ingredient is used traditionally for Pesto?", "Tomatoes", "Basil", "Spinach", "Oregano", 'B');
|
|
kategorien[1].fragen[1] = erstelleFrage("Which meal is known for its usage of rice?", "Lasagna", "Sushi", "Pizza", "Hamburger", 'B');
|
|
kategorien[1].fragen[2] = erstelleFrage("Which color has a ripe banana?", "Red", "Green", "Yellow", "Orange", 'C');
|
|
|
|
kategorien[1].anzahlFragen = MAX_QUESTIONS_PER_CATEGORY;
|
|
kategorien[1].joker = 1;
|
|
|
|
TEST_ASSERT_EQUAL_STRING("Which Ingredient is used traditionally for Pesto?", kategorien[1].fragen[0].frage);
|
|
TEST_ASSERT_EQUAL_STRING("Tomatoes", kategorien[1].fragen[0].antwortA);
|
|
TEST_ASSERT_EQUAL_STRING("Basil", kategorien[1].fragen[0].antwortB);
|
|
TEST_ASSERT_EQUAL_STRING("Spinach", kategorien[1].fragen[0].antwortC);
|
|
TEST_ASSERT_EQUAL_STRING("Oregano", kategorien[1].fragen[0].antwortD);
|
|
TEST_ASSERT_EQUAL_CHAR('B', kategorien[1].fragen[0].korrekteAntwort);
|
|
|
|
|
|
free(kategorien[1].fragen);
|
|
}
|
|
void test_MountainsFragen(void) {
|
|
Kategorie kategorien[MAX_CATEGORIES];
|
|
|
|
kategorien[0].fragen = (QuizFrage*)malloc(MAX_QUESTIONS_PER_CATEGORY * sizeof(QuizFrage));
|
|
|
|
kategorien[0].fragen[0] = erstelleFrage("Whats the height of the Zugspitze?", "2482 Meter", "2867 Meter", "2962 Meter", "3173 Meter", 'C');
|
|
kategorien[0].fragen[1] = erstelleFrage("In which Federal State is the Zugspitze?", "Bayern", "Baden-Wuerttemberg", "Hessen", "Thueringen", 'A');
|
|
kategorien[0].fragen[2] = erstelleFrage("Which Mountain is the highest following after the Zugspitze?", "Grossglockner", "Watzmann", "Feldberg", "Meissner", 'B');
|
|
|
|
kategorien[0].anzahlFragen = MAX_QUESTIONS_PER_CATEGORY;
|
|
kategorien[0].joker = 1;
|
|
|
|
TEST_ASSERT_EQUAL_STRING("Whats the height of the Zugspitze?", kategorien[0].fragen[0].frage);
|
|
TEST_ASSERT_EQUAL_STRING("2482 Meter", kategorien[0].fragen[0].antwortA);
|
|
TEST_ASSERT_EQUAL_STRING("2867 Meter", kategorien[0].fragen[0].antwortB);
|
|
TEST_ASSERT_EQUAL_STRING("2962 Meter", kategorien[0].fragen[0].antwortC);
|
|
TEST_ASSERT_EQUAL_STRING("3173 Meter", kategorien[0].fragen[0].antwortD);
|
|
TEST_ASSERT_EQUAL_CHAR('C', kategorien[0].fragen[0].korrekteAntwort);
|
|
|
|
free(kategorien[0].fragen);
|
|
}
|
|
void test_createCategory2WithQuestions(void) {
|
|
Kategorie kategorien[MAX_CATEGORIES];
|
|
|
|
kategorien[2].fragen = (QuizFrage*)malloc(MAX_QUESTIONS_PER_CATEGORY * sizeof(QuizFrage));
|
|
|
|
kategorien[2].fragen[0] = erstelleFrage("In which sport is the term 'home run' used?", "Soccer/Football", "Baseball", "Tennis", "Golf", 'B');
|
|
kategorien[2].fragen[1] = erstelleFrage("How many players are there normally on the pitch in a soccer/football team?", "9", "11", "7", "5", 'B');
|
|
kategorien[2].fragen[2] = erstelleFrage("What sport is played on a pitch and has a 'wicket'?", "Rugby", "Cricket", "American Football", "Hockey", 'B');
|
|
|
|
kategorien[2].anzahlFragen = MAX_QUESTIONS_PER_CATEGORY;
|
|
kategorien[2].joker = 1;
|
|
|
|
TEST_ASSERT_EQUAL_STRING("In which sport is the term 'home run' used?", kategorien[2].fragen[0].frage);
|
|
TEST_ASSERT_EQUAL_STRING("Soccer/Football", kategorien[2].fragen[0].antwortA);
|
|
TEST_ASSERT_EQUAL_STRING("Baseball", kategorien[2].fragen[0].antwortB);
|
|
TEST_ASSERT_EQUAL_STRING("Tennis", kategorien[2].fragen[0].antwortC);
|
|
TEST_ASSERT_EQUAL_STRING("Golf", kategorien[2].fragen[0].antwortD);
|
|
TEST_ASSERT_EQUAL_CHAR('B', kategorien[2].fragen[0].korrekteAntwort);
|
|
|
|
free(kategorien[2].fragen);
|
|
}
|
|
void test_befreieKategorie(void) {
|
|
Kategorie testKategorie;
|
|
testKategorie.fragen = (QuizFrage*)malloc(MAX_QUESTIONS_PER_CATEGORY * sizeof(QuizFrage));
|
|
testKategorie.anzahlFragen = 3;
|
|
testKategorie.joker = 1;
|
|
|
|
befreieKategorie(&testKategorie);
|
|
|
|
TEST_ASSERT_NULL(testKategorie.fragen);
|
|
TEST_ASSERT_EQUAL_INT(0, testKategorie.anzahlFragen);
|
|
TEST_ASSERT_EQUAL_INT(0, testKategorie.joker);
|
|
}
|
|
void test_pruefeAntwort_CorrectAnswer(void) {
|
|
QuizFrage frage = erstelleFrage("Test Question", "Option A", "Option B", "Option C", "Option D", 'A');
|
|
TEST_ASSERT_EQUAL_INT(1, pruefeAntwort(frage, 'A'));
|
|
}
|
|
void test_pruefeAntwort_WrongAnswer(void) {
|
|
QuizFrage frage = erstelleFrage("Test Question", "Option A", "Option B", "Option C", "Option D", 'A');
|
|
TEST_ASSERT_EQUAL_INT(0, pruefeAntwort(frage, 'B'));
|
|
}
|
|
void test_sportsCategoryInitialization(void) {
|
|
Kategorie kategorien[MAX_CATEGORIES];
|
|
|
|
kategorien[2].fragen = (QuizFrage*)malloc(MAX_QUESTIONS_PER_CATEGORY * sizeof(QuizFrage));
|
|
|
|
kategorien[2].fragen[0] = erstelleFrage("In which sport is the term 'home run' used?", "Soccer/Football", "Baseball", "Tennis", "Golf", 'B');
|
|
kategorien[2].fragen[1] = erstelleFrage("How many players are there normally on the pitch in a soccer/football team?", "9", "11", "7", "5", 'B');
|
|
kategorien[2].fragen[2] = erstelleFrage("What sport is played on a pitch and has a 'wicket'?", "Rugby", "Cricket", "American Football", "Hockey", 'B');
|
|
kategorien[2].anzahlFragen = MAX_QUESTIONS_PER_CATEGORY;
|
|
kategorien[2].joker = 1;
|
|
|
|
TEST_ASSERT_NOT_NULL(kategorien[2].fragen);
|
|
TEST_ASSERT_EQUAL_STRING("In which sport is the term 'home run' used?", kategorien[2].fragen[0].frage);
|
|
TEST_ASSERT_EQUAL_STRING("Soccer/Football", kategorien[2].fragen[0].antwortA);
|
|
TEST_ASSERT_EQUAL_STRING("Baseball", kategorien[2].fragen[0].antwortB);
|
|
TEST_ASSERT_EQUAL_STRING("Tennis", kategorien[2].fragen[0].antwortC);
|
|
TEST_ASSERT_EQUAL_STRING("Golf", kategorien[2].fragen[0].antwortD);
|
|
TEST_ASSERT_EQUAL('B', kategorien[2].fragen[0].korrekteAntwort);
|
|
TEST_ASSERT_EQUAL_STRING("How many players are there normally on the pitch in a soccer/football team?", kategorien[2].fragen[1].frage);
|
|
TEST_ASSERT_EQUAL_STRING("9", kategorien[2].fragen[1].antwortA);
|
|
TEST_ASSERT_EQUAL_STRING("11", kategorien[2].fragen[1].antwortB);
|
|
TEST_ASSERT_EQUAL_STRING("7", kategorien[2].fragen[1].antwortC);
|
|
TEST_ASSERT_EQUAL_STRING("5", kategorien[2].fragen[1].antwortD);
|
|
TEST_ASSERT_EQUAL('B', kategorien[2].fragen[1].korrekteAntwort);
|
|
TEST_ASSERT_EQUAL_STRING("What sport is played on a pitch and has a 'wicket'?", kategorien[2].fragen[2].frage);
|
|
TEST_ASSERT_EQUAL_STRING("Rugby", kategorien[2].fragen[2].antwortA);
|
|
TEST_ASSERT_EQUAL_STRING("Cricket", kategorien[2].fragen[2].antwortB);
|
|
TEST_ASSERT_EQUAL_STRING("American Football", kategorien[2].fragen[2].antwortC);
|
|
TEST_ASSERT_EQUAL_STRING("Hockey", kategorien[2].fragen[2].antwortD);
|
|
TEST_ASSERT_EQUAL('B', kategorien[2].fragen[2].korrekteAntwort);
|
|
TEST_ASSERT_EQUAL(MAX_QUESTIONS_PER_CATEGORY, kategorien[2].anzahlFragen);
|
|
TEST_ASSERT_EQUAL(1, kategorien[2].joker);
|
|
|
|
free(kategorien[2].fragen);
|
|
kategorien[2].fragen = NULL;
|
|
}
|
|
#endif //TEST
|