Simon Hildebrandt 11 months ago
parent
commit
00e08309d2
  1. 232
      src/main/c/VierGewinnt.c
  2. 20
      src/main/c/VierGewinnt.h
  3. 398
      src/main/c/hangman.c
  4. 23
      src/main/c/hangman.h
  5. 1
      src/main/c/hangman.txt
  6. 20
      src/main/c/hangman_words.txt
  7. 151
      src/test/c/test_VierGewinnt.c
  8. 147
      src/test/c/test_hangman_test.c
  9. 28
      src/test/c/test_test.c
  10. 3
      team.md

232
src/main/c/VierGewinnt.c

@ -0,0 +1,232 @@
// Author fdai7726
/*
*Ein Vier-Gewinnt-Spiel, das in der Kommandozeile gespielt wird.
*Das Programm ermöglicht es zwei Spielern, abwechselnd Steine in eine Spalte zu setzen,
*um eine Reihe von vier Steinen horizontal,
*vertikal oder diagonal zu bilden und das Spiel zu gewinnen.
*Das Spielfeld wird grafisch in der Kommandozeile dargestellt,
*und das Programm überprüft automatisch,
*ob einer der Spieler gewonnen hat oder ob das Spielfeld voll ist.
*/
//Importiere wichtige Bibliotheken
#include <stdio.h>
#include <stdlib.h>
//Definiere Feldgröße
#define ROWS 6
#define COLS 7
// Definiere Farben
#define RESET_COLOR "\033[0m"
#define BLACK "\033[0;30m"
#define RED "\033[0;31m"
#define GREEN "\033[0;32m"
#define YELLOW "\033[0;33m"
#define BLUE "\033[0;34m"
#define MAGENTA "\033[0;35m"
#define CYAN "\033[0;36m"
#define WHITE "\033[0;37m"
//Funktionsprototypen
void initializeBoard(char board[ROWS][COLS]);
void printBoard(char board[ROWS][COLS]);
void clearScreen();
int isColumnFull(char board[ROWS][COLS], int col);
int dropPiece(char board[ROWS][COLS], int col, char player);
int checkWin(char board[ROWS][COLS], char player);
int checkHorizontal(char board[ROWS][COLS], char player);
int checkVertical(char board[ROWS][COLS], char player);
int checkDiagonalRL(char board[ROWS][COLS], char player);
void showInvalidInputWarning();
void showColumnFullMessage();
void showWinMessage(int player);
int main_function() {
char board[ROWS][COLS];
int Player = 1;
initializeBoard(board);
printBoard(board);
int column;
while (1) {
printf(YELLOW"Spieler %d, wähle eine Spalte (1-7): "RESET_COLOR, Player);
scanf("%d", &column);
if (column < 1 || column > 7) {
showInvalidInputWarning();
continue;
}
column--;
if (isColumnFull(board, column)) {
showColumnFullMessage();
continue;
}
if (dropPiece(board, column, (Player == 1) ? 'X' : 'O')) {
printBoard(board);
if (checkWin(board, (Player == 1) ? 'X' : 'O')) {
showWinMessage(Player);
break;
}
Player = (Player == 1) ? 2 : 1;
}
}
return 0;
}
void initializeBoard(char board[ROWS][COLS]) {
for (int i = 0; i < ROWS; i++) {
for (int j = 0; j < COLS; j++) {
board[i][j] = ' ';
}
}
}
void printBoard(char board[ROWS][COLS]) {
clearScreen();
printf("\n");
for (int i = 0; i < ROWS; i++) {
for (int j = 0; j < COLS; j++) {
printf("| %c ", board[i][j]);
}
printf("|\n");
for (int j = 0; j < COLS; j++) {
printf("----");
}
printf("-\n");
}
printf(" 1 2 3 4 5 6 7\n\n");
}
void clearScreen() {
#ifdef _WIN32
system("cls");
#else
system("clear");
#endif
}
int isColumnFull(char board[ROWS][COLS], int col) {
return (board[0][col] != ' ');
}
int dropPiece(char board[ROWS][COLS], int col, char player) {
for (int i = ROWS - 1; i >= 0; i--) {
if (board[i][col] == ' ') {
board[i][col] = player;
return 1;
}
}
return 0;
}
int checkHorizontal(char board[ROWS][COLS], char player) {
for (int row = 0; row < ROWS; row++) {
for (int col = 0; col <= COLS - 4; col++) {
if (board[row][col] == player &&
board[row][col + 1] == player &&
board[row][col + 2] == player &&
board[row][col + 3] == player) {
return 1;
}
}
}
return 0;
}
int checkVertical(char board[ROWS][COLS], char player) {
for (int col = 0; col < COLS; col++) {
for (int row = 0; row <= ROWS - 4; row++) {
if (board[row][col] == player &&
board[row + 1][col] == player &&
board[row + 2][col] == player &&
board[row + 3][col] == player) {
return 1;
}
}
}
return 0;
}
int checkDiagonalLR(char board[ROWS][COLS], char player) {
for (int row = 0; row <= ROWS - 4; row++) {
for (int col = 0; col <= COLS - 4; col++) {
if (board[row][col] == player &&
board[row + 1][col + 1] == player &&
board[row + 2][col + 2] == player &&
board[row + 3][col + 3] == player) {
return 1;
}
}
}
return 0;
}
int checkDiagonalRL(char board[ROWS][COLS], char player) {
for (int row = 0; row <= ROWS - 4; row++) {
for (int col = 3; col < COLS; col++) {
if (board[row][col] == player &&
board[row + 1][col - 1] == player &&
board[row + 2][col - 2] == player &&
board[row + 3][col - 3] == player) {
return 1;
}
}
}
return 0;
}
int checkWin(char board[ROWS][COLS], char player) {
return checkHorizontal(board, player) ||
checkVertical(board, player) ||
checkDiagonalLR(board, player) ||
checkDiagonalRL(board, player);
}
// Die Funktion showMessage gibt eine formatierte Nachricht aus, wobei die Farbe der Nachricht dynamisch festgelegt werden kann.
void showMessage(const char* messageColor, const char* message) {
printf("%s%s"RESET_COLOR, messageColor, message);
}
//Die Funktion showInvalidInputWarning zeigt eine Warnung für ungültige Benutzereingaben an. Sie ruft die Funktion showMessage auf, um die Nachricht in roter Farbe auszugeben, die den Benutzer darüber informiert, dass die Eingabe ungültig ist und er eine Spalte zwischen 1 und 7 wählen soll.
void showInvalidInputWarning() {
showMessage(RED, "Ungültige Eingabe. Bitte wähle eine Spalte zwischen 1 und 7.\n");
}
void showColumnFullMessage() {
showMessage(RED, "Die ausgewählte Spalte ist bereits belegt. Bitte wähle eine andere Spalte aus.\n");
}
void showWinMessage(int player) {
printf("Spieler %d ist der Gewinner!\n", player);
}

