Просмотр исходного кода

Nucleotide count tests and version #1142 (#1248)

* version 1.3.0 added to nucleotide-count

* tests added

* removed duplicate

* added exception throwing statement

* refactored to fit the canonical data

* Tests made more thorough

* Updated to throw Illegal ArguementException

* Remove unnecessary Tests

* Remove @Ignore

* Braces added

* Shifted checking to constructor
Shradheya Thakre 8 лет назад
Родитель
Сommit
2a7d3ead79

+ 7
- 1
exercises/nucleotide-count/.meta/src/reference/java/NucleotideCounter.java Просмотреть файл

@@ -6,11 +6,17 @@ final class NucleotideCounter {
6 6
 
7 7
   NucleotideCounter(String sequence) {
8 8
     this.sequence = sequence;
9
+    for (char c : sequence.toCharArray()) {
10
+      if (isCountable(c)) {
11
+        throw new IllegalArgumentException(c + " is not a nucleotide");
12
+      }
13
+    }
9 14
   }
10 15
 
11 16
   int count(char base) {
12
-    if (isCountable(base))
17
+    if (isCountable(base)) {
13 18
       throw new IllegalArgumentException(base + " is not a nucleotide");
19
+    }
14 20
 
15 21
     try {
16 22
       return nucleotideCounts().get(base);

+ 1
- 0
exercises/nucleotide-count/.meta/version Просмотреть файл

@@ -0,0 +1 @@
1
+1.3.0

+ 19
- 54
exercises/nucleotide-count/src/test/java/NucleotideCounterTest.java Просмотреть файл

@@ -14,17 +14,9 @@ public class NucleotideCounterTest {
14 14
     public ExpectedException expectedException = ExpectedException.none();
15 15
 
16 16
     @Test
17
-    public void testEmptyDnaStringHasNoAdenine() {
18
-        NucleotideCounter nucleotideCounter = new NucleotideCounter("");
19
-        assertThat(nucleotideCounter.count('A'), is(0));
20
-    }
21
-
22
-    @Ignore("Remove to run test")
23
-    @Test
24 17
     public void testEmptyDnaStringHasNoNucleotides() {
25 18
         NucleotideCounter nucleotideCounter = new NucleotideCounter("");
26 19
         Map<Character, Integer> counts = nucleotideCounter.nucleotideCounts();
27
-        assertThat(counts.size(), is(4));
28 20
         assertThat(counts, allOf(
29 21
                 hasEntry('A', 0),
30 22
                 hasEntry('C', 0),
@@ -35,70 +27,36 @@ public class NucleotideCounterTest {
35 27
 
36 28
     @Ignore("Remove to run test")
37 29
     @Test
38
-    public void testRepetitiveCytosineGetsCounted() {
39
-        NucleotideCounter nucleotideCounter = new NucleotideCounter("CCCCC");
40
-        assertThat(nucleotideCounter.count('C'), is(5));
41
-    }
42
-
43
-    @Ignore("Remove to run test")
44
-    @Test
45
-    public void testRepetitiveSequenceWithOnlyGuanine() {
46
-        NucleotideCounter nucleotideCounter = new NucleotideCounter("GGGGGGGG");
30
+    public void testDnaStringHasOneNucleotide() {
31
+        NucleotideCounter nucleotideCounter = new NucleotideCounter("G");
47 32
         Map<Character, Integer> counts = nucleotideCounter.nucleotideCounts();
48
-        assertThat(counts.size(), is(4));
49 33
         assertThat(counts, allOf(
50 34
                 hasEntry('A', 0),
51 35
                 hasEntry('C', 0),
52
-                hasEntry('G', 8),
36
+                hasEntry('G', 1),
53 37
                 hasEntry('T', 0)
54 38
         ));
55 39
     }
56 40
 
57 41
     @Ignore("Remove to run test")
58 42
     @Test
59
-    public void testCountsOnlyThymine() {
60
-        NucleotideCounter nucleotideCounter = new NucleotideCounter("GGGGGTAACCCGG");
61
-        assertThat(nucleotideCounter.count('T'), is(1));
62
-    }
63
-
64
-    @Ignore("Remove to run test")
65
-    @Test
66
-    public void testCountsANucleotideOnlyOnce() {
67
-        NucleotideCounter nucleotideCounter = new NucleotideCounter("CGATTGGG");
68
-        nucleotideCounter.count('T');
69
-        assertThat(nucleotideCounter.count('T'), is(2));
70
-    }
71
-
72
-    @Ignore("Remove to run test")
73
-    @Test
74
-    public void testDnaCountsDoNotChangeAfterCountingAdenine() {
75
-        NucleotideCounter nucleotideCounter = new NucleotideCounter("GATTACA");
76
-        nucleotideCounter.count('A');
43
+    public void testRepetitiveSequenceWithOnlyGuanine() {
44
+        NucleotideCounter nucleotideCounter = new NucleotideCounter("GGGGGGG");
77 45
         Map<Character, Integer> counts = nucleotideCounter.nucleotideCounts();
78
-        assertThat(counts.size(), is(4));
79 46
         assertThat(counts, allOf(
80
-                hasEntry('A', 3),
81
-                hasEntry('C', 1),
82
-                hasEntry('G', 1),
83
-                hasEntry('T', 2)
47
+                hasEntry('A', 0),
48
+                hasEntry('C', 0),
49
+                hasEntry('G', 7),
50
+                hasEntry('T', 0)
84 51
         ));
85 52
     }
86 53
 
87 54
     @Ignore("Remove to run test")
88 55
     @Test
89
-    public void testValidatesNucleotides() {
90
-        expectedException.expect(IllegalArgumentException.class);
91
-        NucleotideCounter nucleotideCounter = new NucleotideCounter("GACT");
92
-        nucleotideCounter.count('X');
93
-    }
94
-
95
-    @Ignore("Remove to run test")
96
-    @Test
97
-    public void testCountsAllNucleotides() {
98
-        String s = "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC";
99
-        NucleotideCounter nucleotideCounter = new NucleotideCounter(s);
56
+    public void testDnaStringHasMultipleNucleotide() {
57
+        NucleotideCounter nucleotideCounter
58
+            = new NucleotideCounter("AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC");
100 59
         Map<Character, Integer> counts = nucleotideCounter.nucleotideCounts();
101
-        assertThat(counts.size(), is(4));
102 60
         assertThat(counts, allOf(
103 61
                 hasEntry('A', 20),
104 62
                 hasEntry('C', 12),
@@ -106,4 +64,11 @@ public class NucleotideCounterTest {
106 64
                 hasEntry('T', 21)
107 65
         ));
108 66
     }
67
+
68
+    @Ignore("Remove to run test")
69
+    @Test
70
+    public void testDnaStringHasInvalidNucleotides() {
71
+        expectedException.expect(IllegalArgumentException.class);
72
+        NucleotideCounter nucleotideCounter = new NucleotideCounter("AGXXACT");
73
+    }
109 74
 }