From 6fdccd7ef13f314b7829b0afecc2e6a4aaa0a10c Mon Sep 17 00:00:00 2001 From: KaffeeMaus Date: Thu, 25 Jan 2024 21:30:20 +0100 Subject: [PATCH 01/11] add my files --- src/main/c/Georg/tictactoe.c | 4 ++++ src/main/c/Georg/tictactoe.h | 5 +++++ src/test/c/Georg/test_tictactoe.c | 15 +++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 src/main/c/Georg/tictactoe.c create mode 100644 src/main/c/Georg/tictactoe.h create mode 100644 src/test/c/Georg/test_tictactoe.c diff --git a/src/main/c/Georg/tictactoe.c b/src/main/c/Georg/tictactoe.c new file mode 100644 index 0000000..87680a0 --- /dev/null +++ b/src/main/c/Georg/tictactoe.c @@ -0,0 +1,4 @@ +#include +#include + +#include "tictactoe.h" diff --git a/src/main/c/Georg/tictactoe.h b/src/main/c/Georg/tictactoe.h new file mode 100644 index 0000000..ca8f3ae --- /dev/null +++ b/src/main/c/Georg/tictactoe.h @@ -0,0 +1,5 @@ +#ifndef TICTACTOE_H +#define TICTACTOE_H + + +#endif //TICTACTOE_H diff --git a/src/test/c/Georg/test_tictactoe.c b/src/test/c/Georg/test_tictactoe.c new file mode 100644 index 0000000..95b2edc --- /dev/null +++ b/src/test/c/Georg/test_tictactoe.c @@ -0,0 +1,15 @@ +#include "tictactoe.h" +#include "unity.h" + +void setup(void){ + +} + +void tearDown(void){ + +} + +void test_compileTest_shutBeAllwaysTrue(void){ + TEST_ASSERT_EQUAL_INT(1,1); +} + From 7ffbb05393e719cd55f1f6d1c012db8d5311044f Mon Sep 17 00:00:00 2001 From: KaffeeMaus Date: Fri, 26 Jan 2024 10:54:39 +0100 Subject: [PATCH 02/11] welcome message added --- src/main/c/Georg/tictactoe.c | 4 ++++ src/main/c/Georg/tictactoe.h | 1 + src/test/c/Georg/test_tictactoe.c | 10 ++++++++++ 3 files changed, 15 insertions(+) diff --git a/src/main/c/Georg/tictactoe.c b/src/main/c/Georg/tictactoe.c index 87680a0..c97a735 100644 --- a/src/main/c/Georg/tictactoe.c +++ b/src/main/c/Georg/tictactoe.c @@ -2,3 +2,7 @@ #include #include "tictactoe.h" + +char* getWelcomeMessage(){ + return "Hallo und willkommen zu unserem TicTacToe Spiel. Anbei die Anleitung:\n"; +} \ No newline at end of file diff --git a/src/main/c/Georg/tictactoe.h b/src/main/c/Georg/tictactoe.h index ca8f3ae..9ac6a1f 100644 --- a/src/main/c/Georg/tictactoe.h +++ b/src/main/c/Georg/tictactoe.h @@ -1,5 +1,6 @@ #ifndef TICTACTOE_H #define TICTACTOE_H +char* getWelcomeMessage(); #endif //TICTACTOE_H diff --git a/src/test/c/Georg/test_tictactoe.c b/src/test/c/Georg/test_tictactoe.c index 95b2edc..05fa62c 100644 --- a/src/test/c/Georg/test_tictactoe.c +++ b/src/test/c/Georg/test_tictactoe.c @@ -13,3 +13,13 @@ 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 = getWelcomeMessage(); + + // aassert + TEST_ASSERT_EQUAL_STRING(expectedMessage, message); +} \ No newline at end of file From e2f9678cbbfa228e45bf3a27fb15fb5767d2bb21 Mon Sep 17 00:00:00 2001 From: KaffeeMaus Date: Fri, 26 Jan 2024 10:56:26 +0100 Subject: [PATCH 03/11] rules message added --- src/main/c/Georg/tictactoe.c | 10 +++++++++- src/main/c/Georg/tictactoe.h | 1 + src/test/c/Georg/test_tictactoe.c | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/main/c/Georg/tictactoe.c b/src/main/c/Georg/tictactoe.c index c97a735..7134783 100644 --- a/src/main/c/Georg/tictactoe.c +++ b/src/main/c/Georg/tictactoe.c @@ -5,4 +5,12 @@ char* getWelcomeMessage(){ return "Hallo und willkommen zu unserem TicTacToe Spiel. Anbei die Anleitung:\n"; -} \ No newline at end of file +} + +char* getRulesMessage(){ + 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."; +} diff --git a/src/main/c/Georg/tictactoe.h b/src/main/c/Georg/tictactoe.h index 9ac6a1f..72778f5 100644 --- a/src/main/c/Georg/tictactoe.h +++ b/src/main/c/Georg/tictactoe.h @@ -2,5 +2,6 @@ #define TICTACTOE_H char* getWelcomeMessage(); +char* getRulesMessage(); #endif //TICTACTOE_H diff --git a/src/test/c/Georg/test_tictactoe.c b/src/test/c/Georg/test_tictactoe.c index 05fa62c..cc7b353 100644 --- a/src/test/c/Georg/test_tictactoe.c +++ b/src/test/c/Georg/test_tictactoe.c @@ -22,4 +22,19 @@ void test_welcome_message(void){ // 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 = getRulesMessage(); + + // assert + TEST_ASSERT_EQUAL_STRING(expectedMessage, message); } \ No newline at end of file From b2938395d128f41435b3323b21620035419bb9a5 Mon Sep 17 00:00:00 2001 From: KaffeeMaus Date: Fri, 26 Jan 2024 10:58:48 +0100 Subject: [PATCH 04/11] add ga structure that holds the game informations --- src/main/c/Georg/tictactoe.c | 2 ++ src/main/c/Georg/tictactoe.h | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/main/c/Georg/tictactoe.c b/src/main/c/Georg/tictactoe.c index 7134783..4b91348 100644 --- a/src/main/c/Georg/tictactoe.c +++ b/src/main/c/Georg/tictactoe.c @@ -3,6 +3,8 @@ #include "tictactoe.h" +struct ticTacToe TICTACTOE; + char* getWelcomeMessage(){ return "Hallo und willkommen zu unserem TicTacToe Spiel. Anbei die Anleitung:\n"; } diff --git a/src/main/c/Georg/tictactoe.h b/src/main/c/Georg/tictactoe.h index 72778f5..d8b2a20 100644 --- a/src/main/c/Georg/tictactoe.h +++ b/src/main/c/Georg/tictactoe.h @@ -1,6 +1,10 @@ #ifndef TICTACTOE_H #define TICTACTOE_H +struct ticTacToe{ + int currentState; +}; + char* getWelcomeMessage(); char* getRulesMessage(); From f74e8420bb5067c14c62f352485677f92f137e09 Mon Sep 17 00:00:00 2001 From: KaffeeMaus Date: Fri, 26 Jan 2024 11:02:41 +0100 Subject: [PATCH 05/11] add a test for the initialization of the game info structure --- src/main/c/Georg/tictactoe.c | 6 ++++++ src/main/c/Georg/tictactoe.h | 1 + src/test/c/Georg/test_tictactoe.c | 12 ++++++++++++ 3 files changed, 19 insertions(+) diff --git a/src/main/c/Georg/tictactoe.c b/src/main/c/Georg/tictactoe.c index 4b91348..f531dd4 100644 --- a/src/main/c/Georg/tictactoe.c +++ b/src/main/c/Georg/tictactoe.c @@ -16,3 +16,9 @@ char* getRulesMessage(){ "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; +} \ No newline at end of file diff --git a/src/main/c/Georg/tictactoe.h b/src/main/c/Georg/tictactoe.h index d8b2a20..cc05322 100644 --- a/src/main/c/Georg/tictactoe.h +++ b/src/main/c/Georg/tictactoe.h @@ -7,5 +7,6 @@ struct ticTacToe{ char* getWelcomeMessage(); char* getRulesMessage(); +struct ticTacToe createTicTacToe(); #endif //TICTACTOE_H diff --git a/src/test/c/Georg/test_tictactoe.c b/src/test/c/Georg/test_tictactoe.c index cc7b353..cce0a6f 100644 --- a/src/test/c/Georg/test_tictactoe.c +++ b/src/test/c/Georg/test_tictactoe.c @@ -37,4 +37,16 @@ void test_rules_message(void){ // 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 ); } \ No newline at end of file From de794a0f4211f5ab3b48dca7ef8959c7e0293bc9 Mon Sep 17 00:00:00 2001 From: KaffeeMaus Date: Fri, 26 Jan 2024 11:03:53 +0100 Subject: [PATCH 06/11] added a function that evaluates user input --- src/main/c/Georg/tictactoe.c | 7 +++++++ src/main/c/Georg/tictactoe.h | 1 + src/test/c/Georg/test_tictactoe.c | 12 ++++++++++++ 3 files changed, 20 insertions(+) diff --git a/src/main/c/Georg/tictactoe.c b/src/main/c/Georg/tictactoe.c index f531dd4..961789b 100644 --- a/src/main/c/Georg/tictactoe.c +++ b/src/main/c/Georg/tictactoe.c @@ -1,5 +1,6 @@ #include #include +#include #include "tictactoe.h" @@ -21,4 +22,10 @@ struct ticTacToe createTicTacToe() { struct ticTacToe newGame; newGame.currentState = 0; return newGame; +} + +int handleState( char* input ){ + if( strcmp(input, "start game") == 0 ){ + return 1; + } } \ No newline at end of file diff --git a/src/main/c/Georg/tictactoe.h b/src/main/c/Georg/tictactoe.h index cc05322..2091478 100644 --- a/src/main/c/Georg/tictactoe.h +++ b/src/main/c/Georg/tictactoe.h @@ -8,5 +8,6 @@ struct ticTacToe{ char* getWelcomeMessage(); char* getRulesMessage(); struct ticTacToe createTicTacToe(); +int handleState( char* input ); #endif //TICTACTOE_H diff --git a/src/test/c/Georg/test_tictactoe.c b/src/test/c/Georg/test_tictactoe.c index cce0a6f..cd209a9 100644 --- a/src/test/c/Georg/test_tictactoe.c +++ b/src/test/c/Georg/test_tictactoe.c @@ -49,4 +49,16 @@ void test_initial_state(void){ // assert TEST_ASSERT_EQUAL_INT( expectedState, newGame.currentState ); +} + +void test_userInput(void){ + // arrange + int expectedState = 1; + char* input = "start game"; + + // act + int actualState = handleState( input ); + + // assert + TEST_ASSERT_EQUAL_INT( expectedState, actualState ); } \ No newline at end of file From f921aaaf1c1893d1cce3b48aea7023dc6350fa78 Mon Sep 17 00:00:00 2001 From: KaffeeMaus Date: Fri, 26 Jan 2024 11:05:31 +0100 Subject: [PATCH 07/11] refactoring: commandHandler --- src/main/c/Georg/tictactoe.c | 2 +- src/main/c/Georg/tictactoe.h | 2 +- src/test/c/Georg/test_tictactoe.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/c/Georg/tictactoe.c b/src/main/c/Georg/tictactoe.c index 961789b..8501c52 100644 --- a/src/main/c/Georg/tictactoe.c +++ b/src/main/c/Georg/tictactoe.c @@ -24,7 +24,7 @@ struct ticTacToe createTicTacToe() { return newGame; } -int handleState( char* input ){ +int handeCommand( char* input ){ if( strcmp(input, "start game") == 0 ){ return 1; } diff --git a/src/main/c/Georg/tictactoe.h b/src/main/c/Georg/tictactoe.h index 2091478..1500ee2 100644 --- a/src/main/c/Georg/tictactoe.h +++ b/src/main/c/Georg/tictactoe.h @@ -8,6 +8,6 @@ struct ticTacToe{ char* getWelcomeMessage(); char* getRulesMessage(); struct ticTacToe createTicTacToe(); -int handleState( char* input ); +int handeCommand( char* input ); #endif //TICTACTOE_H diff --git a/src/test/c/Georg/test_tictactoe.c b/src/test/c/Georg/test_tictactoe.c index cd209a9..8984fb8 100644 --- a/src/test/c/Georg/test_tictactoe.c +++ b/src/test/c/Georg/test_tictactoe.c @@ -51,13 +51,13 @@ void test_initial_state(void){ TEST_ASSERT_EQUAL_INT( expectedState, newGame.currentState ); } -void test_userInput(void){ +void test_command_startGame(void){ // arrange int expectedState = 1; char* input = "start game"; // act - int actualState = handleState( input ); + int actualState = handeCommand( input ); // assert TEST_ASSERT_EQUAL_INT( expectedState, actualState ); From 17bdcd90a7a6adbeec70d0534e336a7d8e03e016 Mon Sep 17 00:00:00 2001 From: KaffeeMaus Date: Fri, 26 Jan 2024 11:06:08 +0100 Subject: [PATCH 08/11] added another command --- src/main/c/Georg/tictactoe.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/c/Georg/tictactoe.c b/src/main/c/Georg/tictactoe.c index 8501c52..de5401b 100644 --- a/src/main/c/Georg/tictactoe.c +++ b/src/main/c/Georg/tictactoe.c @@ -27,5 +27,7 @@ struct ticTacToe createTicTacToe() { int handeCommand( char* input ){ if( strcmp(input, "start game") == 0 ){ return 1; + }else if( strcmp(input, "start menu") == 0 ){ + return 0; } } \ No newline at end of file From 5dc45b9943bb3a8944beacb0c3016663c3c96b03 Mon Sep 17 00:00:00 2001 From: KaffeeMaus Date: Fri, 26 Jan 2024 11:06:36 +0100 Subject: [PATCH 09/11] added a test case for the command --- src/test/c/Georg/test_tictactoe.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/c/Georg/test_tictactoe.c b/src/test/c/Georg/test_tictactoe.c index 8984fb8..102ef7a 100644 --- a/src/test/c/Georg/test_tictactoe.c +++ b/src/test/c/Georg/test_tictactoe.c @@ -59,6 +59,18 @@ void test_command_startGame(void){ // act int actualState = handeCommand( input ); + // assert + TEST_ASSERT_EQUAL_INT( expectedState, actualState ); +} + +void test_command_startMenu(void){ + // arrange + int expectedState = 0; + char* input = "start menu"; + + // act + int actualState = handeCommand( input ); + // assert TEST_ASSERT_EQUAL_INT( expectedState, actualState ); } \ No newline at end of file From e52cfccaa0bd45aa3a955ce57fe21eef3fe83bfa Mon Sep 17 00:00:00 2001 From: KaffeeMaus Date: Fri, 26 Jan 2024 11:07:11 +0100 Subject: [PATCH 10/11] refactoring: handleCommand --- src/main/c/Georg/tictactoe.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/c/Georg/tictactoe.c b/src/main/c/Georg/tictactoe.c index de5401b..a5955ee 100644 --- a/src/main/c/Georg/tictactoe.c +++ b/src/main/c/Georg/tictactoe.c @@ -25,9 +25,9 @@ struct ticTacToe createTicTacToe() { } int handeCommand( char* input ){ - if( strcmp(input, "start game") == 0 ){ - return 1; - }else if( strcmp(input, "start menu") == 0 ){ + if( strcmp(input, "start menu") == 0 ){ return 0; + }else if( strcmp(input, "start game") == 0 ){ + return 1; } } \ No newline at end of file From 04e8045c7c42366aa21b5e85bfa43a9462718cac Mon Sep 17 00:00:00 2001 From: KaffeeMaus Date: Fri, 26 Jan 2024 11:08:48 +0100 Subject: [PATCH 11/11] refactoring: typo --- src/main/c/Georg/tictactoe.c | 2 +- src/main/c/Georg/tictactoe.h | 2 +- src/test/c/Georg/test_tictactoe.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/c/Georg/tictactoe.c b/src/main/c/Georg/tictactoe.c index a5955ee..c3b5525 100644 --- a/src/main/c/Georg/tictactoe.c +++ b/src/main/c/Georg/tictactoe.c @@ -24,7 +24,7 @@ struct ticTacToe createTicTacToe() { return newGame; } -int handeCommand( char* input ){ +int handleCommand( char* input ){ if( strcmp(input, "start menu") == 0 ){ return 0; }else if( strcmp(input, "start game") == 0 ){ diff --git a/src/main/c/Georg/tictactoe.h b/src/main/c/Georg/tictactoe.h index 1500ee2..d054a66 100644 --- a/src/main/c/Georg/tictactoe.h +++ b/src/main/c/Georg/tictactoe.h @@ -8,6 +8,6 @@ struct ticTacToe{ char* getWelcomeMessage(); char* getRulesMessage(); struct ticTacToe createTicTacToe(); -int handeCommand( char* input ); +int handleCommand( char* input ); #endif //TICTACTOE_H diff --git a/src/test/c/Georg/test_tictactoe.c b/src/test/c/Georg/test_tictactoe.c index 102ef7a..546dc88 100644 --- a/src/test/c/Georg/test_tictactoe.c +++ b/src/test/c/Georg/test_tictactoe.c @@ -57,7 +57,7 @@ void test_command_startGame(void){ char* input = "start game"; // act - int actualState = handeCommand( input ); + int actualState = handleCommand( input ); // assert TEST_ASSERT_EQUAL_INT( expectedState, actualState ); @@ -69,7 +69,7 @@ void test_command_startMenu(void){ char* input = "start menu"; // act - int actualState = handeCommand( input ); + int actualState = handleCommand( input ); // assert TEST_ASSERT_EQUAL_INT( expectedState, actualState );