Преглед изворни кода

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 година
родитељ
комит
2a7d3ead79

+ 7
- 1
exercises/nucleotide-count/.meta/src/reference/java/NucleotideCounter.java Прегледај датотеку

6
 
6
 
7
   NucleotideCounter(String sequence) {
7
   NucleotideCounter(String sequence) {
8
     this.sequence = sequence;
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
   int count(char base) {
16
   int count(char base) {
12
-    if (isCountable(base))
17
+    if (isCountable(base)) {
13
       throw new IllegalArgumentException(base + " is not a nucleotide");
18
       throw new IllegalArgumentException(base + " is not a nucleotide");
19
+    }
14
 
20
 
15
     try {
21
     try {
16
       return nucleotideCounts().get(base);
22
       return nucleotideCounts().get(base);

+ 1
- 0
exercises/nucleotide-count/.meta/version Прегледај датотеку

1
+1.3.0

+ 19
- 54
exercises/nucleotide-count/src/test/java/NucleotideCounterTest.java Прегледај датотеку

14
     public ExpectedException expectedException = ExpectedException.none();
14
     public ExpectedException expectedException = ExpectedException.none();
15
 
15
 
16
     @Test
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
     public void testEmptyDnaStringHasNoNucleotides() {
17
     public void testEmptyDnaStringHasNoNucleotides() {
25
         NucleotideCounter nucleotideCounter = new NucleotideCounter("");
18
         NucleotideCounter nucleotideCounter = new NucleotideCounter("");
26
         Map<Character, Integer> counts = nucleotideCounter.nucleotideCounts();
19
         Map<Character, Integer> counts = nucleotideCounter.nucleotideCounts();
27
-        assertThat(counts.size(), is(4));
28
         assertThat(counts, allOf(
20
         assertThat(counts, allOf(
29
                 hasEntry('A', 0),
21
                 hasEntry('A', 0),
30
                 hasEntry('C', 0),
22
                 hasEntry('C', 0),
35
 
27
 
36
     @Ignore("Remove to run test")
28
     @Ignore("Remove to run test")
37
     @Test
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
         Map<Character, Integer> counts = nucleotideCounter.nucleotideCounts();
32
         Map<Character, Integer> counts = nucleotideCounter.nucleotideCounts();
48
-        assertThat(counts.size(), is(4));
49
         assertThat(counts, allOf(
33
         assertThat(counts, allOf(
50
                 hasEntry('A', 0),
34
                 hasEntry('A', 0),
51
                 hasEntry('C', 0),
35
                 hasEntry('C', 0),
52
-                hasEntry('G', 8),
36
+                hasEntry('G', 1),
53
                 hasEntry('T', 0)
37
                 hasEntry('T', 0)
54
         ));
38
         ));
55
     }
39
     }
56
 
40
 
57
     @Ignore("Remove to run test")
41
     @Ignore("Remove to run test")
58
     @Test
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
         Map<Character, Integer> counts = nucleotideCounter.nucleotideCounts();
45
         Map<Character, Integer> counts = nucleotideCounter.nucleotideCounts();
78
-        assertThat(counts.size(), is(4));
79
         assertThat(counts, allOf(
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
     @Ignore("Remove to run test")
54
     @Ignore("Remove to run test")
88
     @Test
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
         Map<Character, Integer> counts = nucleotideCounter.nucleotideCounts();
59
         Map<Character, Integer> counts = nucleotideCounter.nucleotideCounts();
101
-        assertThat(counts.size(), is(4));
102
         assertThat(counts, allOf(
60
         assertThat(counts, allOf(
103
                 hasEntry('A', 20),
61
                 hasEntry('A', 20),
104
                 hasEntry('C', 12),
62
                 hasEntry('C', 12),
106
                 hasEntry('T', 21)
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
 }