Skip to content

Khalil coats code review#21

Open
KhalilxCoats wants to merge 2 commits intoSWE-CS410:mainfrom
KhalilxCoats:Khalil_Coats_CodeReview
Open

Khalil coats code review#21
KhalilxCoats wants to merge 2 commits intoSWE-CS410:mainfrom
KhalilxCoats:Khalil_Coats_CodeReview

Conversation

@KhalilxCoats
Copy link

No description provided.

Copy link

@silkycode silkycode left a comment

Choose a reason for hiding this comment

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

Good job with the code assignment! The majority of my comments are mostly in regards to small optimizations/readability improvements, so I don't consider them necessarily must-fix before approval. In the case of your unit testing, I believe that your tests largely cover the behavior cases that you expect from your methods, but I think that they could also be somewhat improved by refining their scope by splitting them up to test a single functionality per test.

-Nicholas C

@Override
public class StringManipulation implements StringManipulationInterface {

private String objString;

Choose a reason for hiding this comment

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

Good use of private access modifier to ensure encapsulation of class String member

public int count() {
return 0;

String[] words = this.getString().split(" +");
Copy link

@silkycode silkycode Jun 19, 2023

Choose a reason for hiding this comment

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

Good use of one-or-many whitespaces to split on, but because split() uses regex, perhaps you could go even a step farther and use "\s+" instead of " +" so that all potential characters that separate words (like newlines, whitespace, etc.) are split upon.

}
this.setString(String.valueOf(objChars));
}
else if(!maintainSpacing)

Choose a reason for hiding this comment

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

Could use just a simple else here since maintainSpacing only ever has two possibilities

else
{
returnList = new String[endWord-startWord+1];
int loopStart = startWord;

Choose a reason for hiding this comment

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

Can discard and use value of startWord in the following loop where loopStart is, since startWord is passed as an argument originally

{
throw new IllegalArgumentException("upper bound greater than lower bound");
}
else if(endWord > this.count())

Choose a reason for hiding this comment

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

Since you've already done the work of splitting the String into words in line 66, you could compare the length of that array instead of needing to call the count() method for error checking, but good idea to use existing methods

public String restoreString(int[] indices) {
return null;
public String restoreString(int[] indices){
String restore = "";

Choose a reason for hiding this comment

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

Really small optimization, but can throw the creation of the String to be returned after the error checking

{
newChars[i] = this.getString().charAt(indices[i]);
}
restore = (String.valueOf(newChars));

Choose a reason for hiding this comment

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

Using the String variable 'restore' is good for enhancing the readability of the code, but can also be left out since you could also return the 'newChars' array as a String with the same method you're using to assign it to 'restore'

//blanks out string, maintainSpacing=false
manipulatedstring.setString("the quick brown fox jumps over the lazy dog");
assertEquals("", manipulatedstring.removeNthCharacter(1, false));
}

Choose a reason for hiding this comment

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

6 and 7 are good tests, it is worth testing to verify a behavior that you'd expect like this when n = 1.


assertEquals("Word position argument must be positive nonzero number.", thrown.getMessage());
}

Choose a reason for hiding this comment

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

For getSubStrings() tests, because the behavior you're trying to verify is that the method throws an exception, the assertEquals statements may fall outside their scopes. The assertEquals() statements are best used in tests where you're testing the output, rather than the error checking.

Copy link

@TimSon1022 TimSon1022 left a comment

Choose a reason for hiding this comment

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

Overall the code looks well-structured and readable. There are some things you can change and edit but it's very small, so they are not necessarily prioritized changes. Great job though!

for(int i = 0; i < endWord- startWord+1; i++)
{
returnList[i] = words[loopStart - 1 + i];
System.out.println(returnList[i]);

Choose a reason for hiding this comment

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

Make sure to remove any debugging System.out.println statements that are not needed in the final code

}
else if(n > this.getString().length()-1)
{
throw new IndexOutOfBoundsException("index out of bounds");

Choose a reason for hiding this comment

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

The error message can be more descriptive here for if n is more than the string's length minus 1

}
else if(endWord > this.count())
{
throw new IndexOutOfBoundsException("upper bound or lower is greater than word count");

Choose a reason for hiding this comment

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

In the error statement, you can add to the statement "or startWord is larger than the word count" to complete your error message.

public int count() {
return 0;

String[] words = this.getString().split(" +");

Choose a reason for hiding this comment

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

you can use \s+ instead of + so it can represent all whitespace characters

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