Selaa lähdekoodia

Merge pull request #731 from McEileen/rna-transcription-invalid-input

Add tests to catch invalid input edge cases
Logan Stucki 9 vuotta sitten
vanhempi
commit
ef184d585b

+ 3
- 0
exercises/rna-transcription/src/example/java/RnaTranscription.java Näytä tiedosto

16
                 case 'T':
16
                 case 'T':
17
                     sb.append('A');
17
                     sb.append('A');
18
                     break;
18
                     break;
19
+                default:
20
+                    throw new IllegalArgumentException("Invalid input");
21
+
19
             }
22
             }
20
         }
23
         }
21
         return sb.toString();
24
         return sb.toString();

+ 33
- 0
exercises/rna-transcription/src/test/java/RnaTranscriptionTest.java Näytä tiedosto

2
 import org.junit.Before;
2
 import org.junit.Before;
3
 import org.junit.Ignore;
3
 import org.junit.Ignore;
4
 import org.junit.Test;
4
 import org.junit.Test;
5
+import org.junit.rules.ExpectedException;
6
+import org.junit.Rule;
5
 
7
 
6
 public class RnaTranscriptionTest {
8
 public class RnaTranscriptionTest {
7
 
9
 
10
+    /*
11
+    version: 2.0.0
12
+     */
13
+
14
+    @Rule
15
+    public ExpectedException thrown = ExpectedException.none();
16
+
8
     private RnaTranscription rnaTranscription;
17
     private RnaTranscription rnaTranscription;
9
 
18
 
10
     @Before
19
     @Before
46
     public void testRnaTranscription() {
55
     public void testRnaTranscription() {
47
         Assert.assertEquals("UGCACCAGAAUU", rnaTranscription.transcribe("ACGTGGTCTTAA"));
56
         Assert.assertEquals("UGCACCAGAAUU", rnaTranscription.transcribe("ACGTGGTCTTAA"));
48
     }
57
     }
58
+
59
+    @Ignore("Remove to run test")
60
+    @Test
61
+    public void testRnaTranscriptionOfRnaThrowsAnError() {
62
+        thrown.expect(IllegalArgumentException.class);
63
+        thrown.expectMessage("Invalid input");
64
+        rnaTranscription.transcribe("U");
65
+    }
66
+
67
+    @Ignore("Remove to run test")
68
+    @Test
69
+    public void testRnaTranscriptionOfInvalidInputThrowsAnError() {
70
+        thrown.expect(IllegalArgumentException.class);
71
+        thrown.expectMessage("Invalid input");
72
+        rnaTranscription.transcribe("BFV");
73
+    }
74
+
75
+    @Ignore("Remove to run test")
76
+    @Test
77
+    public void testRnaTranscriptionOfPartiallyInvalidInput() {
78
+        thrown.expect(IllegalArgumentException.class);
79
+        thrown.expectMessage("Invalid input");
80
+        rnaTranscription.transcribe("GCVV");
81
+    }
49
 }
82
 }