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

feat: refactor string package reverse #1082

Merged
merged 9 commits into from
Oct 31, 2023
Merged

feat: refactor string package reverse #1082

merged 9 commits into from
Oct 31, 2023

Conversation

steff456
Copy link
Contributor

@steff456 steff456 commented Aug 12, 2023

Part of #1062

Description

What is the purpose of this pull request?

This pull request:

  • Refactors the string package @stdlib/string/reverse
  • Adds @stdlib/string/base/reverse
  • Adds @stdlib/string/base/reverse-code-points
  • Adds @stdlib/string/base/reverse-grapheme-clusters

Related Issues

Does this pull request have any related issues?

This pull request:

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

No.

Checklist

Please ensure the following tasks are completed before submitting this pull request.


@stdlib-js/reviewers

@steff456 steff456 self-assigned this Aug 12, 2023
@stdlib-bot
Copy link
Contributor

stdlib-bot commented Aug 12, 2023

Coverage Report

Package Statements Branches Functions Lines
string/base/reverse-code-point $\color{red}120/134$
$\color{green}+89.55\%$
$\color{red}4/5$
$\color{green}+80.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{red}120/134$
$\color{green}+89.55\%$
string/base/reverse-grapheme-cluster $\color{green}121/121$
$\color{green}+100.00\%$
$\color{green}5/5$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}121/121$
$\color{green}+100.00\%$
string/base/reverse $\color{green}102/102$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}102/102$
$\color{green}+100.00\%$
string/reverse $\color{green}147/147$
$\color{green}+100.00\%$
$\color{green}12/12$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}147/147$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this PR.

@kgryte
Copy link
Member

kgryte commented Aug 12, 2023

@steff456 Looks like the tests don't cover all branches for reversing code points. Would you mind adding a few tests to address?

@kgryte
Copy link
Member

kgryte commented Aug 12, 2023

You can generate a test coverage report locally using make test-cov.

@Planeshifter
Copy link
Member

Planeshifter commented Aug 12, 2023

@steff456 @kgryte

Ran make test-cov TESTS_FILTER='.*/string/base/reverse-code-point/.*' locally and am getting the same coverage as in the table.

One can see the uncovered lines online as well: https://coverage.stdlib.io/string/base/reverse-code-point/

@steff456
Copy link
Contributor Author

Thanks @Planeshifter and @kgryte, I'll check the tests :)

@stdlib-bot
Copy link
Contributor

Coverage Report

Package Statements Branches Functions Lines
string/base/reverse-code-point $\color{red}133/137$
$\color{green}+97.08\%$
$\color{red}7/8$
$\color{green}+87.50\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{red}133/137$
$\color{green}+97.08\%$
string/base/reverse-grapheme-cluster $\color{green}121/121$
$\color{green}+100.00\%$
$\color{green}5/5$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}121/121$
$\color{green}+100.00\%$
string/base/reverse $\color{green}102/102$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}102/102$
$\color{green}+100.00\%$
string/reverse $\color{green}147/147$
$\color{green}+100.00\%$
$\color{green}12/12$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}147/147$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this PR.

@stdlib-bot
Copy link
Contributor

Coverage Report

Package Statements Branches Functions Lines
string/base/reverse-code-point $\color{green}137/137$
$\color{green}+100.00\%$
$\color{green}10/10$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}137/137$
$\color{green}+100.00\%$
string/base/reverse-grapheme-cluster $\color{green}121/121$
$\color{green}+100.00\%$
$\color{green}5/5$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}121/121$
$\color{green}+100.00\%$
string/base/reverse $\color{green}102/102$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}102/102$
$\color{green}+100.00\%$
string/reverse $\color{green}147/147$
$\color{green}+100.00\%$
$\color{green}12/12$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}147/147$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this PR.

@steff456
Copy link
Contributor Author

I'm not sure why the coverage tests failed with the last commit, but when I try it locally it is working 🙃

@kgryte
Copy link
Member

kgryte commented Aug 14, 2023

@steff456 I believe the test coverage failure is due to a known issue. @Planeshifter can you comment?

@Planeshifter
Copy link
Member

@steff456 Will look into it, sorry for that; seems like the job was not able to push the coverage report to the test coverage repo. The table now shows that 100% coverage is achieved, though, so that's awesome!

@steff456
Copy link
Contributor Author

Perf! Thanks to both 👏🏻

@kgryte
Copy link
Member

kgryte commented Aug 22, 2023

@steff456 Would you mind renaming the packages from

reverse-code-point
reverse-grapheme-cluster

to

reverse-code-points
reverse-grapheme-clusters

The use of singular is a bit confusing in this context, as, e.g., reverse-code-point, makes it seem as those the function only reverses a single code point, rather than a sequence of code points.

@stdlib-bot
Copy link
Contributor

Coverage Report

Package Statements Branches Functions Lines
string/base/reverse-code-points $\color{green}137/137$
$\color{green}+100.00\%$
$\color{green}10/10$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}137/137$
$\color{green}+100.00\%$
string/base/reverse-grapheme-clusters $\color{green}121/121$
$\color{green}+100.00\%$
$\color{green}5/5$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}121/121$
$\color{green}+100.00\%$
string/base/reverse $\color{green}102/102$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}102/102$
$\color{green}+100.00\%$
string/reverse $\color{green}147/147$
$\color{green}+100.00\%$
$\color{green}12/12$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}147/147$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this PR.

@stdlib-bot
Copy link
Contributor

Coverage Report

