Browse Source

characterAppearanceInString() definiert und einen Test für die Funktion geschrieben

remotes/origin/habib
Habib 11 months ago
parent
commit
a19e5d9bfc
  1. 12
      src/c/funktionen.c
  2. 16
      src/test/test_funktionen.c

12
src/c/funktionen.c

@ -64,3 +64,15 @@ int string_character_counter(char string[]) {
return stringLength; 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;
}

16
src/test/test_funktionen.c

@ -121,4 +121,20 @@ void test_stringLaenge_von_Kokosnuss(void)
TEST_ASSERT_EQUAL_INT(expected, actual); 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 #endif
Loading…
Cancel
Save