Ver código fonte

nucleotide-count: rename class and test class

Rename class user test to be more similar to the name of the exercise.
Rename the test class to use the name of the class user test.
Frida Tveit 9 anos atrás
pai
commit
0107cd6aff

exercises/nucleotide-count/src/example/java/DNA.java → exercises/nucleotide-count/src/example/java/NucleotideCounter.java Ver arquivo

1
 import java.util.HashMap;
1
 import java.util.HashMap;
2
 import java.util.Map;
2
 import java.util.Map;
3
 
3
 
4
-public final class DNA {
4
+final class NucleotideCounter {
5
   private final String sequence;
5
   private final String sequence;
6
 
6
 
7
-  public DNA(String sequence) {
7
+  NucleotideCounter(String sequence) {
8
     this.sequence = sequence;
8
     this.sequence = sequence;
9
   }
9
   }
10
 
10
 
11
-  public int count(char base) {
11
+  int count(char base) {
12
     if (isCountable(base))
12
     if (isCountable(base))
13
       throw new IllegalArgumentException(base + " is not a nucleotide");
13
       throw new IllegalArgumentException(base + " is not a nucleotide");
14
 
14
 
24
     return COUNTABLE_NUCLEOTIDES.indexOf(base) == -1;
24
     return COUNTABLE_NUCLEOTIDES.indexOf(base) == -1;
25
   }
25
   }
26
 
26
 
27
-  public Map<Character, Integer> nucleotideCounts() {
27
+  Map<Character, Integer> nucleotideCounts() {
28
     Map<Character, Integer> counts = emptyCounts();
28
     Map<Character, Integer> counts = emptyCounts();
29
     for (char c : sequence.toCharArray()) {
29
     for (char c : sequence.toCharArray()) {
30
       counts.put(c, counts.get(c) + 1);
30
       counts.put(c, counts.get(c) + 1);

exercises/nucleotide-count/src/test/java/NucleotideTest.java → exercises/nucleotide-count/src/test/java/NucleotideCounterTest.java Ver arquivo

8
 import static org.hamcrest.Matchers.*;
8
 import static org.hamcrest.Matchers.*;
9
 import static org.junit.Assert.*;
9
 import static org.junit.Assert.*;
10
 
10
 
11
-public class NucleotideTest {
11
+public class NucleotideCounterTest {
12
 
12
 
13
     @Rule
13
     @Rule
14
     public ExpectedException expectedException = ExpectedException.none();
14
     public ExpectedException expectedException = ExpectedException.none();
15
 
15
 
16
     @Test
16
     @Test
17
     public void testEmptyDnaStringHasNoAdenine() {
17
     public void testEmptyDnaStringHasNoAdenine() {
18
-        DNA dna = new DNA("");
19
-        assertThat(dna.count('A'), is(0));
18
+        NucleotideCounter nucleotideCounter = new NucleotideCounter("");
19
+        assertThat(nucleotideCounter.count('A'), is(0));
20
     }
20
     }
21
 
21
 
22
     @Ignore("Remove to run test")
22
     @Ignore("Remove to run test")
23
     @Test
23
     @Test
24
     public void testEmptyDnaStringHasNoNucleotides() {
24
     public void testEmptyDnaStringHasNoNucleotides() {
25
-        DNA dna = new DNA("");
26
-        Map<Character, Integer> counts = dna.nucleotideCounts();
25
+        NucleotideCounter nucleotideCounter = new NucleotideCounter("");
26
+        Map<Character, Integer> counts = nucleotideCounter.nucleotideCounts();
27
         assertThat(counts.size(), is(4));
27
         assertThat(counts.size(), is(4));
28
         assertThat(counts, allOf(
28
         assertThat(counts, allOf(
29
                 hasEntry('A', 0),
29
                 hasEntry('A', 0),
36
     @Ignore("Remove to run test")
36
     @Ignore("Remove to run test")
37
     @Test
37
     @Test
38
     public void testRepetitiveCytosineGetsCounted() {
38
     public void testRepetitiveCytosineGetsCounted() {
39
-        DNA dna = new DNA("CCCCC");
40
-        assertThat(dna.count('C'), is(5));
39
+        NucleotideCounter nucleotideCounter = new NucleotideCounter("CCCCC");
40
+        assertThat(nucleotideCounter.count('C'), is(5));
41
     }
41
     }
42
 
42
 
43
     @Ignore("Remove to run test")
43
     @Ignore("Remove to run test")
44
     @Test
44
     @Test
45
     public void testRepetitiveSequenceWithOnlyGuanine() {
45
     public void testRepetitiveSequenceWithOnlyGuanine() {
46
-        DNA dna = new DNA("GGGGGGGG");
47
-        Map<Character, Integer> counts = dna.nucleotideCounts();
46
+        NucleotideCounter nucleotideCounter = new NucleotideCounter("GGGGGGGG");
47
+        Map<Character, Integer> counts = nucleotideCounter.nucleotideCounts();
48
         assertThat(counts.size(), is(4));
48
         assertThat(counts.size(), is(4));
49
         assertThat(counts, allOf(
49
         assertThat(counts, allOf(
50
                 hasEntry('A', 0),
50
                 hasEntry('A', 0),
57
     @Ignore("Remove to run test")
57
     @Ignore("Remove to run test")
58
     @Test
58
     @Test
59
     public void testCountsOnlyThymine() {
59
     public void testCountsOnlyThymine() {
60
-        DNA dna = new DNA("GGGGGTAACCCGG");
61
-        assertThat(dna.count('T'), is(1));
60
+        NucleotideCounter nucleotideCounter = new NucleotideCounter("GGGGGTAACCCGG");
61
+        assertThat(nucleotideCounter.count('T'), is(1));
62
     }
62
     }
63
 
63
 
64
     @Ignore("Remove to run test")
64
     @Ignore("Remove to run test")
65
     @Test
65
     @Test
66
     public void testCountsANucleotideOnlyOnce() {
66
     public void testCountsANucleotideOnlyOnce() {
67
-        DNA dna = new DNA("CGATTGGG");
68
-        dna.count('T');
69
-        assertThat(dna.count('T'), is(2));
67
+        NucleotideCounter nucleotideCounter = new NucleotideCounter("CGATTGGG");
68
+        nucleotideCounter.count('T');
69
+        assertThat(nucleotideCounter.count('T'), is(2));
70
     }
70
     }
71
 
71
 
72
     @Ignore("Remove to run test")
72
     @Ignore("Remove to run test")
73
     @Test
73
     @Test
74
     public void testDnaCountsDoNotChangeAfterCountingAdenine() {
74
     public void testDnaCountsDoNotChangeAfterCountingAdenine() {
75
-        DNA dna = new DNA("GATTACA");
76
-        dna.count('A');
77
-        Map<Character, Integer> counts = dna.nucleotideCounts();
75
+        NucleotideCounter nucleotideCounter = new NucleotideCounter("GATTACA");
76
+        nucleotideCounter.count('A');
77
+        Map<Character, Integer> counts = nucleotideCounter.nucleotideCounts();
78
         assertThat(counts.size(), is(4));
78
         assertThat(counts.size(), is(4));
79
         assertThat(counts, allOf(
79
         assertThat(counts, allOf(
80
                 hasEntry('A', 3),
80
                 hasEntry('A', 3),
88
     @Test
88
     @Test
89
     public void testValidatesNucleotides() {
89
     public void testValidatesNucleotides() {
90
         expectedException.expect(IllegalArgumentException.class);
90
         expectedException.expect(IllegalArgumentException.class);
91
-        DNA dna = new DNA("GACT");
92
-        dna.count('X');
91
+        NucleotideCounter nucleotideCounter = new NucleotideCounter("GACT");
92
+        nucleotideCounter.count('X');
93
     }
93
     }
94
 
94
 
95
     @Ignore("Remove to run test")
95
     @Ignore("Remove to run test")
96
     @Test
96
     @Test
97
     public void testCountsAllNucleotides() {
97
     public void testCountsAllNucleotides() {
98
         String s = "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC";
98
         String s = "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC";
99
-        DNA dna = new DNA(s);
100
-        Map<Character, Integer> counts = dna.nucleotideCounts();
99
+        NucleotideCounter nucleotideCounter = new NucleotideCounter(s);
100
+        Map<Character, Integer> counts = nucleotideCounter.nucleotideCounts();
101
         assertThat(counts.size(), is(4));
101
         assertThat(counts.size(), is(4));
102
         assertThat(counts, allOf(
102
         assertThat(counts, allOf(
103
                 hasEntry('A', 20),
103
                 hasEntry('A', 20),