From a19e5d9bfca49eca1d0d577586f26b76a8b228cf Mon Sep 17 00:00:00 2001 From: Habib Date: Sun, 4 Feb 2024 17:31:22 +0100 Subject: [PATCH] =?UTF-8?q?characterAppearanceInString()=20definiert=20und?= =?UTF-8?q?=20einen=20Test=20f=C3=BCr=20die=20Funktion=20geschrieben?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/c/funktionen.c | 12 ++++++++++++ src/test/test_funktionen.c | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/c/funktionen.c b/src/c/funktionen.c index d7b310b..c1ba980 100644 --- a/src/c/funktionen.c +++ b/src/c/funktionen.c @@ -63,4 +63,16 @@ int string_character_counter(char string[]) { } return stringLength; +} + +int characterAppearanceInString(char c, char string[]) { + int appear = 0; + + for (int i = 0; i < string_character_counter(string); i++) { + if (string[i] == c) { + appear++; + } + } + + return appear; } \ No newline at end of file diff --git a/src/test/test_funktionen.c b/src/test/test_funktionen.c index 2f82c60..37852c4 100644 --- a/src/test/test_funktionen.c +++ b/src/test/test_funktionen.c @@ -121,4 +121,20 @@ void test_stringLaenge_von_Kokosnuss(void) TEST_ASSERT_EQUAL_INT(expected, actual); } +void test_howManyTimes_e_appearsIn_Beere(void) +{ + /* arrange */ + int actual; + int expected = 3; + + char c = 'e'; + char string[] = "Beere"; + + /* act */ + actual = characterAppearanceInString(c, string); + + /* assert */ + TEST_ASSERT_EQUAL_INT(expected, actual); +} + #endif \ No newline at end of file