Add final project implementation from Assignment 2#8
Conversation
brunochristensen
left a comment
There was a problem hiding this comment.
The code looks good and functional, I would just think about expanding the scope of your test cases.
| String[] words = string.trim().split("\\s+"); | ||
| int numWords = words.length; | ||
|
|
||
| if (startWord <= 0 || endWord <= 0 || startWord > endWord) { |
There was a problem hiding this comment.
This might be more of a style choice, but wouldn't it make more sense to throw exceptions before executing business logic?
| char[] restoredChars = new char[chars.length]; | ||
| for (int i = 0; i < indices.length; i++) { | ||
| int index = indices[i]; | ||
| if (index < 0 || index >= chars.length) { |
There was a problem hiding this comment.
Would it make more sense to verify the integrity of your data prior to when you start executing the logic of the method?
| public void testRemoveNthCharacter6() { | ||
| fail("Not yet implemented"); | ||
| manipulatedString.setString("Exception testing1"); | ||
| assertEquals("Don't mind this", manipulatedString.removeNthCharacter(0, true)); |
There was a problem hiding this comment.
JUnit does provide a assertThrows() method to test exception handling. It would probably be better than relying on the exception methods returning string.
| throw new IndexOutOfBoundsException("n exceeds string length"); | ||
| } | ||
| StringBuilder result = new StringBuilder(); | ||
| char[] chars = string.toCharArray(); |
There was a problem hiding this comment.
It doesn't look like you ever do anything with the chars variable.
|
|
||
| @Test | ||
| public void testCount2() { | ||
| fail("Not yet implemented"); |
There was a problem hiding this comment.
I would consider adding more variety or some edge cases to your testing. Maybe add some sentences with unconventional spacing for characters.
| if (string == null) { | ||
| return 0; | ||
| } | ||
| String[] words = string.trim().split("\\s+"); |
There was a problem hiding this comment.
trim() is probably an unnecessary step to separate word by whitespace.
| fail("Not yet implemented"); | ||
| manipulatedString.setString("Why there are so many test cases to create"); | ||
| String [] sStings = manipulatedString.getSubStrings(0, 6); | ||
|
|
There was a problem hiding this comment.
How is this testing if an exception is thrown? What are the mechanics behind this?
| manipulatedString.setString("art"); | ||
| int [] array; | ||
| array=new int[]{2,0,1}; | ||
| String restoreString = manipulatedString.restoreString(array); |
There was a problem hiding this comment.
What would happen if the array argument uses duplicate values?
No description provided.