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

Merge pull request #699 from FridaTveit/NucleotideCountRenameClasses

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

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

17
 
17
 
18
 | Track Event | Policies to review |
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
 | Track rearranged | [Starter implementations](#starter-implementations); [Multiple file submissions](#multiple-file-submissions) |
21
 | Track rearranged | [Starter implementations](#starter-implementations); [Multiple file submissions](#multiple-file-submissions) |
22
 | New issue observed in track | [Good first patches](#good-first-patches) |
22
 | New issue observed in track | [Good first patches](#good-first-patches) |
23
 | "Good first patch" issue completed | [Good first patches](#good-first-patches) |
23
 | "Good first patch" issue completed | [Good first patches](#good-first-patches) |
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.
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
 References: [[1](https://github.com/exercism/java/issues/395#issue-215734887)]
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
 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 Просмотреть файл

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