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

Merge pull request #64 from jmluy/crypto-square

crypto-square: Fix invalid tests
John Ryan 11 лет назад
Родитель
Сommit
49bb252b1e

+ 8
- 6
crypto-square/src/example/java/Crypto.java Просмотреть файл

@@ -51,6 +51,10 @@ public class Crypto {
51 51
     }
52 52
 
53 53
     public String getCipherText() {
54
+        return getNormalizedCipherText().replaceAll("\\s", "");
55
+    }
56
+
57
+    public String getNormalizedCipherText() {
54 58
         StringBuilder cipherText = new StringBuilder(normalizedPlaintext.length());
55 59
 
56 60
         for (int index = 0; index < squareSize; index++) {
@@ -59,14 +63,12 @@ public class Crypto {
59 63
                     cipherText.append(segment.charAt(index));
60 64
                 }
61 65
             }
66
+
67
+            if (index < squareSize - 1) {
68
+                cipherText.append(" ");
69
+            }
62 70
         }
63 71
 
64 72
         return cipherText.toString();
65 73
     }
66
-
67
-    public String getNormalizedCipherText() {
68
-        String cipher = getCipherText();
69
-
70
-        return String.join(" ", getSegmentText(cipher, squareSize - 1));
71
-    }
72 74
 }

+ 2
- 2
crypto-square/src/test/java/CryptoSquareTest.java Просмотреть файл

@@ -106,7 +106,7 @@ public class CryptoSquareTest {
106 106
     @Test
107 107
     public void normalizedCipherNotExactlyDivisibleBy5SpillsIntoSmallerSegment() {
108 108
         Crypto crypto = new Crypto("Madness, and then illumination.");
109
-        String expectedOutput = "msemo aanin dninn dlaet ltshu i";
109
+        String expectedOutput = "msemo aanin dnin ndla etlt shui";
110 110
 
111 111
         assertEquals(expectedOutput, crypto.getNormalizedCipherText());
112 112
     }
@@ -114,7 +114,7 @@ public class CryptoSquareTest {
114 114
     @Test
115 115
     public void normalizedCipherIsSplitIntoSegmentsOfCorrectSize() {
116 116
         Crypto crypto = new Crypto("If man was meant to stay on the ground god would have given us roots");
117
-        String expectedOutput = "imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghns seoau";
117
+        String expectedOutput = "imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau";
118 118
 
119 119
         assertEquals(expectedOutput, crypto.getNormalizedCipherText());
120 120
     }