Skip to content

updated w/ final implementation and tests#9

Open
brunochristensen wants to merge 1 commit intomainfrom
Bruno_Chritensen_CodeReview
Open

updated w/ final implementation and tests#9
brunochristensen wants to merge 1 commit intomainfrom
Bruno_Chritensen_CodeReview

Conversation

@brunochristensen
Copy link

No description provided.

@sarafarag sarafarag requested a review from will-eand June 14, 2023 18:27
Copy link

@will-eand will-eand left a comment

Choose a reason for hiding this comment

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

General comment: I think your methods are both very concise and your variables names are chosen good. It was difficult to find glaring issues in your logic. There were a few edge cases not considered in your test file and I made comments that addressed those topics. Great job, especially on the part where you checked for duplicates by making a helper method using the set method.


public class StringManipulation implements StringManipulationInterface {

String s;

Choose a reason for hiding this comment

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

On line 8, the data field String s should be private. The business logic of the code needs to incorporate encapsulation to protect from external access.

public String removeNthCharacter(int n, boolean maintainSpacing) {
return null;
if (n <= 0) {
throw new IllegalArgumentException();

Choose a reason for hiding this comment

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

It may be helpful to provide am message pertaining to the exact reason illegalArgumentException is called. This may help clarify during testing to save some time.

public String restoreString(int[] indices) {
return null;
public String restoreString(int[] indices){
if(indices.length != s.length() || duplicates(indices)){

Choose a reason for hiding this comment

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

Utilizing a set here to check for duplicates is nice way and optimal way to compare for duplicates. You helped me realize that I might not have done this for my own method. Well done.

array=new int[]{1,0,2,3};
assertThrows(IllegalArgumentException.class, () -> manipulatedstring.restoreString(array));
}

Choose a reason for hiding this comment

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

Your code handles illegalArgumentException in two situations; the first is when there are duplicates, and the second when the size of the array is either too big or too small relative to the length of the string. I see you testing the duplicates well, but what about different length of arrays being inputted? Another testRestoreString6 could be here.

}

//This test handles IllegalArgumentException for improper start and end values
@Test
Copy link

@will-eand will-eand Jun 14, 2023

Choose a reason for hiding this comment

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

This test case is redundant. The test above tests the exact same thing as below. you're Testing the situation where the startWord is greater than the endWord, but there is also the possibility the start word and end words are the same, OR that the parameter inputs a negative number on accident. These are other cases you can test.

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.

2 participants