Skip to content

Update reverse-string missing test cases #917

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions exercises/practice/reverse-string/.docs/instructions.append.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Additional Instructions

## Grapheme Clusters

Unicode supports a lot of characters and languages.
Copy link
Member

Choose a reason for hiding this comment

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

Unicode is not introduced before this sentence. I'd similarly recommend an external link and perhaps a framing sentence about how Unicode is relevant before diving into the technical details.

The displayed 'graphemes' are constructed from code points.
Copy link
Member

Choose a reason for hiding this comment

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

Neither graphemes nor code points are introduced before this sentence. An external link here might be useful as background info.

Their combination and _order_ is the basis of the resulting grapheme.
Imagine, a simple algorithm that might flip the 'dots' from one place to another during reversal: `Noël` becomes `leöN`.
Now consider more [complex constructions][grapheme-construction] like the Bengali word `ঝিল্লি`, which consists of six code points.

As graphemes make the string reversal process a lot more complicated, we made the respective test cases optional.
You can try them out by setting the `TEST_GRAPHEMES` compiler flag or editing the test file accordingly.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
You can try them out by setting the `TEST_GRAPHEMES` compiler flag or editing the test file accordingly.
You can try them out by setting the `TEST_GRAPHEMES` preprocessor define or editing the test file accordingly.


[grapheme-construction]: https://r12a.github.io/uniview/?charlist=%E0%A6%9D%E0%A6%BF%E0%A6%B2%E0%A7%8D%E0%A6%B2%E0%A6%BF
Copy link
Contributor

Choose a reason for hiding this comment

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

To me this sounds reasonable, but @BNAndras's points are valid. Having a few more external references probably wouldn't hurt.

However, what I'm missing most here is something about how to approach this in C++. Simply using something like std::u16string won't work, since in the test cases we clearly use UTF-8. Are students expected to implement some UTF-8 handling themselves? Can they use some library?

22 changes: 19 additions & 3 deletions exercises/practice/reverse-string/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# This is an auto-generated file. Regular comments will be removed when this
# file is regenerated. Regenerating will not touch any manually added keys,
# so comments can be added in a "comment" key.
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[c3b7d806-dced-49ee-8543-933fd1719b1c]
description = "an empty string"
Expand All @@ -19,3 +26,12 @@ description = "a palindrome"

[b9e7dec1-c6df-40bd-9fa3-cd7ded010c4c]
description = "an even-sized word"

[1bed0f8a-13b0-4bd3-9d59-3d0593326fa2]
description = "wide characters"

[93d7e1b8-f60f-4f3c-9559-4056e10d2ead]
description = "grapheme cluster with pre-combined form"

[1028b2c1-6763-4459-8540-2da47ca512d9]
description = "grapheme clusters"
38 changes: 33 additions & 5 deletions exercises/practice/reverse-string/reverse_string_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,52 @@
#include "test/catch.hpp"
#endif

TEST_CASE("an_empty_string") {
/*
If property based testing tools are available, a good property to test is
reversing a string twice: reverse(reverse(string)) == string
*/

TEST_CASE("an empty string", "[c3b7d806-dced-49ee-8543-933fd1719b1c]") {
REQUIRE("" == reverse_string::reverse_string(""));
}

#if defined(EXERCISM_RUN_ALL_TESTS)
TEST_CASE("a_word") {

TEST_CASE("a word", "[01ebf55b-bebb-414e-9dec-06f7bb0bee3c]") {
REQUIRE("tobor" == reverse_string::reverse_string("robot"));
}

TEST_CASE("a_capitalized_word") {
TEST_CASE("a capitalized word", "[0f7c07e4-efd1-4aaa-a07a-90b49ce0b746]") {
REQUIRE("nemaR" == reverse_string::reverse_string("Ramen"));
}

TEST_CASE("a_sentence_with_punctuation") {
TEST_CASE("a sentence with punctuation",
"[71854b9c-f200-4469-9f5c-1e8e5eff5614]") {
REQUIRE("!yrgnuh m'I" == reverse_string::reverse_string("I'm hungry!"));
}

TEST_CASE("a_palindrome") {
TEST_CASE("a palindrome", "[1f8ed2f3-56f3-459b-8f3e-6d8d654a1f6c]") {
REQUIRE("racecar" == reverse_string::reverse_string("racecar"));
}

TEST_CASE("an even-sized word", "[b9e7dec1-c6df-40bd-9fa3-cd7ded010c4c]") {
REQUIRE("reward" == reverse_string::reverse_string("drawer"));
}

#if defined(TEST_GRAPHEMES)
TEST_CASE("wide characters", "[1bed0f8a-13b0-4bd3-9d59-3d0593326fa2]") {
REQUIRE("猫子" == reverse_string::reverse_string("子猫"));
}

TEST_CASE("grapheme cluster with pre-combined form",
"[93d7e1b8-f60f-4f3c-9559-4056e10d2ead]") {
REQUIRE("dnatsnehctsrüW" ==
reverse_string::reverse_string("Würstchenstand"));
}

TEST_CASE("grapheme clusters", "[1028b2c1-6763-4459-8540-2da47ca512d9]") {
REQUIRE("มรกแรปโนยขีเผู้" == reverse_string::reverse_string("ผู้เขียนโปรแกรม"));
}
#endif

#endif