Sfoglia il codice sorgente

Issue #200: Replaced assertj assertions in nucleotide-count tests with junit and assertj assertions. Removed assertj from nucleotide-count gradle build file. Added extra hamcrest library to nucleotide-count gradle build file to be able to use hasEntry for maps.

Frida Tveit 9 anni fa
parent
commit
fb48b956de

+ 1
- 1
exercises/nucleotide-count/build.gradle Vedi File

8
 
8
 
9
 dependencies {
9
 dependencies {
10
   testCompile "junit:junit:4.12"
10
   testCompile "junit:junit:4.12"
11
-  testCompile "org.assertj:assertj-core:3.2.0"
11
+  testCompile 'org.hamcrest:hamcrest-library:1.3'
12
 }
12
 }
13
 
13
 
14
 test {
14
 test {

+ 42
- 32
exercises/nucleotide-count/src/test/java/NucleotideTest.java Vedi File

1
-import static org.assertj.core.api.Assertions.assertThat;
2
-import static org.assertj.core.api.Assertions.entry;
3
-
4
-import org.junit.Test;
5
 import org.junit.Ignore;
1
 import org.junit.Ignore;
2
+import org.junit.Test;
3
+
4
+import java.util.Map;
5
+
6
+import static org.hamcrest.Matchers.*;
7
+import static org.junit.Assert.*;
6
 
8
 
7
 public class NucleotideTest {
9
 public class NucleotideTest {
8
 
10
 
9
     @Test
11
     @Test
10
     public void testEmptyDnaStringHasNoAdenosine() {
12
     public void testEmptyDnaStringHasNoAdenosine() {
11
         DNA dna = new DNA("");
13
         DNA dna = new DNA("");
12
-        assertThat(dna.count('A')).isEqualTo(0);
14
+        assertThat(dna.count('A'), is(0));
13
     }
15
     }
14
 
16
 
15
     @Ignore
17
     @Ignore
16
     @Test
18
     @Test
17
     public void testEmptyDnaStringHasNoNucleotides() {
19
     public void testEmptyDnaStringHasNoNucleotides() {
18
         DNA dna = new DNA("");
20
         DNA dna = new DNA("");
19
-        assertThat(dna.nucleotideCounts()).hasSize(4).contains(
20
-            entry('A', 0),
21
-            entry('C', 0),
22
-            entry('G', 0),
23
-            entry('T', 0)
24
-        );
21
+        Map<Character, Integer> counts = dna.nucleotideCounts();
22
+        assertThat(counts.size(), is(4));
23
+        assertThat(counts, allOf(
24
+                hasEntry('A', 0),
25
+                hasEntry('C', 0),
26
+                hasEntry('G', 0),
27
+                hasEntry('T', 0)
28
+        ));
25
     }
29
     }
26
 
30
 
27
     @Ignore
31
     @Ignore
28
     @Test
32
     @Test
29
     public void testRepetitiveCytidineGetsCounted() {
33
     public void testRepetitiveCytidineGetsCounted() {
30
         DNA dna = new DNA("CCCCC");
34
         DNA dna = new DNA("CCCCC");
31
-        assertThat(dna.count('C')).isEqualTo(5);
35
+        assertThat(dna.count('C'), is(5));
32
     }
36
     }
33
 
37
 
34
     @Ignore
38
     @Ignore
35
     @Test
39
     @Test
36
     public void testRepetitiveSequenceWithOnlyGuanosine() {
40
     public void testRepetitiveSequenceWithOnlyGuanosine() {
37
         DNA dna = new DNA("GGGGGGGG");
41
         DNA dna = new DNA("GGGGGGGG");
38
-        assertThat(dna.nucleotideCounts()).hasSize(4).contains(
39
-            entry('A', 0),
40
-            entry('C', 0),
41
-            entry('G', 8),
42
-            entry('T', 0)
43
-        );
42
+        Map<Character, Integer> counts = dna.nucleotideCounts();
43
+        assertThat(counts.size(), is(4));
44
+        assertThat(counts, allOf(
45
+                hasEntry('A', 0),
46
+                hasEntry('C', 0),
47
+                hasEntry('G', 8),
48
+                hasEntry('T', 0)
49
+        ));
44
     }
50
     }
45
 
51
 
46
     @Ignore
52
     @Ignore
47
     @Test
53
     @Test
48
     public void testCountsOnlyThymidine() {
54
     public void testCountsOnlyThymidine() {
49
         DNA dna = new DNA("GGGGGTAACCCGG");
55
         DNA dna = new DNA("GGGGGTAACCCGG");
50
-        assertThat(dna.count('T')).isEqualTo(1);
56
+        assertThat(dna.count('T'), is(1));
51
     }
57
     }
52
 
58
 
53
     @Ignore
59
     @Ignore
55
     public void testCountsANucleotideOnlyOnce() {
61
     public void testCountsANucleotideOnlyOnce() {
56
         DNA dna = new DNA("CGATTGGG");
62
         DNA dna = new DNA("CGATTGGG");
57
         dna.count('T');
63
         dna.count('T');
58
-        assertThat(dna.count('T')).isEqualTo(2);
64
+        assertThat(dna.count('T'), is(2));
59
     }
65
     }
60
 
66
 
61
     @Ignore
67
     @Ignore
63
     public void testDnaCountsDoNotChangeAfterCountingAdenosine() {
69
     public void testDnaCountsDoNotChangeAfterCountingAdenosine() {
64
         DNA dna = new DNA("GATTACA");
70
         DNA dna = new DNA("GATTACA");
65
         dna.count('A');
71
         dna.count('A');
66
-        assertThat(dna.nucleotideCounts()).hasSize(4).contains(
67
-            entry('A', 3),
68
-            entry('C', 1),
69
-            entry('G', 1),
70
-            entry('T', 2)
71
-        );
72
+        Map<Character, Integer> counts = dna.nucleotideCounts();
73
+        assertThat(counts.size(), is(4));
74
+        assertThat(counts, allOf(
75
+                hasEntry('A', 3),
76
+                hasEntry('C', 1),
77
+                hasEntry('G', 1),
78
+                hasEntry('T', 2)
79
+        ));
72
     }
80
     }
73
 
81
 
74
     @Ignore
82
     @Ignore
83
     public void testCountsAllNucleotides() {
91
     public void testCountsAllNucleotides() {
84
         String s = "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC";
92
         String s = "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC";
85
         DNA dna = new DNA(s);
93
         DNA dna = new DNA(s);
86
-        assertThat(dna.nucleotideCounts()).hasSize(4).contains(
87
-            entry('A', 20),
88
-            entry('C', 12),
89
-            entry('G', 17),
90
-            entry('T', 21)
91
-        );
94
+        Map<Character, Integer> counts = dna.nucleotideCounts();
95
+        assertThat(counts.size(), is(4));
96
+        assertThat(counts, allOf(
97
+                hasEntry('A', 20),
98
+                hasEntry('C', 12),
99
+                hasEntry('G', 17),
100
+                hasEntry('T', 21)
101
+        ));
92
     }
102
     }
93
 }
103
 }