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

reverse-string: encourage grapheme awareness #261

Merged
merged 1 commit into from
Sep 29, 2020
Merged
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
13 changes: 13 additions & 0 deletions exercises/reverse-string/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ For example:
input: "cool"
output: "looc"

## Bonus

Preserve grapheme clusters, i.e.

```julia
myreverse("hi 👋🏾") == "👋🏾 ih"
myreverse("as⃝df̅") == "f̅ds⃝a"
```

You will probably find the `Unicode` stdlib useful for this bonus task.

To enable the graphemes test, add `const TEST_GRAPHEMES = true` to the global scope of your file.
Copy link
Contributor

Choose a reason for hiding this comment

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

I wish Julia had a nicer way of handling this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think there's much that can be done. Test or build suites in other languages would read a DEFINE or config files or environment variables. We want the student to only have to modify the one file and we want mentors to run the same tests the students are running, so we probably don't want a config file or env variables.

We could define a function in runtests and give the students an API like

enable_bonus_test(:graphemes)

or something?

That would require some changes to our repo-level runtests because that includes the files in a different order.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think how you did it works fine, it would just be nice if Julia had a nice way to run specific testsets. (there's an issue open for that I think)


## Source

Introductory challenge to reverse an input string [https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb](https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb)
Expand Down
10 changes: 5 additions & 5 deletions exercises/reverse-string/example.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Unicode: graphemes

const TEST_GRAPHEMES = true

function myreverse(phrase::String)
chars = Char[]
for c in phrase
push!(chars, c)
end
join(chars[end:-1:1])
join(reverse(collect(graphemes(phrase))))
end
3 changes: 0 additions & 3 deletions exercises/reverse-string/reverse-string.jl

This file was deleted.

11 changes: 11 additions & 0 deletions exercises/reverse-string/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,14 @@ end
@testset "reversing a string twice" begin
@test myreverse(myreverse("gift")) == "gift"
end

@testset "emoji" begin
@test myreverse("hi 🐱") == "🐱 ih"
end

if @isdefined(TEST_GRAPHEMES)
@eval @testset "graphemes" begin
@test myreverse("as⃝df̅") == "f̅ds⃝a"
@test myreverse("hi 👋🏾") == "👋🏾 ih"
end
end