As title says, im having trouble with my junit tests passing for checking if a character is not in a string and how to check if an empty string doesnt have a character. here is the method i have:
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);
}
}
Thank you very much, appreciated