Rust - WIP hamming

This commit is contained in:
Unknown 2017-05-10 12:18:55 -04:00
parent f685454728
commit e27a4a71cc
5 changed files with 127 additions and 0 deletions

7
rust/hamming/.gitignore vendored Normal file
View file

@ -0,0 +1,7 @@
# Generated by Cargo
# will have compiled files and executables
/target/
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
Cargo.lock

3
rust/hamming/Cargo.toml Normal file
View file

@ -0,0 +1,3 @@
[package]
name = "hamming"
version = "0.0.0"

75
rust/hamming/README.md Normal file
View file

@ -0,0 +1,75 @@
# Hamming
Calculate the Hamming difference between two DNA strands.
A mutation is simply a mistake that occurs during the creation or
copying of a nucleic acid, in particular DNA. Because nucleic acids are
vital to cellular functions, mutations tend to cause a ripple effect
throughout the cell. Although mutations are technically mistakes, a very
rare mutation may equip the cell with a beneficial attribute. In fact,
the macro effects of evolution are attributable by the accumulated
result of beneficial microscopic mutations over many generations.
The simplest and most common type of nucleic acid mutation is a point
mutation, which replaces one base with another at a single nucleotide.
By counting the number of differences between two homologous DNA strands
taken from different genomes with a common ancestor, we get a measure of
the minimum number of point mutations that could have occurred on the
evolutionary path between the two strands.
This is called the 'Hamming distance'.
It is found by comparing two DNA strands and counting how many of the
nucleotides are different from their equivalent in the other string.
GAGCCTACTAACGGGAT
CATCGTAATGACGGCCT
^ ^ ^ ^ ^ ^^
The Hamming distance between these two DNA strands is 7.
# Implementation notes
The Hamming distance is only defined for sequences of equal length. This means
that based on the definition, each language could deal with getting sequences
of equal length differently.
## Rust Installation
Refer to the [exercism help page][help-page] for Rust installation and learning
resources.
## Writing the Code
Execute the tests with:
```bash
$ cargo test
```
All but the first test have been ignored. After you get the first test to
pass, remove the ignore flag (`#[ignore]`) from the next test and get the tests
to pass again. The test file is located in the `tests` directory. You can
also remove the ignore flag from all the tests to get them to run all at once
if you wish.
Make sure to read the [Crates and Modules](https://doc.rust-lang.org/stable/book/crates-and-modules.html) chapter if you
haven't already, it will help you with organizing your files.
## Feedback, Issues, Pull Requests
The [exercism/xrust](https://github.com/exercism/xrust) repository on GitHub is the home for all of the Rust exercises. If you have feedback about an exercise, or want to help implement new exercises, head over there and create an issue. Members of the [rust track team](https://github.com/orgs/exercism/teams/rust) are happy to help!
If you want to know more about Exercism, take a look at the [contribution guide](https://github.com/exercism/x-common/blob/master/CONTRIBUTING.md).
[help-page]: http://exercism.io/languages/rust
[crates-and-modules]: http://doc.rust-lang.org/stable/book/crates-and-modules.html
## Source
The Calculating Point Mutations problem at Rosalind [http://rosalind.info/problems/hamm/](http://rosalind.info/problems/hamm/)
## Submitting Incomplete Problems
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

0
rust/hamming/src/lib.rs Normal file
View file

View file

@ -0,0 +1,42 @@
extern crate hamming;
#[test]
fn test_no_difference_between_empty_strands() {
assert_eq!(hamming::hamming_distance("", "").unwrap(), 0);
}
#[test]
#[ignore]
fn test_no_difference_between_identical_strands() {
assert_eq!(hamming::hamming_distance("GGACTGA", "GGACTGA").unwrap(), 0);
}
#[test]
#[ignore]
fn test_complete_hamming_distance_in_small_strand() {
assert_eq!(hamming::hamming_distance("ACT", "GGA").unwrap(), 3);
}
#[test]
#[ignore]
fn test_small_hamming_distance_in_the_middle_somewhere() {
assert_eq!(hamming::hamming_distance("GGACG", "GGTCG").unwrap(), 1);
}
#[test]
#[ignore]
fn test_larger_distance() {
assert_eq!(hamming::hamming_distance("ACCAGGG", "ACTATGG").unwrap(), 2);
}
#[test]
#[ignore]
fn test_first_string_is_longer() {
assert!(hamming::hamming_distance("AAA", "AA").is_err());
}
#[test]
#[ignore]
fn test_second_string_is_longer() {
assert!(hamming::hamming_distance("A", "AA").is_err());
}