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

crypto-square: Fix invalid tests which were chunked on the square size instead of the actual order.

John Michael Luy 11 лет назад
Родитель
Сommit
8fed213c4f
2 измененных файлов: 10 добавлений и 8 удалений
  1. 8
    6
      crypto-square/src/example/java/Crypto.java
  2. 2
    2
      crypto-square/src/test/java/CryptoSquareTest.java

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

51
     }
51
     }
52
 
52
 
53
     public String getCipherText() {
53
     public String getCipherText() {
54
+        return getNormalizedCipherText().replaceAll("\\s", "");
55
+    }
56
+
57
+    public String getNormalizedCipherText() {
54
         StringBuilder cipherText = new StringBuilder(normalizedPlaintext.length());
58
         StringBuilder cipherText = new StringBuilder(normalizedPlaintext.length());
55
 
59
 
56
         for (int index = 0; index < squareSize; index++) {
60
         for (int index = 0; index < squareSize; index++) {
59
                     cipherText.append(segment.charAt(index));
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
         return cipherText.toString();
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
     @Test
106
     @Test
107
     public void normalizedCipherNotExactlyDivisibleBy5SpillsIntoSmallerSegment() {
107
     public void normalizedCipherNotExactlyDivisibleBy5SpillsIntoSmallerSegment() {
108
         Crypto crypto = new Crypto("Madness, and then illumination.");
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
         assertEquals(expectedOutput, crypto.getNormalizedCipherText());
111
         assertEquals(expectedOutput, crypto.getNormalizedCipherText());
112
     }
112
     }
114
     @Test
114
     @Test
115
     public void normalizedCipherIsSplitIntoSegmentsOfCorrectSize() {
115
     public void normalizedCipherIsSplitIntoSegmentsOfCorrectSize() {
116
         Crypto crypto = new Crypto("If man was meant to stay on the ground god would have given us roots");
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
         assertEquals(expectedOutput, crypto.getNormalizedCipherText());
119
         assertEquals(expectedOutput, crypto.getNormalizedCipherText());
120
     }
120
     }