Package Statements Branches Functions Lines
string/base/reverse-code-points $\color{green}135/135$
$\color{green}+100.00\%$
$\color{green}10/10$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}135/135$
$\color{green}+100.00\%$
string/base/reverse-grapheme-clusters $\color{green}121/121$
$\color{green}+100.00\%$
$\color{green}5/5$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}121/121$
$\color{green}+100.00\%$
string/base/reverse $\color{green}102/102$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}102/102$
$\color{green}+100.00\%$
string/reverse $\color{green}147/147$
$\color{green}+0.00\%$
$\color{green}12/12$
$\color{green}+0.00\%$
$\color{green}1/1$
$\color{green}+0.00\%$
$\color{green}147/147$
$\color{green}+0.00\%$

The above coverage report was generated for the changes in this PR.

@stdlib-bot
Copy link
Contributor

Coverage Report

Package Statements Branches Functions Lines
string/base/reverse-code-points $\color{green}135/135$
$\color{green}+100.00\%$
$\color{green}10/10$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}135/135$
$\color{green}+100.00\%$
string/base/reverse-grapheme-clusters $\color{green}121/121$
$\color{green}+100.00\%$
$\color{green}5/5$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}121/121$
$\color{green}+100.00\%$
string/base/reverse $\color{green}102/102$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}102/102$
$\color{green}+100.00\%$
string/reverse $\color{green}147/147$
$\color{green}+0.00\%$
$\color{green}12/12$
$\color{green}+0.00\%$
$\color{green}1/1$
$\color{green}+0.00\%$
$\color{green}147/147$
$\color{green}+0.00\%$

The above coverage report was generated for the changes in this PR.

Copy link
Member

@kgryte kgryte left a comment

Choose a reason for hiding this comment

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

@steff456 Thanks for working on this. Left a few comments. The handling of grapheme clusters looks off to me, based on the expected test values. Additionally, we need to add a couple more TypeScript tests and fix some missing documentation.

@stdlib-bot
Copy link
Contributor

Coverage Report

Package Statements Branches Functions Lines
string/base/reverse-code-points $\color{green}135/135$
$\color{green}+100.00\%$
$\color{green}10/10$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}135/135$
$\color{green}+100.00\%$
string/base/reverse-grapheme-clusters $\color{green}121/121$
$\color{green}+0.00\%$
$\color{green}5/5$
$\color{green}+0.00\%$
$\color{green}1/1$
$\color{green}+0.00\%$
$\color{green}121/121$
$\color{green}+0.00\%$
string/base/reverse $\color{green}102/102$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}102/102$
$\color{green}+100.00\%$
string/reverse $\color{green}147/147$
$\color{green}+0.00\%$
$\color{green}12/12$
$\color{green}+0.00\%$
$\color{green}1/1$
$\color{green}+0.00\%$
$\color{green}147/147$
$\color{green}+0.00\%$

The above coverage report was generated for the changes in this PR.

@stdlib-bot
Copy link
Contributor

Coverage Report

Package Statements Branches Functions Lines
string/base/reverse-code-points $\color{green}135/135$
$\color{green}+100.00\%$
$\color{green}10/10$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}135/135$
$\color{green}+100.00\%$
string/base/reverse-grapheme-clusters $\color{green}127/127$
$\color{green}+0.00\%$
$\color{green}6/6$
$\color{green}+0.00\%$
$\color{green}1/1$
$\color{green}+0.00\%$
$\color{green}127/127$
$\color{green}+0.00\%$
string/base/reverse $\color{green}102/102$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}102/102$
$\color{green}+100.00\%$
string/reverse $\color{green}148/148$
$\color{green}+0.00\%$
$\color{green}12/12$
$\color{green}+0.00\%$
$\color{green}1/1$
$\color{green}+0.00\%$
$\color{green}148/148$
$\color{green}+0.00\%$

The above coverage report was generated for the changes in this PR.

for ( i = idx; i < brk; i++ ) {
cluster += str.charAt( i );
}
out = cluster + out;
Copy link
Member

Choose a reason for hiding this comment

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

For future reference, this is not the most memory efficient approach (i.e., prepending strings), but we don't have much choice until the bug in prevGraphemeClusterBreak is resolved (ref: #1092).

Copy link
Member

@kgryte kgryte left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks, @steff456!

@stdlib-bot
Copy link
Contributor

Coverage Report

Package Statements Branches Functions Lines
string/base/reverse-code-points $\color{green}135/135$
$\color{green}+100.00\%$
$\color{green}10/10$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}135/135$
$\color{green}+100.00\%$
string/base/reverse-grapheme-clusters $\color{green}127/127$
$\color{green}+0.00\%$
$\color{green}6/6$
$\color{green}+0.00\%$
$\color{green}1/1$
$\color{green}+0.00\%$
$\color{green}127/127$
$\color{green}+0.00\%$
string/base/reverse $\color{green}102/102$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}102/102$
$\color{green}+100.00\%$
string/reverse $\color{green}148/148$
$\color{green}+0.00\%$
$\color{green}12/12$
$\color{green}+0.00\%$
$\color{green}1/1$
$\color{green}+0.00\%$
$\color{green}148/148$
$\color{green}+0.00\%$

The above coverage report was generated for the changes in this PR.

@kgryte
Copy link
Member

kgryte commented Oct 31, 2023

The failing CI jobs do not appear related to this PR. As such, will go ahead and merge...

@kgryte kgryte merged commit de17736 into develop Oct 31, 2023
7 of 9 checks passed
@kgryte kgryte deleted the reverse branch October 31, 2023 05:46
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.

4 participants