As the name says, I am having problems passing junit tests to check if there is a character in a string and how to check if an empty string contains a character. here is my method:
public static boolean isThere(String s, char value){
for(int x = 0; x <= s.length(); x++){
if(s.charAt(x) == value){
return true;
} else if(s.length() == 0){
return false;
}
}
return false;
And here is the junit test:
public void testIsThere() {
{
String sVal = "Jeff George";
boolean hasA = StringMethods.isThere(sVal,'e');
assertTrue(hasA);
boolean hasE = StringMethods.isThere(sVal, 'o');
assertTrue(hasE);
boolean notIn = StringMethods.isThere(sVal,'b');
assertTrue(notIn);
}
{
String sVal = "";
boolean nothingIn = StringMethods.isThere(sVal,'a');
assertFalse(nothingIn);
boolean notIn = StringMethods.isThere(sVal,'b');
assertFalse(notIn);
}
}
Thanks, appreciated
source
share