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

Add test case to Hamming that shows the difference between len() and chars().count() #128

Closed
IanWhitney opened this issue May 27, 2016 · 5 comments

Comments

@IanWhitney
Copy link
Contributor

I see this solution a lot

let x = "Hi";
let y = "Yo";

if x.len() == y.len() {
//do something
} else {
//do something else
}

But that's tricky in Rust because all strings are UTF-8 and the number of characters != the length of the string slice.

An example: https://play.rust-lang.org/?gist=b0fb8157fd7903333d9441164e0fffaf&version=stable&backtrace=0

I just saw this pop up in Hamming, so maybe exposing this difference via a test in that problem is a good idea.

@kytrinyx
Copy link
Member

In the case of hamming for DNA mutations the UTF-8 issue doesn't really come into play. Do we have any other exercises where we could expose this?

@IanWhitney
Copy link
Contributor Author

In our current problem set? Not really. Anagrams can do it, but that's going to move much later in the sequence. Maybe in a problem we haven't implemented yet?

@kytrinyx
Copy link
Member

Yeah, maybe, though there's nothing obvious in the list: http://exercism.io/languages/rust/contribute

Maybe we need a new exercise that focuses on this explicitly. Go has the same thing.

@petertseng
Copy link
Member

Since #175 now deals with the difference between bytes and characters, I think the original intent behind this is in fact covered, even if the test was added to a different exercise than Hamming. What say you?

@IanWhitney
Copy link
Contributor Author

Sounds good.

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

No branches or pull requests

3 participants