-
Notifications
You must be signed in to change notification settings - Fork 543
hamming: Updated the exercise to the 2.1.1 version #762
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| [package] | ||
| name = "hamming" | ||
| version = "0.0.0" | ||
| version = "2.1.1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /// Return the Hamming distance between the strings, | ||
| /// or None if the lengths are mismatched. | ||
| pub fn hamming_distance(s1: &str, s2: &str) -> Option<usize> { | ||
| unimplemented!("What is the Hamming Distance between {:?} and {:?}", s1, s2); | ||
| unimplemented!("What is the Hamming Distance between {} and {}", s1, s2); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,42 +1,147 @@ | ||
| extern crate hamming; | ||
|
|
||
| fn process_distance_case(strand_pair: [&str; 2], expected_distance: Option<usize>) { | ||
| assert_eq!( | ||
| hamming::hamming_distance(strand_pair[0], strand_pair[1]), | ||
| expected_distance | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_no_difference_between_empty_strands() { | ||
| assert_eq!(hamming::hamming_distance("", ""), Some(0)); | ||
| fn test_empty_strands() { | ||
| process_distance_case(["", ""], Some(0)); | ||
| } | ||
|
|
||
| #[test] | ||
| #[ignore] | ||
| fn test_no_difference_between_identical_strands() { | ||
| assert_eq!(hamming::hamming_distance("GGACTGA", "GGACTGA"), Some(0)); | ||
| process_distance_case(["GGACTGA", "GGACTGA"], Some(0)); | ||
| } | ||
|
|
||
| #[test] | ||
| #[ignore] | ||
| fn test_complete_hamming_distance_in_small_strand() { | ||
| assert_eq!(hamming::hamming_distance("ACT", "GGA"), Some(3)); | ||
| process_distance_case(["ACT", "GGA"], Some(3)); | ||
| } | ||
|
|
||
| #[test] | ||
| #[ignore] | ||
| fn test_small_hamming_distance_in_the_middle_somewhere() { | ||
| assert_eq!(hamming::hamming_distance("GGACG", "GGTCG"), Some(1)); | ||
| process_distance_case(["GGACG", "GGTCG"], Some(1)); | ||
| } | ||
|
|
||
| #[test] | ||
| #[ignore] | ||
| fn test_larger_distance() { | ||
| assert_eq!(hamming::hamming_distance("ACCAGGG", "ACTATGG"), Some(2)); | ||
| process_distance_case(["ACCAGGG", "ACTATGG"], Some(2)); | ||
| } | ||
|
|
||
| #[test] | ||
| #[ignore] | ||
| fn test_first_string_is_longer() { | ||
| assert_eq!(hamming::hamming_distance("AAA", "AA"), None); | ||
| process_distance_case(["AAA", "AA"], None); | ||
| } | ||
|
|
||
| #[test] | ||
| #[ignore] | ||
| fn test_second_string_is_longer() { | ||
| assert_eq!(hamming::hamming_distance("A", "AA"), None); | ||
| process_distance_case(["A", "AA"], None); | ||
| } | ||
|
|
||
| #[test] | ||
| #[ignore] | ||
| /// non-unique character in first strand | ||
| fn test_nonunique_character_in_first_strand() { | ||
| process_distance_case(["AAG", "AAA"], Some(1)); | ||
| } | ||
|
|
||
| #[test] | ||
| #[ignore] | ||
| /// identical strands | ||
| fn test_identical_strands() { | ||
| process_distance_case(["A", "A"], Some(0)); | ||
| } | ||
|
|
||
| #[test] | ||
| #[ignore] | ||
| /// complete distance in small strands | ||
| fn test_complete_distance_in_small_strands() { | ||
| process_distance_case(["AG", "CT"], Some(2)); | ||
| } | ||
|
|
||
| #[test] | ||
| #[ignore] | ||
| /// disallow first strand longer | ||
| fn test_disallow_first_strand_longer() { | ||
| process_distance_case(["AATG", "AAA"], None); | ||
| } | ||
|
|
||
| #[test] | ||
| #[ignore] | ||
| /// large distance | ||
| fn test_large_distance() { | ||
| process_distance_case(["GATACA", "GCATAA"], Some(4)); | ||
| } | ||
|
|
||
| #[test] | ||
| #[ignore] | ||
| /// long identical strands | ||
| fn test_long_identical_strands() { | ||
| process_distance_case(["GGACTGA", "GGACTGA"], Some(0)); | ||
| } | ||
|
|
||
| #[test] | ||
| #[ignore] | ||
| /// complete distance in single nucleotide strands | ||
| fn test_complete_distance_in_single_nucleotide_strands() { | ||
| process_distance_case(["A", "G"], Some(1)); | ||
| } | ||
|
|
||
| #[test] | ||
| #[ignore] | ||
| /// small distance | ||
| fn test_small_distance() { | ||
| process_distance_case(["GGACG", "GGTCG"], Some(1)); | ||
| } | ||
|
|
||
| #[test] | ||
| #[ignore] | ||
| /// non-unique character in second strand | ||
| fn test_nonunique_character_in_second_strand() { | ||
| process_distance_case(["AAA", "AAG"], Some(1)); | ||
| } | ||
|
|
||
| #[test] | ||
| #[ignore] | ||
| /// small distance in long strands | ||
| fn test_small_distance_in_long_strands() { | ||
| process_distance_case(["ACCAGGG", "ACTATGG"], Some(2)); | ||
| } | ||
|
|
||
| #[test] | ||
| #[ignore] | ||
| /// disallow second strand longer | ||
| fn test_disallow_second_strand_longer() { | ||
| process_distance_case(["ATA", "AGTG"], None); | ||
| } | ||
|
|
||
| #[test] | ||
| #[ignore] | ||
| /// small distance in small strands | ||
| fn test_small_distance_in_small_strands() { | ||
| process_distance_case(["AT", "CT"], Some(1)); | ||
| } | ||
|
|
||
| #[test] | ||
| #[ignore] | ||
| /// large distance in off-by-one strand | ||
| fn test_large_distance_in_offbyone_strand() { | ||
| process_distance_case(["GGACGGATTCTG", "AGGACGGATTCT"], Some(9)); | ||
| } | ||
|
|
||
| #[test] | ||
| #[ignore] | ||
| /// same nucleotides in different positions | ||
| fn test_same_nucleotides_in_different_positions() { | ||
| process_distance_case(["TAG", "GAT"], Some(2)); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious why you wrote this as
[&str; 2]instead of(&str, &str). I tend to think of function arguments as tuple-like instead of array-like, so the latter would have seemed more natural to me.I suspect that the two forms are equivalent in memory, and this does work; you certainly don't need to change it. I'm just curious about your design process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guess I decided to go with the array, because the types of the variables are similar (perhaps a little C-like design).
If the strands where represented with different types, e.g.
LeftStrand/RightStrand, then I would surely used the tuple.