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

Merge pull request #699 from FridaTveit/NucleotideCountRenameClasses

nucleotide-count: rename classes
Stuart Kent 9 лет назад
Родитель
Сommit
69eecef632

+ 9
- 1
POLICIES.md Просмотреть файл

@@ -17,7 +17,7 @@ Our policies are not set-in-stone. They represent directions chosen at a point i
17 17
 
18 18
 | Track Event | Policies to review |
19 19
 |:------------|:-----------------|
20
-| Exercise added/updated | [Prefer instance methods](#prefer-instance-methods); [Avoid using final](#avoid-using-final); [Adhere to best practices](#adhere-to-best-practices); [Starter implementations](#starter-implementations); [Ignore noninitial tests](#ignore-noninitial-tests); [Multiple file submissions](#multiple-file-submissions) |
20
+| Exercise added/updated | [Prefer instance methods](#prefer-instance-methods); [Avoid using final](#avoid-using-final); [Adhere to best practices](#adhere-to-best-practices); [Starter implementations](#starter-implementations); [Ignore noninitial tests](#ignore-noninitial-tests); [Multiple file submissions](#multiple-file-submissions); [Name test class after class under test](#name-test-class-after-class-under-test)
21 21
 | Track rearranged | [Starter implementations](#starter-implementations); [Multiple file submissions](#multiple-file-submissions) |
22 22
 | New issue observed in track | [Good first patches](#good-first-patches) |
23 23
 | "Good first patch" issue completed | [Good first patches](#good-first-patches) |
@@ -71,3 +71,11 @@ References: [[1](https://github.com/exercism/java/issues/220#issue-196447088)]
71 71
 > The Installing Java instructions should seek to minimize the number of steps and the number of concepts a new-to-the-track practitioner needs to learn to get to coding.
72 72
 
73 73
 References: [[1](https://github.com/exercism/java/issues/395#issue-215734887)]
74
+
75
+### Name test class after class under test
76
+
77
+> If you're testing a class called `SomeClassName` then your test class should be called `SomeClassNameTest`. 
78
+
79
+> The exception to this is if the tests are split into several test classes where each test class tests different functionality. In that case each class should be named `SomeClassNameFunctionalityTest` where `Functionality` is the name of the functionality to be tested in that class. See the [clock exercise](https://github.com/exercism/java/tree/master/exercises/clock) as an example.
80
+
81
+References: [[1](https://github.com/exercism/java/issues/697)]

exercises/nucleotide-count/src/example/java/DNA.java → exercises/nucleotide-count/src/example/java/NucleotideCounter.java Просмотреть файл

@@ -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 Просмотреть файл

@@ -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),