|
|
@@ -8,138 +8,65 @@ import static org.junit.Assert.assertEquals;
|
|
8
|
8
|
|
|
9
|
9
|
public class CryptoSquareTest {
|
|
10
|
10
|
|
|
11
|
|
-
|
|
12
|
|
- @Test
|
|
13
|
|
- public void strangeCharactersAreStrippedDuringNormalization() {
|
|
14
|
|
- Crypto crypto = new Crypto("s#$%^&plunk");
|
|
15
|
|
- String expectedOutput = "splunk";
|
|
16
|
|
-
|
|
17
|
|
- assertEquals(expectedOutput, crypto.getNormalizedPlaintext());
|
|
18
|
|
- }
|
|
19
|
|
-
|
|
20
|
|
- @Ignore("Remove to run test")
|
|
21
|
|
- @Test
|
|
22
|
|
- public void lettersAreLowerCasedDuringNormalization() {
|
|
23
|
|
- Crypto crypto = new Crypto("WHOA HEY!");
|
|
24
|
|
- String expectedOutput = "whoahey";
|
|
25
|
|
-
|
|
26
|
|
- assertEquals(expectedOutput, crypto.getNormalizedPlaintext());
|
|
27
|
|
- }
|
|
28
|
|
-
|
|
29
|
|
- @Ignore("Remove to run test")
|
|
30
|
|
- @Test
|
|
31
|
|
- public void numbersAreKeptDuringNormalization() {
|
|
32
|
|
- Crypto crypto = new Crypto("1, 2, 3, GO!");
|
|
33
|
|
- String expectedOutput = "123go";
|
|
34
|
|
-
|
|
35
|
|
- assertEquals(expectedOutput, crypto.getNormalizedPlaintext());
|
|
36
|
|
- }
|
|
37
|
|
-
|
|
38
|
|
- @Ignore("Remove to run test")
|
|
39
|
|
- @Test
|
|
40
|
|
- public void smallestSquareSizeIs2() {
|
|
41
|
|
- Crypto crypto = new Crypto("1234");
|
|
42
|
|
- int expectedOutput = 2;
|
|
43
|
|
-
|
|
44
|
|
- assertEquals(expectedOutput, crypto.getSquareSize());
|
|
45
|
|
- }
|
|
46
|
|
-
|
|
47
|
|
- @Ignore("Remove to run test")
|
|
48
|
|
- @Test
|
|
49
|
|
- public void sizeOfTextWhoseLengthIsPerfectSquareIsItsSquareRoot() {
|
|
50
|
|
- Crypto crypto = new Crypto("123456789");
|
|
51
|
|
- int expectedOutput = 3;
|
|
52
|
|
-
|
|
53
|
|
- assertEquals(expectedOutput, crypto.getSquareSize());
|
|
54
|
|
- }
|
|
55
|
|
-
|
|
56
|
|
- @Ignore("Remove to run test")
|
|
57
|
|
- @Test
|
|
58
|
|
- public void sizeOfTextWhoseLengthIsNoPerfectSquareIsNextBiggestSquareRoot() {
|
|
59
|
|
- Crypto crypto = new Crypto("123456789abc");
|
|
60
|
|
- int expectedOutput = 4;
|
|
61
|
|
-
|
|
62
|
|
- assertEquals(expectedOutput, crypto.getSquareSize());
|
|
63
|
|
- }
|
|
64
|
|
-
|
|
65
|
|
- @Ignore("Remove to run test")
|
|
66
|
|
- @Test
|
|
67
|
|
- public void sizeIsDeterminedByNormalizedText() {
|
|
68
|
|
- Crypto crypto = new Crypto("Oh hey, this is nuts!");
|
|
69
|
|
- int expectedOutput = 4;
|
|
70
|
|
-
|
|
71
|
|
- assertEquals(expectedOutput, crypto.getSquareSize());
|
|
72
|
|
- }
|
|
73
|
|
-
|
|
74
|
|
- @Ignore("Remove to run test")
|
|
75
|
|
- @Test
|
|
76
|
|
- public void segmentsAreSplitBySquareSize() {
|
|
77
|
|
- Crypto crypto = new Crypto("Never vex thine heart with idle woes");
|
|
78
|
|
- List<String> expectedOutput = Arrays.asList(new String[]{"neverv", "exthin", "eheart", "withid", "lewoes"});
|
|
79
|
|
-
|
|
80
|
|
- assertEquals(expectedOutput, crypto.getPlaintextSegments());
|
|
81
|
|
- }
|
|
82
|
|
-
|
|
83
|
|
- @Ignore("Remove to run test")
|
|
84
|
11
|
@Test
|
|
85
|
|
- public void segmentsAreSplitBySquareSizeUntilTextRunsOut() {
|
|
86
|
|
- Crypto crypto = new Crypto("ZOMG! ZOMBIES!!!");
|
|
87
|
|
- List<String> expectedOutput = Arrays.asList(new String[]{"zomg", "zomb", "ies"});
|
|
|
12
|
+ public void emptyPlaintextResultsInEmptyCiphertext() {
|
|
|
13
|
+ CryptoSquare cryptoSquare = new CryptoSquare("");
|
|
|
14
|
+ String expectedOutput = "";
|
|
88
|
15
|
|
|
89
|
|
- assertEquals(expectedOutput, crypto.getPlaintextSegments());
|
|
|
16
|
+ assertEquals(expectedOutput, cryptoSquare.getCiphertext());
|
|
90
|
17
|
}
|
|
91
|
18
|
|
|
92
|
19
|
@Ignore("Remove to run test")
|
|
93
|
20
|
@Test
|
|
94
|
|
- public void cipherTextCombinesTextByColumn() {
|
|
95
|
|
- Crypto crypto = new Crypto("First, solve the problem. Then, write the code.");
|
|
96
|
|
- String expectedOutput = "foeewhilpmrervrticseohtottbeedshlnte";
|
|
|
21
|
+ public void lettersAreLowerCasedDuringEncryption() {
|
|
|
22
|
+ CryptoSquare cryptoSquare = new CryptoSquare("A");
|
|
|
23
|
+ String expectedOutput = "a";
|
|
97
|
24
|
|
|
98
|
|
- assertEquals(expectedOutput, crypto.getCipherText());
|
|
|
25
|
+ assertEquals(expectedOutput, cryptoSquare.getCiphertext());
|
|
99
|
26
|
}
|
|
100
|
27
|
|
|
101
|
28
|
@Ignore("Remove to run test")
|
|
102
|
29
|
@Test
|
|
103
|
|
- public void cipherTextSkipsCellsWithNoText() {
|
|
104
|
|
- Crypto crypto = new Crypto("Time is an illusion. Lunchtime doubly so.");
|
|
105
|
|
- String expectedOutput = "tasneyinicdsmiohooelntuillibsuuml";
|
|
|
30
|
+ public void spacesAreRemovedDuringEncryption() {
|
|
|
31
|
+ CryptoSquare cryptoSquare = new CryptoSquare(" b ");
|
|
|
32
|
+ String expectedOutput = "b";
|
|
106
|
33
|
|
|
107
|
|
- assertEquals(expectedOutput, crypto.getCipherText());
|
|
|
34
|
+ assertEquals(expectedOutput, cryptoSquare.getCiphertext());
|
|
108
|
35
|
}
|
|
109
|
36
|
|
|
110
|
37
|
@Ignore("Remove to run test")
|
|
111
|
38
|
@Test
|
|
112
|
|
- public void normalizedCipherTextIsSplitByHeightOfSquare() {
|
|
113
|
|
- Crypto crypto = new Crypto("Vampires are people too!");
|
|
114
|
|
- String expectedOutput = "vrel aepe mset paoo irpo";
|
|
|
39
|
+ public void punctuationIsRemovedDuringEncryption() {
|
|
|
40
|
+ CryptoSquare cryptoSquare = new CryptoSquare("@1,%!");
|
|
|
41
|
+ String expectedOutput = "1";
|
|
115
|
42
|
|
|
116
|
|
- assertEquals(expectedOutput, crypto.getNormalizedCipherText());
|
|
|
43
|
+ assertEquals(expectedOutput, cryptoSquare.getCiphertext());
|
|
117
|
44
|
}
|
|
118
|
45
|
|
|
119
|
46
|
@Ignore("Remove to run test")
|
|
120
|
47
|
@Test
|
|
121
|
|
- public void normalizedCipherNotExactlyDivisibleBy5SpillsIntoSmallerSegment() {
|
|
122
|
|
- Crypto crypto = new Crypto("Madness, and then illumination.");
|
|
123
|
|
- String expectedOutput = "msemo aanin dnin ndla etlt shui";
|
|
|
48
|
+ public void nineCharacterPlaintextResultsInThreeChunksOfThreeCharacters() {
|
|
|
49
|
+ CryptoSquare cryptoSquare = new CryptoSquare("This is fun!");
|
|
|
50
|
+ String expectedOutput = "tsf hiu isn";
|
|
124
|
51
|
|
|
125
|
|
- assertEquals(expectedOutput, crypto.getNormalizedCipherText());
|
|
|
52
|
+ assertEquals(expectedOutput, cryptoSquare.getCiphertext());
|
|
126
|
53
|
}
|
|
127
|
54
|
|
|
128
|
55
|
@Ignore("Remove to run test")
|
|
129
|
56
|
@Test
|
|
130
|
|
- public void normalizedCipherIsSplitIntoSegmentsOfCorrectSize() {
|
|
131
|
|
- Crypto crypto = new Crypto("If man was meant to stay on the ground god would have given us roots");
|
|
132
|
|
- String expectedOutput = "imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau";
|
|
|
57
|
+ public void eightCharacterPlaintextResultsInThreeChunksWithATrailingSpace() {
|
|
|
58
|
+ CryptoSquare cryptoSquare = new CryptoSquare("Chill out.");
|
|
|
59
|
+ String expectedOutput = "clu hlt io ";
|
|
133
|
60
|
|
|
134
|
|
- assertEquals(expectedOutput, crypto.getNormalizedCipherText());
|
|
|
61
|
+ assertEquals(expectedOutput, cryptoSquare.getCiphertext());
|
|
135
|
62
|
}
|
|
136
|
63
|
|
|
137
|
64
|
@Ignore("Remove to run test")
|
|
138
|
65
|
@Test
|
|
139
|
|
- public void normalizedCipherTextIsSplitIntoSegmentsOfCorrectSizeWithPunctuation() {
|
|
140
|
|
- Crypto crypto = new Crypto("Have a nice day. Feed the dog & chill out!");
|
|
141
|
|
- String expectedOutput = "hifei acedl veeol eddgo aatcu nyhht";
|
|
|
66
|
+ public void fiftyFourCharacterPlaintextResultsInSevenChunksWithTrailingSpaces() {
|
|
|
67
|
+ CryptoSquare cryptoSquare = new CryptoSquare("If man was meant to stay on the ground, god would have given us roots.");
|
|
|
68
|
+ String expectedOutput = "imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau ";
|
|
142
|
69
|
|
|
143
|
|
- assertEquals(expectedOutput, crypto.getNormalizedCipherText());
|
|
|
70
|
+ assertEquals(expectedOutput, cryptoSquare.getCiphertext());
|
|
144
|
71
|
}
|
|
145
|
72
|
}
|