Skip to content

Thomas/Paige Riffle Code Review Pull Request#33

Open
Trifflenator wants to merge 1 commit intoSWE-CS410:mainfrom
Trifflenator:main
Open

Thomas/Paige Riffle Code Review Pull Request#33
Trifflenator wants to merge 1 commit intoSWE-CS410:mainfrom
Trifflenator:main

Conversation

@Trifflenator
Copy link

Late due to family affairs yesterday and today.

@sarafarag sarafarag requested a review from kemeng001 June 19, 2023 23:07
Copy link

@kemeng001 kemeng001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation and testing are generally very good, but there is still some room for improvement to make the code more robust.

public int count() {
return 0;
//checks for null or 'empty' one char strings, anything more is a bit beyond scope of project
if( str == null || str == " ") {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More exceptions may make this method more robust, for example, handling strings that contain only spaces, or strings that contain punctuation and other non-alphabetic characters.

return 0;
//checks for null or 'empty' one char strings, anything more is a bit beyond scope of project
if( str == null || str == " ") {
return 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other methods, invalid inputs lead to an IllegalArgumentException, to shows the user why this error happens, we may need similar Exception in this method, to make user understand why this input is illegal.

return null;
public String restoreString(int[] indices){
//Exception for incorrect int array
if(indices.length != str.length()) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check whether indices is null before using may make the code more robust, or when try to use indices.length may cause NullPointerException.

Exception exception = assertThrows(IllegalArgumentException.class, () -> {manipulatedstring.getSubStrings(0, 1);});
String expected = "startWord must be greater than zero";
String actual = exception.getMessage();
assertTrue(actual == expected);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other test cases use assertEquals to check the actual and expected value, but this one uses assertTrue, in this way, we cannot see the difference between the actual and expected value.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation basically meets the performance and functional requirements, but still needs to be improved in some places to achieve better robustness.

@spadeX6 spadeX6 self-requested a review June 20, 2023 06:21
Copy link

@spadeX6 spadeX6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation is good overall, approving!

@Override
public String[] getSubStrings(int startWord, int endWord) {
return null;
public String[] getSubStrings(int startWord, int endWord){
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding Exception Handling: This method is doing a great job of validating its input parameters and throwing exceptions accordingly. However, the error messages could be made a little more user-friendly, perhaps by including the invalid value in the message itself for quick reference.

On String Concatenation: In the loop where words are constructed using result[words] += str.charAt(x);, it's important to remember that strings in Java are immutable and that each concatenation results in the creation of a new object. This could potentially be inefficient in terms of memory usage, especially for long strings. Consider using a StringBuilder for constructing the words, which would be more efficient.

On Loop Control Variable 'x': The variable 'x' is being used to track the index in the original string. It would be helpful to provide a more descriptive name for this variable to make the code more readable.

On Variable Naming: The variables startWord, endWord, and words are well named and convey their purpose effectively. However, x and i could be renamed to something more descriptive to further improve readability. For example, x could be renamed to charIndex and i could be renamed to wordIndex. This could help other developers understand the code more quickly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants