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

Merge pull request #421 from FridaTveit/AtbashCipherUseInstanceMethod

atbash-cipher: make class use instance method [Fix #366]
Stuart Kent 9 лет назад
Родитель
Сommit
baf477c4af

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

@@ -7,7 +7,7 @@ public class Atbash {
7 7
     private static final String PLAIN = "abcdefghijklmnopqrstuvwxyz";
8 8
     private static final String CIPHER = "zyxwvutsrqponmlkjihgfedcba";
9 9
 
10
-    public static String encode(String input) {
10
+    public String encode(String input) {
11 11
         String encoded = stripInvalidCharacters(input).toLowerCase();
12 12
         String cyphered = "";
13 13
 
@@ -18,7 +18,7 @@ public class Atbash {
18 18
         return splitIntoFiveLetterWords(cyphered);
19 19
     }
20 20
 
21
-    public static String decode(String input) {
21
+    public String decode(String input) {
22 22
         String encoded = stripInvalidCharacters(input).toLowerCase();
23 23
         String deciphered = "";
24 24
 
@@ -29,7 +29,7 @@ public class Atbash {
29 29
         return deciphered;
30 30
     }
31 31
 
32
-    private static String stripInvalidCharacters(String input) {
32
+    private String stripInvalidCharacters(String input) {
33 33
         String filteredValue = "";
34 34
 
35 35
         for (char c : input.toCharArray()) {
@@ -41,13 +41,13 @@ public class Atbash {
41 41
         return filteredValue;
42 42
     }
43 43
 
44
-    private static char applyCipher(char input) {
44
+    private char applyCipher(char input) {
45 45
         int idx = PLAIN.indexOf(input);
46 46
 
47 47
         return idx >= 0 ? CIPHER.toCharArray()[idx] : input;
48 48
     }
49 49
 
50
-    private static String splitIntoFiveLetterWords(String value) {
50
+    private String splitIntoFiveLetterWords(String value) {
51 51
         List<String> words = new ArrayList<>();
52 52
 
53 53
         for (int i = 0; i < value.length(); i += GROUP_SIZE) {

+ 18
- 18
exercises/atbash-cipher/src/test/java/AtbashTest.java Просмотреть файл

@@ -1,5 +1,5 @@
1
-import org.junit.Test;
2 1
 import org.junit.Ignore;
2
+import org.junit.Test;
3 3
 import org.junit.experimental.runners.Enclosed;
4 4
 import org.junit.runner.RunWith;
5 5
 import org.junit.runners.Parameterized;
@@ -20,14 +20,14 @@ public class AtbashTest {
20 20
 
21 21
         @Parameters(name = "{index}: expected plaintext \"{0}\" to encode to ciphertext \"{1}\".")
22 22
         public static Collection<Object[]> data() {
23
-            return Arrays.asList(new Object[][] {
24
-                    { "no", "ml" },
25
-                    { "yes", "bvh" },
26
-                    { "OMG", "lnt" },
27
-                    { "mindblowingly", "nrmwy oldrm tob" },
28
-                    { "Testing, 1 2 3, testing.", "gvhgr mt123 gvhgr mt" },
29
-                    { "Truth is fiction.", "gifgs rhurx grlm" },
30
-                    { "The quick brown fox jumps over the lazy dog.", "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt" }
23
+            return Arrays.asList(new Object[][]{
24
+                    {"no", "ml"},
25
+                    {"yes", "bvh"},
26
+                    {"OMG", "lnt"},
27
+                    {"mindblowingly", "nrmwy oldrm tob"},
28
+                    {"Testing, 1 2 3, testing.", "gvhgr mt123 gvhgr mt"},
29
+                    {"Truth is fiction.", "gifgs rhurx grlm"},
30
+                    {"The quick brown fox jumps over the lazy dog.", "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt"}
31 31
             });
32 32
         }
33 33
 
@@ -37,9 +37,9 @@ public class AtbashTest {
37 37
         }
38 38
 
39 39
 
40
-    @Test
40
+        @Test
41 41
         public void test() {
42
-            assertEquals(ciphertext, Atbash.encode(plaintext));
42
+            assertEquals(ciphertext, new Atbash().encode(plaintext));
43 43
         }
44 44
     }
45 45
 
@@ -50,11 +50,11 @@ public class AtbashTest {
50 50
 
51 51
         @Parameters(name = "{index}: expected ciphertext \"{0}\" to decode to plaintext \"{1}\".")
52 52
         public static Collection<Object[]> data() {
53
-            return Arrays.asList(new Object[][] {
54
-                    { "vcvix rhn", "exercism" },
55
-                    { "zmlyh gzxov rhlug vmzhg vkkrm thglm v", "anobstacleisoftenasteppingstone" },
56
-                    { "gvhgr mt123 gvhgr mt", "testing123testing" },
57
-                    { "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt", "thequickbrownfoxjumpsoverthelazydog" }
53
+            return Arrays.asList(new Object[][]{
54
+                    {"vcvix rhn", "exercism"},
55
+                    {"zmlyh gzxov rhlug vmzhg vkkrm thglm v", "anobstacleisoftenasteppingstone"},
56
+                    {"gvhgr mt123 gvhgr mt", "testing123testing"},
57
+                    {"gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt", "thequickbrownfoxjumpsoverthelazydog"}
58 58
             });
59 59
         }
60 60
 
@@ -64,9 +64,9 @@ public class AtbashTest {
64 64
         }
65 65
 
66 66
         @Ignore
67
-    @Test
67
+        @Test
68 68
         public void test() {
69
-            assertEquals(plaintext, Atbash.decode(ciphertext));
69
+            assertEquals(plaintext, new Atbash().decode(ciphertext));
70 70
         }
71 71
     }
72 72
 }