瀏覽代碼

Merge pull request #703 from FridaTveit/RotationalCipherEstimate

rotational-cipher: estimate and tidy
FridaTveit 9 年之前
父節點
當前提交
b326840b4d

+ 10
- 10
config.json 查看文件

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
       "uuid": "0b92ffee-c092-4ab1-ad78-76c8cf80e1b5",
218
       "uuid": "0b92ffee-c092-4ab1-ad78-76c8cf80e1b5",
209
       "slug": "kindergarten-garden",
219
       "slug": "kindergarten-garden",
210
       "core": false,
220
       "core": false,
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
       "uuid": "e58c29d2-80a7-40ef-bed0-4a184ae35f34",
782
       "uuid": "e58c29d2-80a7-40ef-bed0-4a184ae35f34",
783
       "slug": "accumulate",
783
       "slug": "accumulate",
784
       "deprecated": true
784
       "deprecated": true

+ 5
- 8
exercises/rotational-cipher/src/example/java/RotationalCipher.java 查看文件

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

+ 3
- 6
exercises/rotational-cipher/src/test/java/RotationalCipherTest.java 查看文件

1
-
2
 import org.junit.Assert;
1
 import org.junit.Assert;
3
-import org.junit.Before;
4
 import org.junit.Ignore;
2
 import org.junit.Ignore;
5
 import org.junit.Test;
3
 import org.junit.Test;
6
 
4
 
13
         rotationalCipher = new RotationalCipher(1);
11
         rotationalCipher = new RotationalCipher(1);
14
         Assert.assertEquals("b", rotationalCipher.rotate("a"));
12
         Assert.assertEquals("b", rotationalCipher.rotate("a"));
15
     }
13
     }
16
-    
14
+
17
     @Ignore("Remove to run test")
15
     @Ignore("Remove to run test")
18
     @Test
16
     @Test
19
     public void rotateSingleCharacterBy26() {
17
     public void rotateSingleCharacterBy26() {
75
     public void rotateAllLetters() {
73
     public void rotateAllLetters() {
76
         rotationalCipher = new RotationalCipher(13);
74
         rotationalCipher = new RotationalCipher(13);
77
         Assert.assertEquals("The quick brown fox jumps over the lazy dog.",
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
 }