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

handle different lengths error case in point-mutations #45

Closed
ekse opened this issue Aug 9, 2015 · 0 comments
Closed

handle different lengths error case in point-mutations #45

ekse opened this issue Aug 9, 2015 · 0 comments

Comments

@ekse
Copy link
Contributor

ekse commented Aug 9, 2015

The current tests for the point-mutations exercise assumes that both strings are of the same length. hamming_distance() should return an error when strings of different lengths are passed. I think the idiomatic way to this in Rust would be to change the function signature to return a Result

pub fn hamming_distance(a : &str, b: &str) -> Result<u32, &'static str> 

For expected tests cases a call to unwrap() needs to be added, for error cases we can compare with the error.

#[test]
fn test_no_difference_between_empty_strands() {
    assert_eq!(dna::hamming_distance("", "").unwrap(), 0);
}

#[test]
fn test_second_string_is_longer() {
    assert_eq!(dna::hamming_distance("A", "AA"), Result::Err("inputs of different length"));
}

I will send a pull request for this issue.

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

1 participant