Conversation
| private String s; | ||
|
|
||
| @Override | ||
| public void setString(String s) { |
There was a problem hiding this comment.
The code checks for null or empty string in the count() and getSubStrings() methods, which is good. However, it doesn't handle null or empty string input in the setString() method. You might want to add a check for that.
| if (start < 0 || end > words.length || start > end) { | ||
| return new String[0]; | ||
| } | ||
| return Arrays.copyOfRange(words, start, end+1); |
There was a problem hiding this comment.
The getSubStrings() method splits the string into words using \s+ as the delimiter. It then returns a substring array based on the provided start and end indices. However, the end index is exclusive in Arrays.copyOfRange(), so you could use end instead of end+1 when copying the range
| public void tearDown() { | ||
| manipulatedstring = null; | ||
| } | ||
|
|
There was a problem hiding this comment.
You could add comments before each test case to explain what each one is verifying.
| int length = manipulatedstring.count(); | ||
| assertEquals(1, length); | ||
| } | ||
|
|
There was a problem hiding this comment.
You could add some tests to handle if the string is empty or if after removing you end up with an empty string
| manipulatedstring.setString("123"); | ||
| assertEquals("12", manipulatedstring.removeNthCharacter(3, false)); | ||
| } | ||
|
|
There was a problem hiding this comment.
You handle the testSubString cases really well but you may want to add exception handling for if the indices are out of bound.
update