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

Merge pull request #703 from FridaTveit/RotationalCipherEstimate

rotational-cipher: estimate and tidy
FridaTveit 9 лет назад
Родитель
Сommit
b326840b4d

+ 10
- 10
config.json Просмотреть файл

@@ -205,6 +205,16 @@
205 205
       ]
206 206
     },
207 207
     {
208
+      "uuid": "9eb41883-55ef-4681-b5ac-5c2259302772",
209
+      "slug": "rotational-cipher",
210
+      "core": false,
211
+      "unlocked_by": null,
212
+      "difficulty": 4,
213
+      "topics": [
214
+
215
+      ]
216
+    },
217
+    {
208 218
       "uuid": "0b92ffee-c092-4ab1-ad78-76c8cf80e1b5",
209 219
       "slug": "kindergarten-garden",
210 220
       "core": false,
@@ -769,16 +779,6 @@
769 779
       ]
770 780
     },
771 781
     {
772
-      "uuid": "9eb41883-55ef-4681-b5ac-5c2259302772",
773
-      "slug": "rotational-cipher",
774
-      "core": false,
775
-      "unlocked_by": null,
776
-      "difficulty": 1,
777
-      "topics": [
778
-
779
-      ]
780
-    },
781
-    {
782 782
       "uuid": "e58c29d2-80a7-40ef-bed0-4a184ae35f34",
783 783
       "slug": "accumulate",
784 784
       "deprecated": true

+ 5
- 8
exercises/rotational-cipher/src/example/java/RotationalCipher.java Просмотреть файл

@@ -1,13 +1,12 @@
1
+class RotationalCipher {
1 2
 
2
-public class RotationalCipher {
3
-
4
-    int shiftKey;
3
+    private int shiftKey;
5 4
 
6 5
     RotationalCipher(int shiftKey) {
7 6
         this.shiftKey = shiftKey;
8 7
     }
9 8
 
10
-    public String rotate(String data) {
9
+    String rotate(String data) {
11 10
         StringBuilder dataStringBuilder = new StringBuilder();
12 11
         for (char c : data.toCharArray()) {
13 12
             if (Character.isUpperCase(c)) {
@@ -25,12 +24,10 @@ public class RotationalCipher {
25 24
      * For Uppercase CaseStart = 'A' and CaseEnd = 'Z'
26 25
      * For Lowercase CaseStart = 'a' and CaseEnd = 'z'
27 26
      */
28
-    private char getReplacementCharacter(char characterToReplace,
29
-            char alphabetCaseStart, char alphabetCaseEnd) {
27
+    private char getReplacementCharacter(char characterToReplace, char alphabetCaseStart, char alphabetCaseEnd) {
30 28
         char replacementCharacter = (char) (characterToReplace + shiftKey);
31 29
         if (replacementCharacter > alphabetCaseEnd) {
32
-            replacementCharacter = (char) ((alphabetCaseStart - 1) +
33
-             (replacementCharacter % alphabetCaseEnd));
30
+            replacementCharacter = (char) ((alphabetCaseStart - 1) + (replacementCharacter % alphabetCaseEnd));
34 31
         }
35 32
         return replacementCharacter;
36 33
     }

+ 3
- 6
exercises/rotational-cipher/src/test/java/RotationalCipherTest.java Просмотреть файл

@@ -1,6 +1,4 @@
1
-
2 1
 import org.junit.Assert;
3
-import org.junit.Before;
4 2
 import org.junit.Ignore;
5 3
 import org.junit.Test;
6 4
 
@@ -13,7 +11,7 @@ public class RotationalCipherTest {
13 11
         rotationalCipher = new RotationalCipher(1);
14 12
         Assert.assertEquals("b", rotationalCipher.rotate("a"));
15 13
     }
16
-    
14
+
17 15
     @Ignore("Remove to run test")
18 16
     @Test
19 17
     public void rotateSingleCharacterBy26() {
@@ -75,7 +73,6 @@ public class RotationalCipherTest {
75 73
     public void rotateAllLetters() {
76 74
         rotationalCipher = new RotationalCipher(13);
77 75
         Assert.assertEquals("The quick brown fox jumps over the lazy dog.",
78
-         rotationalCipher.rotate("Gur dhvpx oebja sbk whzcf bire gur ynml qbt."));
79
-    } 
80
-
76
+                rotationalCipher.rotate("Gur dhvpx oebja sbk whzcf bire gur ynml qbt."));
77
+    }
81 78
 }