Skip to content

Commit eb36fc6

Browse files
committed
hamming: Updated the exercise to the 2.1.1
Relevant PRs: 1) Test cases: - exercism/problem-specifications#625 - exercism/problem-specifications#844 - exercism/problem-specifications#845 - exercism/problem-specifications#875 - exercism/problem-specifications#953 - exercism/problem-specifications#1129 - exercism/problem-specifications#1389 2) README: - exercism/problem-specifications#1360 Basically adds every test case from the current canonical-data.json without deleting the old ones.
1 parent a9f0edd commit eb36fc6

File tree

3 files changed

+116
-24
lines changed

3 files changed

+116
-24
lines changed

exercises/hamming/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[package]
22
name = "hamming"
3-
version = "0.0.0"
3+
version = "2.1.1"

exercises/hamming/README.md

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,20 @@
11
# Hamming
22

3-
Calculate the Hamming difference between two DNA strands.
3+
Calculate the Hamming Distance between two DNA strands.
44

5-
A mutation is simply a mistake that occurs during the creation or
6-
copying of a nucleic acid, in particular DNA. Because nucleic acids are
7-
vital to cellular functions, mutations tend to cause a ripple effect
8-
throughout the cell. Although mutations are technically mistakes, a very
9-
rare mutation may equip the cell with a beneficial attribute. In fact,
10-
the macro effects of evolution are attributable by the accumulated
11-
result of beneficial microscopic mutations over many generations.
5+
Your body is made up of cells that contain DNA. Those cells regularly wear out and need replacing, which they achieve by dividing into daughter cells. In fact, the average human body experiences about 10 quadrillion cell divisions in a lifetime!
126

13-
The simplest and most common type of nucleic acid mutation is a point
14-
mutation, which replaces one base with another at a single nucleotide.
7+
When cells divide, their DNA replicates too. Sometimes during this process mistakes happen and single pieces of DNA get encoded with the incorrect information. If we compare two strands of DNA and count the differences between them we can see how many mistakes occurred. This is known as the "Hamming Distance".
158

16-
By counting the number of differences between two homologous DNA strands
17-
taken from different genomes with a common ancestor, we get a measure of
18-
the minimum number of point mutations that could have occurred on the
19-
evolutionary path between the two strands.
20-
21-
This is called the 'Hamming distance'.
22-
23-
It is found by comparing two DNA strands and counting how many of the
24-
nucleotides are different from their equivalent in the other string.
9+
We read DNA using the letters C,A,G and T. Two strands might look like this:
2510

2611
GAGCCTACTAACGGGAT
2712
CATCGTAATGACGGCCT
2813
^ ^ ^ ^ ^ ^^
2914

30-
The Hamming distance between these two DNA strands is 7.
15+
They have 7 differences, and therefore the Hamming Distance is 7.
16+
17+
The Hamming Distance is useful for lots of things in science, not just biology, so it's a nice phrase to be familiar with :)
3118

3219
# Implementation notes
3320

exercises/hamming/tests/hamming.rs

Lines changed: 108 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
extern crate hamming;
22

3+
fn process_distance_case(strand_pair: [&str; 2], expected_distance: Option<usize>) {
4+
assert_eq!(
5+
hamming::hamming_distance(strand_pair[0], strand_pair[1]),
6+
expected_distance
7+
);
8+
}
9+
310
#[test]
4-
fn test_no_difference_between_empty_strands() {
5-
assert_eq!(hamming::hamming_distance("", ""), Some(0));
11+
fn test_empty_strands() {
12+
process_distance_case(["", ""], Some(0));
613
}
714

815
#[test]
916
#[ignore]
1017
fn test_no_difference_between_identical_strands() {
11-
assert_eq!(hamming::hamming_distance("GGACTGA", "GGACTGA"), Some(0));
18+
process_distance_case(["GGACTGA", "GGACTGA"], Some(0));
1219
}
1320

1421
#[test]
@@ -40,3 +47,101 @@ fn test_first_string_is_longer() {
4047
fn test_second_string_is_longer() {
4148
assert_eq!(hamming::hamming_distance("A", "AA"), None);
4249
}
50+
51+
#[test]
52+
#[ignore]
53+
/// non-unique character in first strand
54+
fn test_nonunique_character_in_first_strand() {
55+
process_distance_case(["AAG", "AAA"], Some(1));
56+
}
57+
58+
#[test]
59+
#[ignore]
60+
/// identical strands
61+
fn test_identical_strands() {
62+
process_distance_case(["A", "A"], Some(0));
63+
}
64+
65+
#[test]
66+
#[ignore]
67+
/// complete distance in small strands
68+
fn test_complete_distance_in_small_strands() {
69+
process_distance_case(["AG", "CT"], Some(2));
70+
}
71+
72+
#[test]
73+
#[ignore]
74+
/// disallow first strand longer
75+
fn test_disallow_first_strand_longer() {
76+
process_distance_case(["AATG", "AAA"], None);
77+
}
78+
79+
#[test]
80+
#[ignore]
81+
/// large distance
82+
fn test_large_distance() {
83+
process_distance_case(["GATACA", "GCATAA"], Some(4));
84+
}
85+
86+
#[test]
87+
#[ignore]
88+
/// long identical strands
89+
fn test_long_identical_strands() {
90+
process_distance_case(["GGACTGA", "GGACTGA"], Some(0));
91+
}
92+
93+
#[test]
94+
#[ignore]
95+
/// complete distance in single nucleotide strands
96+
fn test_complete_distance_in_single_nucleotide_strands() {
97+
process_distance_case(["A", "G"], Some(1));
98+
}
99+
100+
#[test]
101+
#[ignore]
102+
/// small distance
103+
fn test_small_distance() {
104+
process_distance_case(["GGACG", "GGTCG"], Some(1));
105+
}
106+
107+
#[test]
108+
#[ignore]
109+
/// non-unique character in second strand
110+
fn test_nonunique_character_in_second_strand() {
111+
process_distance_case(["AAA", "AAG"], Some(1));
112+
}
113+
114+
#[test]
115+
#[ignore]
116+
/// small distance in long strands
117+
fn test_small_distance_in_long_strands() {
118+
process_distance_case(["ACCAGGG", "ACTATGG"], Some(2));
119+
}
120+
121+
#[test]
122+
#[ignore]
123+
/// disallow second strand longer
124+
fn test_disallow_second_strand_longer() {
125+
process_distance_case(["ATA", "AGTG"], None);
126+
}
127+
128+
#[test]
129+
#[ignore]
130+
/// small distance in small strands
131+
fn test_small_distance_in_small_strands() {
132+
process_distance_case(["AT", "CT"], Some(1));
133+
}
134+
135+
#[test]
136+
#[ignore]
137+
/// large distance in off-by-one strand
138+
fn test_large_distance_in_offbyone_strand() {
139+
process_distance_case(["GGACGGATTCTG", "AGGACGGATTCT"], Some(9));
140+
}
141+
142+
#[test]
143+
#[ignore]
144+
/// same nucleotides in different positions
145+
fn test_same_nucleotides_in_different_positions() {
146+
process_distance_case(["TAG", "GAT"], Some(2));
147+
}

0 commit comments

Comments
 (0)