Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve range split function and add unit tests #553

Open
wants to merge 7 commits into
base: @Skalakid/fix-emoji-formatting
Choose a base branch
from

Conversation

289Adam289
Copy link

Details

This pr improves time complexity of splitRangesOnEmoji and adds unit tests

Related Issues

GH_LINK

Manual Tests

The same tests like in linked pr.

Linked PRs

#534

Copy link

github-actions bot commented Nov 27, 2024

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@289Adam289
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

CLABotify added a commit to Expensify/CLA that referenced this pull request Nov 27, 2024
@289Adam289 289Adam289 changed the title @289 adam289/improve split add unit tests @289adam289/improve split add unit tests Nov 27, 2024
@289Adam289 289Adam289 changed the title @289adam289/improve split add unit tests Improve range split function and add unit tests Nov 27, 2024
@289Adam289 289Adam289 marked this pull request as ready for review December 11, 2024 09:54
@Skalakid Skalakid requested a review from tomekzaw December 11, 2024 09:57
@tomekzaw tomekzaw requested review from tomekzaw and removed request for tomekzaw December 11, 2024 16:48
android/build.gradle Outdated Show resolved Hide resolved
Comment on lines 16 to 20
private void testRange(MarkdownRange range, int start, int end, String type) {
assertEquals(start, range.getStart());
assertEquals(end, range.getEnd());
assertEquals(type, range.getType());
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of implementing a custom testRange function (which btw should be named assertRangeStartEndType or something along these lines), let's just implement MarkdownRange#equals method and rewrite the assertions in the unit tests like:

assertEquals(new MarkdownRange("type", 0, 1, 0), markdownRanges.get(0));

This way we get more readable logs (with expected and actual value) if test fails rather than some generic assertion error in utility method.

Copy link
Author

Choose a reason for hiding this comment

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

To ensure more readable logs I've added also simple implementation of MarkdownRange#toString method.

public static void splitRangesOnEmojis(List<MarkdownRange> markdownRanges, String type) {
List<MarkdownRange> emojiRanges = new ArrayList<>();
List<MarkdownRange> oldRanges = new ArrayList<>(markdownRanges);
markdownRanges.clear();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I still don't understand why it's better to modify markdownRanges in-place rather than create a new list. Could you please explain what's the actual benefit from doing so?

Copy link
Author

Choose a reason for hiding this comment

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

I must admit I might have misunderstood you during our last conversation about this.

I don't really see any benefit. I rewrote the function to not modify ranges in place.

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