浏览代码

hamming: update to v1.1.0 of canonical data

https://github.com/exercism/problem-specifications/blob/ebe9bbf952206384d344aded650407751a881e92/exercises/hamming/canonical-data.json
Stuart Kent 9 年前
父节点
当前提交
261fcc02d3
共有 1 个文件被更改,包括 68 次插入26 次删除
  1. 68
    26
      exercises/hamming/src/test/java/HammingTest.java

+ 68
- 26
exercises/hamming/src/test/java/HammingTest.java 查看文件

1
-import static org.hamcrest.CoreMatchers.*;
2
-import static org.junit.Assert.*;
3
-
4
-import org.junit.Test;
5
 import org.junit.Ignore;
1
 import org.junit.Ignore;
6
 import org.junit.Rule;
2
 import org.junit.Rule;
3
+import org.junit.Test;
7
 import org.junit.rules.ExpectedException;
4
 import org.junit.rules.ExpectedException;
8
 
5
 
6
+import static org.junit.Assert.assertEquals;
7
+
8
+/*
9
+ * version: 1.1.0
10
+ */
9
 public class HammingTest {
11
 public class HammingTest {
10
 
12
 
11
     @Rule
13
     @Rule
12
-    public ExpectedException thrown = ExpectedException.none();
13
-    
14
+    public ExpectedException expectedException = ExpectedException.none();
15
+
14
     @Test
16
     @Test
15
-    public void testNoDifferenceBetweenIdenticalStrands() {
16
-        assertThat(new Hamming("A", "A").getHammingDistance(), is(0));
17
+    public void testNoDistanceBetweenEmptyStrands() {
18
+        assertEquals(0, new Hamming("", "").getHammingDistance());
17
     }
19
     }
18
 
20
 
19
     @Ignore("Remove to run test")
21
     @Ignore("Remove to run test")
20
     @Test
22
     @Test
21
-    public void testHammingDistanceForSingleNucleotideStrand() {
22
-        assertThat(new Hamming("A", "G").getHammingDistance(), is(1));
23
+    public void testNoDistanceBetweenShortIdenticalStrands() {
24
+        assertEquals(0, new Hamming("A", "A").getHammingDistance());
23
     }
25
     }
24
 
26
 
25
     @Ignore("Remove to run test")
27
     @Ignore("Remove to run test")
26
     @Test
28
     @Test
27
-    public void testHammingDistanceForSmallStrand() {
28
-        assertThat(new Hamming("AG", "CT").getHammingDistance(), is(2));
29
+    public void testNoDistanceBetweenLongIdenticalStrands() {
30
+        assertEquals(0, new Hamming("GGACTGA", "GGACTGA").getHammingDistance());
29
     }
31
     }
30
 
32
 
31
     @Ignore("Remove to run test")
33
     @Ignore("Remove to run test")
32
     @Test
34
     @Test
33
-    public void testSmallHammingDistance() {
34
-        assertThat(new Hamming("AT", "CT").getHammingDistance(), is(1));
35
+    public void testCompleteDistanceInSingleNucleotideStrand() {
36
+        assertEquals(1, new Hamming("A", "G").getHammingDistance());
35
     }
37
     }
36
 
38
 
37
     @Ignore("Remove to run test")
39
     @Ignore("Remove to run test")
38
     @Test
40
     @Test
39
-    public void testSmallHammingDistanceInLongerStrand() {
40
-        assertThat(new Hamming("GGACG", "GGTCG").getHammingDistance(), is(1));
41
+    public void testCompleteDistanceInSmallStrand() {
42
+        assertEquals(2, new Hamming("AG", "CT").getHammingDistance());
41
     }
43
     }
42
 
44
 
43
     @Ignore("Remove to run test")
45
     @Ignore("Remove to run test")
44
     @Test
46
     @Test
45
-    public void testValidatesFirstStrandNotLonger() {
46
-        thrown.expect(IllegalArgumentException.class);
47
-        new Hamming("AAAG", "AAA");
47
+    public void testSmallDistanceInSmallStrand() {
48
+        assertEquals(1, new Hamming("AT", "CT").getHammingDistance());
48
     }
49
     }
49
 
50
 
50
     @Ignore("Remove to run test")
51
     @Ignore("Remove to run test")
51
     @Test
52
     @Test
52
-    public void testValidatesOtherStrandNotLonger() {
53
-        thrown.expect(IllegalArgumentException.class);
54
-        new Hamming("AAA", "AAAG");
53
+    public void testSmallDistanceInMediumStrand() {
54
+        assertEquals(1, new Hamming("GGACG", "GGTCG").getHammingDistance());
55
     }
55
     }
56
 
56
 
57
     @Ignore("Remove to run test")
57
     @Ignore("Remove to run test")
58
     @Test
58
     @Test
59
-    public void testLargeHammingDistance() {
60
-        assertThat(new Hamming("GATACA", "GCATAA").getHammingDistance(), is(4));
59
+    public void testSmallDistanceInLongStrand() {
60
+        assertEquals(2, new Hamming("ACCAGGG", "ACTATGG").getHammingDistance());
61
     }
61
     }
62
 
62
 
63
     @Ignore("Remove to run test")
63
     @Ignore("Remove to run test")
64
     @Test
64
     @Test
65
-    public void testHammingDistanceInVeryLongStrand() {
66
-        assertThat(new Hamming("GGACGGATTCTG", "AGGACGGATTCT").getHammingDistance(), is(9));
65
+    public void testNonUniqueCharacterInFirstStrand() {
66
+        assertEquals(1, new Hamming("AGA", "AGG").getHammingDistance());
67
+    }
68
+
69
+    @Ignore("Remove to run test")
70
+    @Test
71
+    public void testNonUniqueCharacterInSecondStrand() {
72
+        assertEquals(1, new Hamming("AGG", "AGA").getHammingDistance());
73
+    }
74
+
75
+    @Ignore("Remove to run test")
76
+    @Test
77
+    public void testSameNucleotidesInDifferentPositions() {
78
+        assertEquals(2, new Hamming("TAG", "GAT").getHammingDistance());
79
+    }
80
+
81
+    @Ignore("Remove to run test")
82
+    @Test
83
+    public void testLargeDistanceInPermutedStrand() {
84
+        assertEquals(4, new Hamming("GATACA", "GCATAA").getHammingDistance());
85
+    }
86
+
87
+    @Ignore("Remove to run test")
88
+    @Test
89
+    public void testLargeDistanceInOffByOneStrand() {
90
+        assertEquals(9, new Hamming("GGACGGATTCTG", "AGGACGGATTCT").getHammingDistance());
91
+    }
92
+
93
+    @Ignore("Remove to run test")
94
+    @Test
95
+    public void testValidatesFirstStrandNotLonger() {
96
+        expectedException.expect(IllegalArgumentException.class);
97
+        expectedException.expectMessage("leftStrand and rightStrand must be of equal length.");
98
+
99
+        new Hamming("AATG", "AAA");
100
+    }
101
+
102
+    @Ignore("Remove to run test")
103
+    @Test
104
+    public void testValidatesSecondStrandNotLonger() {
105
+        expectedException.expect(IllegalArgumentException.class);
106
+        expectedException.expectMessage("leftStrand and rightStrand must be of equal length.");
107
+
108
+        new Hamming("ATA", "AGTG");
67
     }
109
     }
68
 
110
 
69
 }
111
 }