KaffeeMaus
11 months ago
10 changed files with 802 additions and 0 deletions
-
126src/main/c/Georg/tictactoe.c
-
35src/main/c/Georg/tictactoe.h
-
260src/main/c/Tim/SchereSteinPapier.c
-
7src/main/c/Tim/SchereSteinPapier.h
-
7src/main/c/Tim/hangman.c
-
6src/main/c/Tim/hangman.h
-
67src/main/c/main.c
-
108src/test/c/Georg/test_tictactoe.c
-
162src/test/c/Tim/test_SchereSteinPapier.c
-
24src/test/c/Tim/test_hangman.c
@ -0,0 +1,126 @@ |
|||
#include <stdio.h> |
|||
#include <stdlib.h> |
|||
#include <string.h> |
|||
|
|||
#include "tictactoe.h" |
|||
|
|||
struct ticTacToe GAME; |
|||
|
|||
struct command COMMANDS[MAX_COMMANDS] = { |
|||
{ 1, "\"start menu\" - startet das menu", startMenu}, |
|||
{ 2, "\"start game\" - startet das spiel", startGame} |
|||
}; |
|||
|
|||
void startTicTacToe(){ |
|||
printf( "%s\n", getWelcomeMessageTicTacToe() ); |
|||
printf( "%s\n\n", getRulesMessageTicTacToe() ); |
|||
|
|||
GAME = createTicTacToe(); |
|||
|
|||
while( GAME.currentState != -1 ){ |
|||
commandFunction command; |
|||
printf("search command!\n"); |
|||
command = getCommandById( GAME.currentState + 1); |
|||
|
|||
if( command != NULL) |
|||
command(0); |
|||
else{ |
|||
printf("command not found"); |
|||
return; |
|||
} |
|||
} |
|||
} |
|||
|
|||
char* getWelcomeMessageTicTacToe(){ |
|||
return "Hallo und willkommen zu unserem TicTacToe Spiel. Anbei die Anleitung:\n"; |
|||
} |
|||
|
|||
char* getRulesMessageTicTacToe(){ |
|||
return "Das spiel wird über die Komandozeile gespielt.\n" |
|||
"Jeder Spielzug ist eine Eingabe in die Konsole. Die enstsprechenden Befehle stehen jeweils unterhalb des Spielfelds.\n" |
|||
"Um ein Zug zu tätigen musst du \"set x,y\" in die Konsole Eingeben. Die Koordinaten stehen dabei für Zeile und Spalte.\n" |
|||
"Mit dem Befehl \"start\" startest du das Spiel" |
|||
"Mit dem Befehl \"rules\" kannst du diese Nachricht erneut aufrufen."; |
|||
} |
|||
|
|||
struct ticTacToe createTicTacToe() { |
|||
struct ticTacToe newGame; |
|||
newGame.currentState = 0; |
|||
return newGame; |
|||
} |
|||
|
|||
int handleCommand( char* input ){ |
|||
if( strcmp(input, "start menu") == 0 ){ |
|||
return 0; |
|||
}else if( strcmp(input, "start game") == 0 ){ |
|||
return 1; |
|||
}else{ |
|||
return -1; |
|||
} |
|||
} |
|||
|
|||
commandFunction getCommandById( int id ){ |
|||
commandFunction result = NULL; |
|||
size_t arraySize = sizeof(COMMANDS) / sizeof(COMMANDS[0]); |
|||
for (size_t i = 0; i < arraySize; i++) { |
|||
//printf( "%s", COMMANDS[i].description ); |
|||
if( COMMANDS[i].id == id ){ |
|||
result = COMMANDS[i].fun; |
|||
break; |
|||
} |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
char* getUserInput(){ |
|||
static char userInput[MAX_INPUT_LENGTH]; |
|||
printf( ":" ); |
|||
fgets(userInput, sizeof(userInput), stdin); |
|||
|
|||
size_t len = strlen(userInput); |
|||
if (len > 0 && userInput[len - 1] == '\n') { |
|||
userInput[len - 1] = '\0'; |
|||
} |
|||
|
|||
return userInput; |
|||
} |
|||
|
|||
int startMenu( int code ){ |
|||
if( code == -1 ){ // command test |
|||
return 1; |
|||
} |
|||
|
|||
printf("Welcome to the menu!\n"); |
|||
|
|||
while( GAME.currentState == 0 ){ |
|||
int nextState = handleCommand( getUserInput() ); |
|||
|
|||
if( nextState == -1 ){ |
|||
printf("command not found!"); |
|||
}else{ |
|||
GAME.currentState = nextState; |
|||
} |
|||
} |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
int startGame( int code ){ |
|||
if( code == -1 ){ // command test |
|||
return 1; |
|||
} |
|||
|
|||
printf("Welcome to the game!\n"); |
|||
|
|||
while( GAME.currentState == 1 ){ |
|||
int nextState = handleCommand( getUserInput() ); |
|||
|
|||
if( nextState == -1 ){ |
|||
printf("command not found!"); |
|||
}else{ |
|||
GAME.currentState = nextState; |
|||
} |
|||
} |
|||
|
|||
return 0; |
|||
} |
@ -0,0 +1,35 @@ |
|||
#ifndef TICTACTOE_H |
|||
#define TICTACTOE_H |
|||
|
|||
#define MAX_INPUT_LENGTH 20 |
|||
#define MAX_COMMANDS 3 |
|||
|
|||
struct ticTacToe{ |
|||
int currentState; |
|||
}; |
|||
|
|||
// Typdefinition für einen Funktionszeiger |
|||
typedef int (*commandFunction)( int ); |
|||
|
|||
struct command{ |
|||
int id; |
|||
char* description; |
|||
commandFunction fun; |
|||
}; |
|||
|
|||
extern struct ticTacToe GAME; |
|||
extern struct command COMMANDS[MAX_COMMANDS]; |
|||
|
|||
|
|||
void startTicTacToe(); |
|||
char* getWelcomeMessageTicTacToe(void); |
|||
char* getRulesMessageTicTacToe(void); |
|||
struct ticTacToe createTicTacToe(); |
|||
int handleCommand( char* input ); |
|||
|
|||
/* commands */ |
|||
commandFunction getCommandById(int id); |
|||
int startMenu( int code ); |
|||
int startGame( int code ); |
|||
|
|||
#endif //TICTACTOE_H |
@ -0,0 +1,260 @@ |
|||
#include "SchereSteinPapier.h" |
|||
#include <stdio.h> |
|||
#include <stdlib.h> |
|||
#include <time.h> |
|||
#include <string.h> |
|||
|
|||
void gameLoop(); |
|||
char* getWelcomeMessageSSP(); |
|||
int selectCOMChoice(); |
|||
void printResult(int, int, int); |
|||
int getuserSelection(); |
|||
|
|||
|
|||
|
|||
void schereSteinPapier() |
|||
{ |
|||
srand(time(NULL)); |
|||
printf("%s", getWelcomeMessageSSP()); |
|||
gameLoop(); |
|||
} |
|||
|
|||
void gameLoop() |
|||
{ |
|||
while(1) |
|||
{ |
|||
int comChoice, userChoice; |
|||
userChoice = getuserSelection(); |
|||
if(userChoice == 0) |
|||
{ |
|||
printf("Vielen Dank fuers Spielen! Tschau!\n"); |
|||
break; |
|||
} |
|||
else if(userChoice == 1 || userChoice == 2 || userChoice == 3) |
|||
{ |
|||
comChoice = selectCOMChoice(); |
|||
int winNum = calculateWinner(userChoice, comChoice); |
|||
printResult(winNum, comChoice, userChoice); |
|||
} |
|||
else |
|||
{ |
|||
printf("Deine eingegebene Wahl ist ungueltig\n"); |
|||
} |
|||
} |
|||
} |
|||
//Berechnung,welche Auswahl gewinnt. |
|||
//@return: 0 = unentschieden; 1 = gewonnen; -1 = verloren; 3 = Fehler bei der Wertuebergabe |
|||
//@param userSelection = UserChoice; comSelection = COMChoice |
|||
int calculateWinner(int userSelection, int comSelection) |
|||
{ |
|||
switch (userSelection) |
|||
{ |
|||
case(1): |
|||
switch (comSelection) { |
|||
case(1): return 0; |
|||
|
|||
case(2): return -1; |
|||
|
|||
case(3): return 1; |
|||
|
|||
default: return 3; |
|||
} |
|||
case(2): |
|||
switch (comSelection) { |
|||
case(1): return 1; |
|||
|
|||
case(2): return 0; |
|||
|
|||
case(3): return -1; |
|||
|
|||
default: return 3; |
|||
} |
|||
case(3): |
|||
switch (comSelection) { |
|||
case(1): return -1; |
|||
|
|||
case(2): return 1; |
|||
|
|||
case(3): return 0; |
|||
|
|||
default: return 3; |
|||
} |
|||
default: return 3; |
|||
} |
|||
|
|||
} |
|||
|
|||
int selectCOMChoice() |
|||
{ |
|||
return rand() % 3 + 1; |
|||
} |
|||
|
|||
int getuserSelection() |
|||
{ |
|||
int userSelect; |
|||
printf("Bitte treffe deine Wahl!\n" |
|||
"1: Schere \n2: Stein \n3: Papier\n0: Spiel verlassen\n"); |
|||
scanf("%d", &userSelect); |
|||
|
|||
return userSelect; |
|||
} |
|||
|
|||
char* getWelcomeMessageSSP() |
|||
{ |
|||
return "\nHallo und Willkommen zu\n\n" |
|||
" _____ _ _____ _____ _ \r\n" |
|||
" | __ \\ | | | __ \\ / ____| (_) \r\n" |
|||
" | |__) |___ ___| | __ | |__) |_ _ _ __ ___ _ __ | (___ ___ _ ___ ___ ___ _ __ ___ \r\n" |
|||
" | _ // _ \\ / __| |/ / | ___/ _` | '_ \\ / _ \\ '__| \\___ \\ / __| / __/ __|/ _ \\| '__/ __|\r\n" |
|||
" | | \\ \\ (_) | (__| < | | | (_| | |_) | __/ | ____) | (__| \\__ \\__ \\ (_) | | \\__ \\\r\n" |
|||
" |_| \\_\\___/ \\___|_|\\_\\ |_| \\__,_| .__/ \\___|_| |_____/ \\___|_|___/___/\\___/|_| |___/ \r\n" |
|||
" | | \r\n" |
|||
" |_| \n" |
|||
"credits to wynand1004\n\n" |
|||
"In diesem Spiel spielst du gegen einen COM Schere-Stein-Papier!\n" |
|||
"Waehle, sobald dich die Konsole dazu auffordert, deine 'Waffe' aus, indem du die entsprechende Zahl eintippst.\n" |
|||
"Gibst du bei der Aufforderung 0 ein, gelangst du zurueck ins Hauptmenue!\n\n"; |
|||
} |
|||
|
|||
void printResult(int winNumb, int comSelect, int userSelect) |
|||
{ |
|||
char comWeapon[10]; |
|||
switch(comSelect) |
|||
{ |
|||
case(1): |
|||
strcpy(comWeapon, "Schere"); |
|||
break; |
|||
case(2): |
|||
strcpy(comWeapon,"Stein"); |
|||
break; |
|||
case(3): |
|||
strcpy(comWeapon,"Papier"); |
|||
break; |
|||
default: |
|||
strcpy(comWeapon, "Not found"); |
|||
break; |
|||
} |
|||
if(userSelect == 1) |
|||
{ |
|||
switch (comSelect) |
|||
{ |
|||
case(1): |
|||
printf(" _______ _______\n" |
|||
"---' ____)____ ____(____ '---\n" |
|||
" ______) (______\n" |
|||
" __________) (__________\n" |
|||
" (____) (____)\n" |
|||
"---.__(___) (___)__.---\n" |
|||
" Scissor vs Scissor\n"); |
|||
break; |
|||
case(2): |
|||
printf(" _______ _______\n" |
|||
"---' ____)____ (____ '---\n" |
|||
" ______) (_____)\n" |
|||
" __________) (_____)\n" |
|||
" (____) (____)\n" |
|||
"---.__(___) (___)__.---\n" |
|||
" Scissor vs Rock\n"); |
|||
break; |
|||
case(3): |
|||
printf(" _______ _______\n" |
|||
"---' ____)____ ____(____ '----\n" |
|||
" ______) (______\n" |
|||
" __________) (_______\n" |
|||
" (____) (_______\n" |
|||
"---.__(___) (_________.---\n" |
|||
" Scissor vs Paper\n"); |
|||
break; |
|||
default: |
|||
printf("ungültige Eingabe\n"); |
|||
break; |
|||
} |
|||
} |
|||
else if(userSelect ==2) |
|||
{ |
|||
switch (comSelect) |
|||
{ |
|||
case(1): |
|||
printf(" _______ _______\n" |
|||
"---' ____) ____(____ '---\n" |
|||
" (_____) (______\n" |
|||
" (_____) (__________\n" |
|||
" (____) (____)\n" |
|||
"---.__(___) (___)__.---\n" |
|||
" Rock VS Scissor\n"); |
|||
break; |
|||
case(2): |
|||
printf(" _______ _______\n" |
|||
"---' ____) (____ '---\n" |
|||
" (_____) (_____)\n" |
|||
" (_____) (_____)\n" |
|||
" (____) (____)\n" |
|||
"---.__(___) (___)__.---\n" |
|||
" Rock VS Rock\n"); |
|||
break; |
|||
case(3): |
|||
printf(" _______ _______\n" |
|||
"---' ____) ____(____ '----\n" |
|||
" (_____) (______\n" |
|||
" (_____) (_______\n" |
|||
" (____) (_______\n" |
|||
"---.__(___) (_________.---\n" |
|||
" Rock VS Paper\n"); |
|||
break; |
|||
default: |
|||
printf("ungültige Eingabe\n"); |
|||
break; |
|||
} |
|||
} |
|||
else if(userSelect ==3) |
|||
{ |
|||
switch (comSelect) |
|||
{ |
|||
case(1): |
|||
printf(" _______ _______\n" |
|||
"---' ____)____ ____(____ '---\n" |
|||
" ______) (______\n" |
|||
" _______) (__________\n" |
|||
" _______) (____)\n" |
|||
"---.__________) (___)__.---\n" |
|||
" Paper VS Scissor\n"); |
|||
break; |
|||
case(2): |
|||
printf(" _______ _______\n" |
|||
"---' ____)____ (____ '---\n" |
|||
" ______) (_____)\n" |
|||
" _______) (_____)\n" |
|||
" _______) (____)\n" |
|||
"---.__________) (___)__.---\n" |
|||
" Paper VS Rock\n"); |
|||
break; |
|||
case(3): |
|||
printf(" _______ _______\n" |
|||
"---' ____)____ ____(____ '----\n" |
|||
" ______) (______\n" |
|||
" _______) (_______\n" |
|||
" _______) (_______\n" |
|||
"---.__________) (_________.---\n" |
|||
" Paper VS Paper\n"); |
|||
break; |
|||
default: |
|||
printf("ungültige Eingabe\n"); |
|||
break; |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
printf("ungültige Eingabe"); |
|||
} |
|||
switch (winNumb) |
|||
{ |
|||
case(-1):printf("Der Computer hat %s gewaehlt, Du hast verloren!!!\n\n", comWeapon); |
|||
break; |
|||
case(0): printf("Der Computer hat %s gewaehlt, Es steht unentschieden!!!\n\n", comWeapon); |
|||
break; |
|||
case(1): printf("Der Computer hat %s gewaehlt, Du hast gewonnen!!!\n\n", comWeapon); |
|||
break; |
|||
default: printf("Error!"); |
|||
break; |
|||
} |
|||
} |
@ -0,0 +1,7 @@ |
|||
#ifndef SCHERESTEINPAPIER_H |
|||
#define SCHERESTEINPAPIER_H |
|||
|
|||
void schereSteinPapier(); |
|||
int calculateWinner(int, int); |
|||
|
|||
#endif |
@ -0,0 +1,7 @@ |
|||
#include "hangman.h" |
|||
#include <stdio.h> |
|||
|
|||
void hangman() |
|||
{ |
|||
printf("Hello World!"); |
|||
} |
@ -0,0 +1,6 @@ |
|||
#ifndef HANGMAN_H |
|||
#define HANGMAN_H |
|||
|
|||
void hangman(); |
|||
|
|||
#endif |
@ -0,0 +1,67 @@ |
|||
//todo |
|||
// Abfolge, um die main-Funktion mit eurem Spiel zu erweitern: |
|||
// 1.Includiert eure .h-Datei |
|||
// 2.Nehmt folgende Veränderungen in der Funktion openInterface() vor |
|||
// 2.1:Fügt dem ersten printf euren Spielnamen mit der nächsten Ziffer der Liste hinzu |
|||
// 2.2:Ruft in der switch-Funktion eure Spiel-Funktion in dem nächstfreien Case auf und entkommentiert diesen Case |
|||
|
|||
|
|||
|
|||
|
|||
//todo |
|||
// Includiert hier euer .h-Datei für das entsprechende Spiel mit '#include "datei.h"' |
|||
#include <stdio.h> |
|||
#include "SchereSteinPapier.h" |
|||
#include "hangman.h" |
|||
#include "tictactoe.h" |
|||
|
|||
|
|||
void openInterface(); |
|||
|
|||
int main() |
|||
{ |
|||
openInterface(); |
|||
return 0; |
|||
} |
|||
|
|||
void openInterface() |
|||
{ |
|||
int selection; |
|||
do { |
|||
// todo |
|||
// In diesem printf bitte euer Spiel mit der nächsten Ziffer und seinem entsprechendem Namen auflisten |
|||
// Vergesst das \n am Ende des Namens nicht!!! |
|||
printf("\n\nHallo und willkommen bei unserer Spielesammlung!!!\n" |
|||
"Du hast folgende Spiele zur Auswahl:\n\n" |
|||
"1: Schere-Stein-Papier\n" |
|||
"2: Hangman\n" |
|||
"3: TicTacToe\n"); |
|||
printf("\nBitte waehle die Zahl des entsprechenden Spiels aus, um damit zu starten.\nAm Ende eines Spiels kannst du mit der Taste 0 wieder zurueck zum Hauptmenue kommen.\nIm Hauptmenue beendest du mit der Auswahl 0 das Programm \n\n"); |
|||
scanf_s("%d", &selection); |
|||
|
|||
|
|||
//todo |
|||
// In die Switch bitte beim Case mit der oben eingetragenen Ziffer zu eurem Spiel eure Spielefunktion vor dem break; aufrufen |
|||
// und die entsprechende case entkommentieren (Verschieben vom /* vor das nächste Case). |
|||
switch (selection) |
|||
{ |
|||
case(1): |
|||
schereSteinPapier(); |
|||
break; |
|||
case(2): |
|||
hangman(); |
|||
break; |
|||
case(3): |
|||
startTicTacToe(); |
|||
break; |
|||
/*case(4): |
|||
//Spiel() |
|||
break; |
|||
case(5): |
|||
//Spiel() |
|||
break;*/ |
|||
default: |
|||
break; |
|||
} |
|||
} while (selection != 0); |
|||
} |
@ -0,0 +1,108 @@ |
|||
#include "tictactoe.h" |
|||
#include "unity.h" |
|||
|
|||
void setup(void){ |
|||
|
|||
} |
|||
|
|||
void tearDown(void){ |
|||
|
|||
} |
|||
|
|||
void test_compileTest_shutBeAllwaysTrue(void){ |
|||
TEST_ASSERT_EQUAL_INT(1,1); |
|||
} |
|||
|
|||
void test_welcome_message(void){ |
|||
// arrange |
|||
char* expectedMessage = "Hallo und willkommen zu unserem TicTacToe Spiel. Anbei die Anleitung:\n"; |
|||
|
|||
// act |
|||
char* message = getWelcomeMessageTicTacToe(); |
|||
|
|||
// aassert |
|||
TEST_ASSERT_EQUAL_STRING(expectedMessage, message); |
|||
} |
|||
|
|||
void test_rules_message(void){ |
|||
// arrange |
|||
char* expectedMessage = "Das spiel wird über die Komandozeile gespielt.\n" |
|||
"Jeder Spielzug ist eine Eingabe in die Konsole. Die enstsprechenden Befehle stehen jeweils unterhalb des Spielfelds.\n" |
|||
"Um ein Zug zu tätigen musst du \"set x,y\" in die Konsole Eingeben. Die Koordinaten stehen dabei für Zeile und Spalte.\n" |
|||
"Mit dem Befehl \"start\" startest du das Spiel" |
|||
"Mit dem Befehl \"rules\" kannst du diese Nachricht erneut aufrufen."; |
|||
|
|||
// act |
|||
char* message = getRulesMessageTicTacToe(); |
|||
|
|||
// assert |
|||
TEST_ASSERT_EQUAL_STRING(expectedMessage, message); |
|||
} |
|||
|
|||
void test_initial_state(void){ |
|||
// arrange |
|||
struct ticTacToe newGame; |
|||
int expectedState = 0; |
|||
|
|||
// act |
|||
newGame = createTicTacToe(); |
|||
|
|||
// assert |
|||
TEST_ASSERT_EQUAL_INT( expectedState, newGame.currentState ); |
|||
} |
|||
|
|||
void test_command_startGame(void){ |
|||
// arrange |
|||
int expectedState = 1; |
|||
char* input = "start game"; |
|||
|
|||
// act |
|||
int actualState = handleCommand( input ); |
|||
|
|||
// assert |
|||
TEST_ASSERT_EQUAL_INT( expectedState, actualState ); |
|||
} |
|||
|
|||
void test_command_startMenu(void){ |
|||
// arrange |
|||
int expectedState = 0; |
|||
char* input = "start menu"; |
|||
|
|||
// act |
|||
int actualState = handleCommand( input ); |
|||
|
|||
// assert |
|||
TEST_ASSERT_EQUAL_INT( expectedState, actualState ); |
|||
} |
|||
|
|||
void test_checkCommandlist(void){ |
|||
// arrange |
|||
|
|||
// act |
|||
|
|||
size_t arraySize = sizeof(*COMMANDS) / sizeof(COMMANDS[0]); |
|||
for (size_t i = 0; i < arraySize; i++) { |
|||
TEST_ASSERT_EQUAL_INT( 1, COMMANDS[i].fun(-1) ); |
|||
} |
|||
} |
|||
|
|||
|
|||
void test_callCommandById(void){ |
|||
// arrange |
|||
|
|||
// act |
|||
commandFunction actualCommand = getCommandById( 1 ); |
|||
|
|||
// assert |
|||
TEST_ASSERT_EQUAL_PTR( startMenu, actualCommand ); |
|||
} |
|||
|
|||
void test_callCommandById_startGame(void){ |
|||
// arrange |
|||
|
|||
// act |
|||
commandFunction actualCommand = getCommandById( 2); |
|||
|
|||
// assert |
|||
TEST_ASSERT_EQUAL_PTR( startGame, actualCommand ); |
|||
} |
@ -0,0 +1,162 @@ |
|||
#include "SchereSteinPapier.h" |
|||
#include "unity.h" |
|||
#include <stdlib.h> |
|||
|
|||
const int scissor = 1; |
|||
const int rock = 2; |
|||
const int paper = 3; |
|||
|
|||
void setUp(void) |
|||
{ |
|||
|
|||
} |
|||
|
|||
void tearDown(void) |
|||
{ |
|||
|
|||
} |
|||
|
|||
//Testfälle für Unentschieden |
|||
//1. Beide wählen Schere |
|||
void test_draw_USER_Scissor_COM_Scissor() |
|||
{ |
|||
//arrange |
|||
int expectedResult = 0; |
|||
//act |
|||
int actualResult = calculateWinner(scissor,scissor); |
|||
//assert |
|||
TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); |
|||
} |
|||
//2. Beide wählen Stein |
|||
void test_draw_USER_Rock_COM_Rock() |
|||
{ |
|||
//arrange |
|||
int expectedResult = 0; |
|||
//act |
|||
int actualResult = calculateWinner(rock,rock); |
|||
//assert |
|||
TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); |
|||
} |
|||
//3. Beide wählen Papier |
|||
void test_draw_USER_Paper_COM_Paper() |
|||
{ |
|||
//arrange |
|||
int expectedResult = 0; |
|||
//act |
|||
int actualResult = calculateWinner(paper,paper); |
|||
//assert |
|||
TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); |
|||
} |
|||
|
|||
|
|||
//Testfälle für Niederlage |
|||
//1. User wählt Schere, Computer wählt Stein |
|||
void test_lose_USER_Scissor_COM_Rock() |
|||
{ |
|||
//arrange |
|||
int expectedResult = -1; |
|||
//act |
|||
int actualResult = calculateWinner(scissor,rock); |
|||
//assert |
|||
TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); |
|||
} |
|||
//2. User wählt Papier, Computer wählt Schere |
|||
void test_lose_USER_Paper_COM_Scissor() |
|||
{ |
|||
//arrange |
|||
int expectedResult = -1; |
|||
//act |
|||
int actualResult = calculateWinner(paper,scissor); |
|||
//assert |
|||
TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); |
|||
} |
|||
//3. User wählt Stein, Computer wählt Papier |
|||
void test_lose_USER_Rock_COM_Paper() |
|||
{ |
|||
//arrange |
|||
int expectedResult = -1; |
|||
//act |
|||
int actualResult = calculateWinner(rock,paper); |
|||
//assert |
|||
TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); |
|||
} |
|||
|
|||
|
|||
//Testfälle für Sieg |
|||
//1. User wählt Schere, Computer wählt Papier |
|||
void test_win_USER_Scissor_COM_Paper() |
|||
{ |
|||
//arrange |
|||
int expectedResult = 1; |
|||
//act |
|||
int actualResult = calculateWinner(scissor,paper); |
|||
//assert |
|||
TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); |
|||
} |
|||
//2. User wählt Stein, Computer wählt Schere |
|||
void test_win_USER_Rock_COM_Scissor() |
|||
{ |
|||
//arrange |
|||
int expectedResult = 1; |
|||
//act |
|||
int actualResult = calculateWinner(rock,scissor); |
|||
//assert |
|||
TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); |
|||
} |
|||
//3. User wählt Papier, Computer wählt Stein |
|||
void test_win_USER_Paper_COM_Rock() |
|||
{ |
|||
//arrange |
|||
int expectedResult = 1; |
|||
//act |
|||
int actualResult = calculateWinner(paper,rock); |
|||
//assert |
|||
TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); |
|||
} |
|||
|
|||
|
|||
//Testfälle für ungültige Parameterübergabe |
|||
//1. Durch den User wurde ein ungültiges Parameter übergeben |
|||
// Der Computer wählt eine Zahl zwischen 1 und 3 |
|||
void test_error_USER_unknownParameter_Rock_randomChoice() |
|||
{ |
|||
//arrange |
|||
int expectedResult = 3; |
|||
//act |
|||
int actualResult = calculateWinner(5,rand() % 3 + 1); |
|||
//assert |
|||
TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); |
|||
} |
|||
//2. Der User wählt eine Zahl zwischen 1 und 3 |
|||
// Durch den Computer wurde ein ungültiges Parameter übergeben |
|||
void test_error_USER_randomChoice_Rock_unknownParameter() |
|||
{ |
|||
//arrange |
|||
int expectedResult = 3; |
|||
//act |
|||
int actualResult = calculateWinner(rand() % 3 + 1, 5); |
|||
//assert |
|||
TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); |
|||
} |
|||
//3. Der User wählt eine Zahl zwischen 1 und 3 |
|||
// Durch den Computer wurde das ungültige Parameter 0 übergeben |
|||
void test_error_USER_randomChoice_Rock_zero() |
|||
{ |
|||
//arrange |
|||
int expectedResult = 3; |
|||
//act |
|||
int actualResult = calculateWinner(rand() % 3 + 1, 0); |
|||
//assert |
|||
TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); |
|||
} |
|||
//4. Durch den User wurde das ungültige Parameter 0 übergeben |
|||
// Der Computer wählt eine Zahl zwischen 1 und 3 |
|||
void test_error_USER_zero_Rock_randomChoice() |
|||
{ |
|||
//arrange |
|||
int expectedResult = 3; |
|||
//act |
|||
int actualResult = calculateWinner(0, rand() % 3 + 1); |
|||
//assert |
|||
TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); |
|||
} |
@ -0,0 +1,24 @@ |
|||
#include "hangman.h" |
|||
#include "unity.h" |
|||
|
|||
|
|||
|
|||
void setUp(void) |
|||
{ |
|||
|
|||
} |
|||
|
|||
void tearDown(void) |
|||
{ |
|||
|
|||
} |
|||
|
|||
void test_ceedling_functionality() |
|||
{ |
|||
//arrange |
|||
int expectedResult = 0; |
|||
//act |
|||
int actualResult = 0; |
|||
//assert |
|||
TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue