Skip to content

FINAL Peer Review updated with my code#12

Open
puleri wants to merge 8 commits intomainfrom
Matthew_Puleri_CodeReview
Open

FINAL Peer Review updated with my code#12
puleri wants to merge 8 commits intomainfrom
Matthew_Puleri_CodeReview

Conversation

@puleri
Copy link

@puleri puleri commented Jun 15, 2023

Updated

@sarafarag sarafarag requested a review from mdbonner June 15, 2023 18:51
@sarafarag sarafarag requested review from YukiRivera and removed request for mdbonner June 15, 2023 20:14
Copy link

@YukiRivera YukiRivera left a comment

Choose a reason for hiding this comment

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

Hi, Matthew! It was great I got this opportunity to see how others solved the same problems and I feel privileged to review yours. It was a relief to see my code is not too far from yours:)
I gave you alternatives in some of my comments, but they are really for sharing ideas.
One part you would probably want to actually change is testCount4( ). Please see the details in my comment for testCount4( ).

Comment on lines +103 to +113
String[] restoredStringArray = new String[indices.length];

for (int i = 0; i < indices.length; i++) {
int oldIndex = indices[i];
if (oldIndex < 0 || oldIndex >= string.length()) {
throw new IndexOutOfBoundsException();
}
restoredStringArray[i] = String.valueOf(string.charAt(oldIndex));
}

return String.join("", restoredStringArray);

Choose a reason for hiding this comment

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

Your restoreString() basically has the same logic as mine and there is nothing wrong with your code:)
Just to share, instead of an array, a StringBuilder could be used as an alternative, which I used in my code. The same operation can be performed with append() for the StringBuilder, then return the string representation by using toString() on the StringBuilder.

Comment on lines 48 to 68
StringBuilder stringBuilder = new StringBuilder();
String phrase = "the quick brown fox jumps over the lazy dog";
int occurrences = 0;

for (int i = 0; i < 100; i++) {
stringBuilder.append(phrase);
stringBuilder.append("\n");
}

String longString = stringBuilder.toString();
int index = 0;
while (index < longString.length()) {
index = longString.indexOf(phrase, index);
if (index == -1) {
break;
}
occurrences++;
index += phrase.length();
}

assertEquals(100, occurrences);

Choose a reason for hiding this comment

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

testCount4( ):
I'm sure this is a working code, but I don't think you actually used count() in it...
You might want to rewrite this test case so that it tests the count() in StringManipulation class.
You could write a test case for a long string or even for an empty string.

@puleri
Copy link
Author

puleri commented Jun 16, 2023

Thank you so much @YukiRivera
Your review is thoughtful. Good catch on the testCount4 test-- I can't believe I missed that!
I hope we get to work at the same company one day!

I made the changes to fix that test case and testCount4 is passing

@puleri puleri requested a review from YukiRivera June 16, 2023 21:29
Copy link

@YukiRivera YukiRivera left a comment

Choose a reason for hiding this comment

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

Hi Matthew, I see your testCount4( ) has been updated and resolved the issue you had. I'm submitting my review with "Approve" this time:) Thank you!

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