Przeglądaj źródła

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 lat temu
rodzic
commit
0107cd6aff

exercises/nucleotide-count/src/example/java/DNA.java → exercises/nucleotide-count/src/example/java/NucleotideCounter.java Wyświetl plik

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

exercises/nucleotide-count/src/test/java/NucleotideTest.java → exercises/nucleotide-count/src/test/java/NucleotideCounterTest.java Wyświetl plik

@@ -8,22 +8,22 @@ import java.util.Map;
8 8
 import static org.hamcrest.Matchers.*;
9 9
 import static org.junit.Assert.*;
10 10
 
11
-public class NucleotideTest {
11
+public class NucleotideCounterTest {
12 12
 
13 13
     @Rule
14 14
     public ExpectedException expectedException = ExpectedException.none();
15 15
 
16 16
     @Test
17 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 22
     @Ignore("Remove to run test")
23 23
     @Test
24 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 27
         assertThat(counts.size(), is(4));
28 28
         assertThat(counts, allOf(
29 29
                 hasEntry('A', 0),
@@ -36,15 +36,15 @@ public class NucleotideTest {
36 36
     @Ignore("Remove to run test")
37 37
     @Test
38 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 43
     @Ignore("Remove to run test")
44 44
     @Test
45 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 48
         assertThat(counts.size(), is(4));
49 49
         assertThat(counts, allOf(
50 50
                 hasEntry('A', 0),
@@ -57,24 +57,24 @@ public class NucleotideTest {
57 57
     @Ignore("Remove to run test")
58 58
     @Test
59 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 64
     @Ignore("Remove to run test")
65 65
     @Test
66 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 72
     @Ignore("Remove to run test")
73 73
     @Test
74 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 78
         assertThat(counts.size(), is(4));
79 79
         assertThat(counts, allOf(
80 80
                 hasEntry('A', 3),
@@ -88,16 +88,16 @@ public class NucleotideTest {
88 88
     @Test
89 89
     public void testValidatesNucleotides() {
90 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 95
     @Ignore("Remove to run test")
96 96
     @Test
97 97
     public void testCountsAllNucleotides() {
98 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 101
         assertThat(counts.size(), is(4));
102 102
         assertThat(counts, allOf(
103 103
                 hasEntry('A', 20),