Procházet zdrojové kódy

Merge branch 'pr/41'

Piet van Dongen před 11 roky
rodič
revize
6b9cc220fe

+ 3
- 1
config.json Zobrazit soubor

@@ -26,7 +26,9 @@
26 26
     "strain",
27 27
     "atbash-cipher",
28 28
     "accumulate",
29
-    "crypto-square"
29
+    "crypto-square",
30
+    "trinary",
31
+    "rna-transcription"
30 32
   ],
31 33
   "deprecated": [
32 34
   ],

+ 11
- 0
rna-transcription/build.gradle Zobrazit soubor

@@ -0,0 +1,11 @@
1
+apply plugin: "java"
2
+apply plugin: "eclipse"
3
+apply plugin: "idea"
4
+
5
+repositories {
6
+  mavenCentral()
7
+}
8
+
9
+dependencies {
10
+  testCompile "junit:junit:4.10"
11
+}

+ 23
- 0
rna-transcription/example.java Zobrazit soubor

@@ -0,0 +1,23 @@
1
+public class RnaTranscription {
2
+
3
+    public static String ofDna(String strand) {
4
+        StringBuilder sb = new StringBuilder();
5
+        for (char c : strand.toCharArray()) {
6
+            switch (c) {
7
+                case 'A':
8
+                    sb.append('U');
9
+                    break;
10
+                case 'G':
11
+                    sb.append('C');
12
+                    break;
13
+                case 'C':
14
+                    sb.append('G');
15
+                    break;
16
+                case 'T':
17
+                    sb.append('A');
18
+                    break;
19
+            }
20
+        }
21
+        return sb.toString();
22
+    }
23
+}

+ 0
- 0
rna-transcription/src/main/java/.keep Zobrazit soubor


+ 2
- 0
rna-transcription/src/main/java/RnaTranscription.java Zobrazit soubor

@@ -0,0 +1,2 @@
1
+public class RnaTranscription {
2
+}

+ 35
- 0
rna-transcription/src/test/java/RnaTranscriptionTest.java Zobrazit soubor

@@ -0,0 +1,35 @@
1
+import org.junit.Assert;
2
+import org.junit.Test;
3
+
4
+public class RnaTranscriptionTest {
5
+
6
+    @Test
7
+    public void testRnaTranscriptionOfEmptyDnaIsEmptyRna() {
8
+        Assert.assertEquals("", RnaTranscription.ofDna(""));
9
+    }
10
+
11
+    @Test
12
+    public void testRnaTranscriptionOfCytosineIsGuanine() {
13
+        Assert.assertEquals("G", RnaTranscription.ofDna("C"));
14
+    }
15
+
16
+    @Test
17
+    public void testRnaTranscriptionOfGuanineIsCytosine() {
18
+        Assert.assertEquals("C", RnaTranscription.ofDna("G"));
19
+    }
20
+
21
+    @Test
22
+    public void testRnaTranscriptionOfThymineIsAdenine() {
23
+        Assert.assertEquals("A", RnaTranscription.ofDna("T"));
24
+    }
25
+
26
+    @Test
27
+    public void testRnaTranscriptionOfAdenineIsUracil() {
28
+        Assert.assertEquals("U", RnaTranscription.ofDna("A"));
29
+    }
30
+
31
+    @Test
32
+    public void testRnaTranscription() {
33
+        Assert.assertEquals("UGCACCAGAAUU", RnaTranscription.ofDna("ACGTGGTCTTAA"));
34
+    }
35
+}

+ 11
- 0
trinary/build.gradle Zobrazit soubor

@@ -0,0 +1,11 @@
1
+apply plugin: "java"
2
+apply plugin: "eclipse"
3
+apply plugin: "idea"
4
+
5
+repositories {
6
+  mavenCentral()
7
+}
8
+
9
+dependencies {
10
+  testCompile "junit:junit:4.10"
11
+}

+ 25
- 0
trinary/example.java Zobrazit soubor

@@ -0,0 +1,25 @@
1
+public class Trinary {
2
+
3
+    private static final int RADIX = 3;
4
+
5
+    public static int toDecimal(String trinary) {
6
+        if (!validTrinary(trinary)) {
7
+            return 0;
8
+        }
9
+
10
+        int result = 0;
11
+        int power = 1;
12
+
13
+        for (int i = trinary.toCharArray().length - 1; i >= 0; i--) {
14
+            int digit = Character.digit(trinary.charAt(i), RADIX);
15
+            result += digit * power;
16
+            power *= RADIX;
17
+        }
18
+
19
+        return result;
20
+    }
21
+
22
+    private static boolean validTrinary(String trinary) {
23
+        return trinary.matches("[012]+");
24
+    }
25
+}

+ 0
- 0
trinary/src/main/java/.keep Zobrazit soubor


+ 2
- 0
trinary/src/main/java/Trinary.java Zobrazit soubor

@@ -0,0 +1,2 @@
1
+public class Trinary {
2
+}

+ 25
- 0
trinary/src/test/java/TrinaryTest.java Zobrazit soubor

@@ -0,0 +1,25 @@
1
+import static org.junit.Assert.assertEquals;
2
+
3
+import org.junit.Test;
4
+
5
+public class TrinaryTest {
6
+    @Test
7
+    public void testNonTrinaryCharacterIsZero() {
8
+        assertEquals(0, Trinary.toDecimal("-"));
9
+    }
10
+
11
+    @Test
12
+    public void testNonTrinaryNumberIsZero() {
13
+        assertEquals(0, Trinary.toDecimal("3"));
14
+    }
15
+
16
+    @Test
17
+    public void testTrinaryWithNonTrinaryIsZero() {
18
+        assertEquals(0, Trinary.toDecimal("102-12"));
19
+    }
20
+
21
+    @Test
22
+    public void testTrinary() {
23
+        assertEquals(302, Trinary.toDecimal("102012"));
24
+    }
25
+}