20
src/main/c/VierGewinnt.h

@ -0,0 +1,20 @@
#ifndef VIERGEWINNT_H
#define VIERGEWINNT_H
#define ROWS 6
#define COLS 7
void initializeBoard(char board[ROWS][COLS]);
void printBoard(char board[ROWS][COLS]);
int isColumnFull(char board[ROWS][COLS], int col);
int dropPiece(char board[ROWS][COLS], int col, char player);
int checkWin(char board[ROWS][COLS], char player);
int checkHorizontal(char board[ROWS][COLS], char player);
int checkVertical(char board[ROWS][COLS], char player);
int checkDiagonalLR(char board[ROWS][COLS], char player);
int checkDiagonalRL(char board[ROWS][COLS], char player);
void showMessage(const char* messageColor, const char* message);
void showInvalidInputMessage();
void showColumnFullMessage();
void showWinMessage(int player);
#endif

398
src/main/c/hangman.c

@ -0,0 +1,398 @@
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
#include <ctype.h>
#include <unistd.h>
void protokoll();
void clear_screen();
void willkommen();
int namePruefen();
void nameWaehlen();
void startauswahl();
void nameAusgeben();
void levelauswahl();
void hauptSpiel(int level);
void zeichne_galgen(int versuche);
void erratenen_buchstaben_hinzufuegen(char* guessed_letters, char guessed_letter);
char eingabe_buchstabe();
void hole_zu_erratendes_wort(char* secret_word, int level, char* path);
void zeige_Buchstabenfeld(char secret_word[100], char guessed_letters[100]);
int buchstabe_im_zu_erratenden_wort(char guessed_letter, char secret_word[100]);
int gewonnen(char secret_word[100], char guessed_letters[100]);
void level_plus();
int overlay();
void protokoll(){
clear_screen();
willkommen();
namePruefen();
startauswahl();
}
void clear_screen() {
system("clear");
// system("cls"); // fuer Windows
// system("clear"); // fuer UNIX/Linux
}
void willkommen(){
char ENTERtxt[] = {"-Druecke ENTER zum starten-\n"};
overlay();
printf("%s", ENTERtxt);
getchar();
}
int namePruefen() {
char KonfDatei[100];
int laengeKonfDatei = 0;
FILE *fp = NULL;
fp = fopen("hangman.txt", "r");
if (fp == NULL) {
printf("Fehler beim Öffnen der Konfigurationsdatei\n");
return 1;
} else {
fscanf(fp, "%s", KonfDatei); //Inhalt der KonfDatei wird ins Array gelesen
while(KonfDatei[laengeKonfDatei] != 0){ //Laenge der KonfDatei wird ermittelt
laengeKonfDatei++;
}
if(laengeKonfDatei > 14){ //mit der Laenge wird geschaut, ob ein Name gespeichert ist oder nicht
fclose(fp);
return 0;
} else {
printf("Sieht aus, als haettest du noch keinen Namen :(\n");
nameWaehlen();
fclose(fp);
return 0;
}
}
fclose(fp);
}
void nameWaehlen(){
char name[50];
FILE *fp = NULL;
fp = fopen("hangman.txt", "w");
clear_screen(); //
overlay();
printf("Geben Sie den Namen ein: ");
scanf("%s", name);
char KonfDatei[100];
snprintf(KonfDatei, sizeof(KonfDatei), "name:%s,level:01", name);
fprintf(fp, "%s", KonfDatei);
fclose(fp);
}
void startauswahl() {
int auswahl;
int modus;
clear_screen(); //
overlay();
printf("Willkommen ");
nameAusgeben();
printf("[1] Spielen\n[2] Namen aendern\n");
scanf("%d", &auswahl);
if(auswahl == 1){
levelauswahl();
} else if (auswahl == 2){
nameWaehlen();
} else {
printf("Eingabe ungueltig");
}
}
void nameAusgeben(){
char KonfDatei[100];
char name[50];
int i = 5;
int zaehler = 0;
int nullterminante;
FILE *fp = NULL;
fp = fopen("hangman.txt", "r");
fscanf(fp, "%s", KonfDatei);
while(KonfDatei[i] != ','){
zaehler++;
i++;
}
nullterminante = zaehler;
while(zaehler != 0){
name[--zaehler] = KonfDatei[--i];
}
i = 0;
while(name[i] != 0){
i++;
}
name[nullterminante] = '\0';
printf("%s\n", name);
fclose(fp);
}
void levelauswahl(){
char levelstr[3];
char KonfDatei[100];
int level;
int i = 0;
clear_screen(); //
overlay();
FILE *fp = NULL;
fp = fopen("hangman.txt", "r");
fscanf(fp, "%s", KonfDatei);
while(KonfDatei[i] != 0){
i++;
}
levelstr[0] = KonfDatei[i-2];
levelstr[1] = KonfDatei[i-1];
levelstr[2] = '\0';
level = atoi(levelstr);
hauptSpiel(level);
fclose(fp);
}
void hauptSpiel(int level){
char secret_word[100];
int versuche = 0;
char guessed_letter;
char guessed_letters[100];
char path[] = "hangman_words.txt";
int result;
int won = 0;
hole_zu_erratendes_wort(secret_word, level, path);
while (versuche < 6 && won == 0) {
zeichne_galgen(versuche);
zeige_Buchstabenfeld(secret_word, guessed_letters);
guessed_letter = eingabe_buchstabe();
result = buchstabe_im_zu_erratenden_wort(guessed_letter, secret_word);
if (result == 0){
erratenen_buchstaben_hinzufuegen(guessed_letters, guessed_letter);
}
else {
versuche++;
}
won = gewonnen(secret_word, guessed_letters);
}
if (won == 1){
level_plus();
}
}
void zeichne_galgen(int versuche) {
clear_screen();
printf("Galgenmann!\n");
printf("v.1.0.2\n\n");
switch(versuche) {
case 0:
printf(" _______\n");
printf(" | |\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf("__|_________\n\n\n\n");
break;
case 1:
printf(" _______\n");
printf(" | |\n");
printf(" | O\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf("__|_________\n\n\n\n");
break;
case 2:
printf(" _______\n");
printf(" | |\n");
printf(" | O\n");
printf(" | |\n");
printf(" |\n");
printf(" |\n");
printf("__|_________\n\n\n\n");
break;
case 3:
printf(" _______\n");
printf(" | |\n");
printf(" | O\n");
printf(" | /|\n");
printf(" |\n");
printf(" |\n");
printf("__|_________\n\n\n\n");
break;
case 4:
printf(" _______\n");
printf(" | |\n");
printf(" | O\n");
printf(" | /|\\\n");
printf(" |\n");
printf(" |\n");
printf("__|_________\n\n\n\n");
break;
case 5:
printf(" _______\n");
printf(" | |\n");
printf(" | O\n");
printf(" | /|\\\n");
printf(" | /\n");
printf(" |\n");
printf("__|_________\n\n\n\n");
break;
case 6:
printf(" _______\n");
printf(" | |\n");
printf(" | O\n");
printf(" | /|\\\n");
printf(" | / \\\n");
printf(" |\n");
printf("__|_________\n\n\n\n");
break;
default:
break;
}
}
void erratenen_buchstaben_hinzufuegen(char* guessed_letters, char guessed_letter){
for (int i = 0; i < strlen(guessed_letters); i++){
if (guessed_letters[i] == guessed_letter){
return;
}
}
guessed_letters[strlen(guessed_letters)] = guessed_letter;
guessed_letters[strlen(guessed_letters) + 1] = '\0';
}
char eingabe_buchstabe(){
char guess;
scanf(" %c", &guess);
guess = tolower(guess);
return guess;
}
void hole_zu_erratendes_wort(char* secret_word, int level, char* path){
FILE *file = fopen(path, "r");
int count = 0;
if ( file != NULL )
{
char line[100]; /* or other suitable maximum line size */
while (fgets(line, sizeof line, file) != NULL) /* read a line */
{
if (count == level)
{
strcpy(secret_word, line);
secret_word[strlen(secret_word) - 1] = '\0';
return;
}
else
{
count++;
}
}
fclose(file);
}
}
void zeige_Buchstabenfeld(char secret_word[100], char guessed_letters[100]){
printf("Erratene Buchstaben: ");
for(int i = 0; i < strlen(secret_word); i++) {
if(strchr(guessed_letters, secret_word[i])){
printf("%c ", secret_word[i]);
}
else{
printf("_ ");
}
}
printf("\n");
}
int buchstabe_im_zu_erratenden_wort(char guessed_letter, char secret_word[100]){
for(int i = 0; i < strlen(secret_word); i++){
if(guessed_letter == secret_word[i]){
return 0;
}
}
return 1;
}
int gewonnen(char secret_word[100], char guessed_letters[100]){
int occured;
for (int i = 0; i < strlen(secret_word); i++){
occured = 0;
for (int k = 0; k < strlen(guessed_letters); k++){
if (secret_word[i] == guessed_letters[k]){
occured = 1;
}
}
if (occured == 0){
return 0;
}
}
return 1;
}
void level_plus(){
char KonfDatei[100];
char level[3];
int i = 0;
FILE *fp = NULL;
fp = fopen("hangman.txt", "r+");
fscanf(fp, "%s", KonfDatei);
while(KonfDatei[i] != 0){
i++;
}
level[0] = KonfDatei[i-2];
level[1] = KonfDatei[i-1];
level[2] = '\0';
if (level[1] == '9'){
KonfDatei[i-2]++;
KonfDatei[i-1] = '0';
} else {
KonfDatei[i-1]++;
}
fclose(fp);
fp = fopen("hangman.txt", "w");
fprintf(fp, "%s", KonfDatei);
fclose(fp);
}
int overlay(){
char galgen_overlay[10][41] = {
" _______ ",
" | | ",
" | ",
" | ",
" | ",
" | ",
"__|_________\n"
};
printf("Galgenmann!\n");
printf("v.1.0.2\n\n");
for (int i = 0; i < 9; i++) {
printf("%s\n", galgen_overlay[i]);
}
return 0;
}

23
src/main/c/hangman.h

@ -0,0 +1,23 @@
#ifndef TEST_H
#define TEST_H
void protokoll();
void clear_screen();
void willkommen();
int namePruefen();
void nameWaehlen();
void startauswahl();
void nameAusgeben();
void levelauswahl();
void hauptSpiel(int level);
void zeichne_galgen(int versuche);
void erratenen_buchstaben_hinzufuegen(char* guessed_letters, char guessed_letter);
char eingabe_buchstabe();
void hole_zu_erratendes_wort(char* secret_word, int level, char* path);
void zeige_Buchstabenfeld(char secret_word[100], char guessed_letters[100]);
int buchstabe_im_zu_erratenden_wort(char guessed_letter, char secret_word[100]);
int gewonnen(char secret_word[100], char guessed_letters[100]);
void level_plus();
int overlay();
#endif // TEST_H

1
src/main/c/hangman.txt

@ -0,0 +1 @@
name:peter,level:02

20
src/main/c/hangman_words.txt

@ -0,0 +1,20 @@
fulda
galgenmann
programmiermethoden
test
peter
ahmad
joe
celine
sigi
jonas
mitochondrien
aufmerksamkeitsdefizithyperaktivitaetsstoerung
donaudampfschifffahrtelekrizitaetenhauptbetriebswerkbauunternehmenbeamtengesellschaft
malaysia
lucas
yasin
samuel
celli
hochschule
fulda

151
src/test/c/test_VierGewinnt.c

@ -0,0 +1,151 @@
#include "unity.h"
#include "VierGewinnt.h"
void setUp(void) {
}
void tearDown(void) {
}
void test_dropPiece_ValidMove(void) {
char board[6][7];
initializeBoard(board);
TEST_ASSERT_EQUAL_INT(1, dropPiece(board, 3, 'X'));
}
void test_dropPiece_FullColumn(void) {
char board[6][7] = {
{'X', 'O', 'X', 'O', 'X', 'O', 'X'},
{'O', 'X', 'O', 'X', 'O', 'X', 'O'},
{'X', 'O', 'X', 'O', 'X', 'O', 'X'},
{'O', 'X', 'O', 'X', 'O', 'X', 'O'},
{'X', 'O', 'X', 'O', 'X', 'O', 'X'},
{'O', 'X', 'O', 'X', 'O', 'X', 'O'}
};
TEST_ASSERT_EQUAL_INT(0, dropPiece(board, 3, 'X')); // Spalte ist voll, sollte 0 zurückgeben
}
void test_checkWin_Horizontal_X(void) {
char board[6][7] = {
{'X', 'X', ' ', ' ', ' ', ' ', ' '},
{'O', 'O', 'O', ' ', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' ', ' ', ' '},
{' ', 'X', 'X', 'X', 'X', ' ', ' '},
{' ', ' ', ' ', ' ', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' ', ' ', ' '}
};
TEST_ASSERT_EQUAL_INT(1, checkWin(board, 'X')); // Horizontale Gewinnsituation für 'X'
}
void test_checkWin_Horizontal_O(void) {
char board[6][7] = {
{'X', 'X', ' ', ' ', ' ', ' ', ' '},
{'O', 'O', 'O', 'O', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' ', ' ', ' '},
{' ', 'X', 'X', ' ', 'X', ' ', ' '},
{' ', ' ', ' ', ' ', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' ', ' ', ' '}
};
TEST_ASSERT_EQUAL_INT(1, checkWin(board, 'O')); // Horizontale Gewinnsituation für 'X'
}
void test_checkWin_Diagonal_X(void) {
char board[6][7] = {
{'X', 'X', ' ', ' ', ' ', ' ', ' '},
{'O', 'O', 'O', 'X', ' ', ' ', ' '},
{' ', 'X', ' ', ' ', ' ', ' ', ' '},
{' ', 'X', 'X', 'X', 'X', ' ', ' '},
{' ', ' ', ' ','X', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' ', 'X', ' '}
};
TEST_ASSERT_EQUAL_INT(1, checkWin(board, 'X')); // Horizontale Gewinnsituation für 'X'
}
void test_checkWin_Diagonal_O(void) {
char board[6][7] = {
{'X', 'X', ' ', ' ', ' ', ' ', ' '},
{'O', 'O', 'O', 'X', ' ', ' ', ' '},
{' ', 'O', ' ', ' ', ' ', ' ', ' '},
{' ', 'X', 'O', 'X', 'X', ' ', ' '},
{' ', ' ', ' ','O', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' ', 'X', ' '}
};
TEST_ASSERT_EQUAL_INT(1, checkWin(board, 'O')); // Horizontale Gewinnsituation für 'X'
}
void test_checkWin_Vertical_X(void) {
char board[6][7] = {
{'X', 'O', ' ', ' ', ' ', ' ', ' '},
{'X', 'O', ' ', ' ', ' ', ' ', ' '},
{'X', 'O', ' ', ' ', ' ', ' ', ' '},
{'X', ' ', ' ', ' ', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' ', ' ', ' '}
};
TEST_ASSERT_EQUAL_INT(1, checkWin(board, 'X')); // Vertikale Gewinnsituation für 'X'
}
void test_checkWin_Vertical_O(void) {
char board[6][7] = {
{'X', 'O', ' ', ' ', ' ', ' ', ' '},
{'X', 'O', ' ', ' ', ' ', ' ', ' '},
{'X', 'O', ' ', ' ', ' ', ' ', ' '},
{' ', 'O', ' ', ' ', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' ', ' ', ' '}
};
TEST_ASSERT_EQUAL_INT(1, checkWin(board, 'O')); // Vertikale Gewinnsituation für 'X'
}
void test_checkWin_NoWinner(void) {
char board[6][7] = {
{'X', 'O', 'X', 'O', 'X', 'O', 'X'},
{'O', 'X', 'O', 'X', 'O', 'X', 'O'},
{'O', 'X', 'O', 'X', 'O', 'X', 'O'},
{'O', 'X', 'O', 'X', 'O', 'X', 'O'},
{'X', 'O', 'X', 'O', 'X', 'O', 'X'},
{'O', 'X', 'O', 'X', 'O', 'X', 'O'}
};
TEST_ASSERT_EQUAL_INT(0, checkWin(board, 'X')); // Kein Gewinner, horizontale Reihe ist voll
TEST_ASSERT_EQUAL_INT(0, checkWin(board, 'O')); // Kein Gewinner, horizontale Reihe ist voll
}
void test_isColumnFull(void) {
char board[6][7] = {
{'X', 'O', 'X', 'O', 'X', 'O', 'X'},
{'O', 'X', 'O', 'X', 'O', 'X', 'O'},
{'X', 'O', 'X', 'O', 'X', 'O', 'X'},
{'O', 'X', 'O', 'X', 'O', 'X', 'O'},
{'X', 'O', 'X', 'O', 'X', 'O', 'X'},
{'O', 'X', 'O', 'X', 'O', 'X', 'O'}
};
TEST_ASSERT_EQUAL_INT(1, isColumnFull(board, 3)); // Column 3 is full
}

147
src/test/c/test_hangman_test.c

@ -0,0 +1,147 @@
#ifdef TEST
#include "unity.h"
#include "hangman.h"
void setUp(void) {}
void tearDown(void) {}
void test_buchstabe_im_zu_erratenden_wort_eingabe_j_in_leerstring_falsch() {
// arrange
int expected = 1;
int actual;
char guessed_letter = 'j';
char secret_word[100] = "";
// act
actual = buchstabe_im_zu_erratenden_wort(guessed_letter, secret_word);
// assert
TEST_ASSERT_EQUAL_INT(expected, actual);
}
void test_buchstabe_im_zu_erratenden_wort_eingabe_j_in_joe_richtig() {
// arrange
int expected = 0;
int actual;
char guessed_letter = 'j';
char secret_word[100] = "joe";
// act
actual = buchstabe_im_zu_erratenden_wort(guessed_letter, secret_word);
// assert
TEST_ASSERT_EQUAL_INT(expected, actual);
}
void test_buchstabe_im_zu_erratenden_wort_eingabe_k_in_joe_falsch() {
// arrange
int expected = 1;
int actual;
char guessed_letter = 'k';
char secret_word[100] = "joe";
// act
actual = buchstabe_im_zu_erratenden_wort(guessed_letter, secret_word);
// assert
TEST_ASSERT_EQUAL_INT(expected, actual);
}
void test_buchstabe_im_zu_erratenden_wort_eingabe_j_in_eoj_richtig() {
// arrange
int expected = 0;
int actual;
char guessed_letter = 'j';
char secret_word[100] = "eoj";
// act
actual = buchstabe_im_zu_erratenden_wort(guessed_letter, secret_word);
// assert
TEST_ASSERT_EQUAL_INT(expected, actual);
}
void test_erratenen_buchstaben_hinzufuegen_anhaengen_r_an_leerstring_zu_peter_richtig() {
// arrange
char expected[100] = "r";
char actual[100] = "";
char to_add = 'r';
// act
erratenen_buchstaben_hinzufuegen(actual, to_add);
// assert
TEST_ASSERT_EQUAL_STRING(expected, actual);
}
void test_erratenen_buchstaben_hinzufuegen_anhaengen_r_an_pete_zu_peter_richtig() {
// arrange
char expected[100] = "peter";
char actual[100] = "pete";
char to_add = 'r';
// act
erratenen_buchstaben_hinzufuegen(actual, to_add);
// assert
TEST_ASSERT_EQUAL_STRING(expected, actual);
}
void test_erratenen_buchstaben_hinzufuegen_anhaengen_r_an_peter_zu_peter_falsch() {
// arrange
char expected[100] = "peter";
char actual[100] = "peter";
char to_add = 'r';
// act
erratenen_buchstaben_hinzufuegen(actual, to_add);
// assert
TEST_ASSERT_FALSE(expected == actual);
}
void test_gewonnen_petr_in_peter_richtig() {
// arrange
int expected = 1;
char actual;
char secret_word[100] = "peter";
char guessed_letters[100] = "petr";
// act
actual = gewonnen(secret_word, guessed_letters);
// assert
TEST_ASSERT_EQUAL_INT(expected, actual);
}
void test_gewonnen_p_in_peter_falsch() {
// arrange
int expected = 0;
char actual;
char secret_word[100] = "peter";
char guessed_letters[100] = "p";
// act
actual = gewonnen(secret_word, guessed_letters);
// assert
TEST_ASSERT_EQUAL_INT(expected, actual);
}
void test_gewonnen_petr_in_leerstring_richtig() {
// arrange
int expected = 1;
char actual;
char secret_word[100] = "";
char guessed_letters[100] = "petr";
// act
actual = gewonnen(secret_word, guessed_letters);
// assert
TEST_ASSERT_EQUAL_INT(expected, actual);
}
#endif // TEST

28
src/test/c/test_test.c

@ -1,28 +0,0 @@
#ifdef TEST
#include "unity.h"
#include "test.h"
void setUp(void)
{
}
void tearDown(void)
{
}
void test_test__return_5(void)
{
/* arrange */
int expected = 5;
int actual;
/* act */
actual = return_5();
/* assert */
TEST_ASSERT_EQUAL_INT(expected, actual);
}
#endif // TEST

3
team.md

@ -3,4 +3,5 @@ Peter Wiebe, fdai7773
Simon Hildebrandt, fdai7864 Simon Hildebrandt, fdai7864
Lucas Heil, fdai7356 Lucas Heil, fdai7356
Celine Khazarian, fdai7781 Celine Khazarian, fdai7781
Ahmad Thaljeh, fdai7726
Ahmad Thaljeh, fdai7726
Yasin Al Satouf, fdai7731
Loading…
Cancel
Save