From c34a836381ce28cccd5eee9bf1ec99866f830b4e Mon Sep 17 00:00:00 2001 From: Habib Date: Sun, 4 Feb 2024 17:03:59 +0100 Subject: [PATCH] =?UTF-8?q?string=5Fcharacter=5Fcounter()=20definiert=20un?= =?UTF-8?q?d=20einen=20Test=20f=C3=BCr=20die=20Funktion=20erstellt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/c/funktionen.c | 10 ++++++++++ src/test/test_funktionen.c | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/c/funktionen.c b/src/c/funktionen.c index d09e661..d7b310b 100644 --- a/src/c/funktionen.c +++ b/src/c/funktionen.c @@ -53,4 +53,14 @@ int x_wins_01_11_21(char board[][3]) { if (board[0][1] == 'X' && board[1][1] == 'X' && board[2][1] == 'X') { return 1; } +} + +int string_character_counter(char string[]) { + int stringLength = 0; + + for (int i = 0; string[i] != '\0'; i++) { + stringLength++; + } + + return stringLength; } \ No newline at end of file diff --git a/src/test/test_funktionen.c b/src/test/test_funktionen.c index 2f16f48..2f82c60 100644 --- a/src/test/test_funktionen.c +++ b/src/test/test_funktionen.c @@ -106,4 +106,19 @@ void test_x_wins_onIndex_01_11_21(void) TEST_ASSERT_EQUAL_INT(expected, actual); } +void test_stringLaenge_von_Kokosnuss(void) +{ + /* arrange */ + int actual; + int expected = 9; + + char string[] = "Kokosnuss"; + + /* act */ + actual = string_character_counter(string); + + /* assert */ + TEST_ASSERT_EQUAL_INT(expected, actual); +} + #endif \ No newline at end of file