Skip to content

Commit bf0a20a

Browse files
authored
[simple-cipher] Fix outdated reference to SimpleCipherStepThreeTest (#2523)
* [simple-cipher] Fix outdated reference to SimpleCipherStepThreeTest This test file was removed years ago in #1639, but the instructions still mention it (which caused me, at least, quite a bit of confusion since I thought I had deleted something erroneously). This fixes the documentation to remove the reference to Step Three. If the intent was to never have deleted SimpleCipherStepThreeTest.java in the first place, let me know and I'll amend the PR to that. * [simple-cipher] Fix incorrect reference to test file in instructions. This revealed that actually there's a typo in the class name itself. Determining next whether to fix that or leave it be. * [simple-cipher] Combine the two test classes into a single suite * [simple-cipher] Fix checkstyle failures * [simple-cipher] Remove outdated test files from .meta/config.json * [simple-cipher] Use Enclosed JUnit runner for inner test classes
1 parent f560ec7 commit bf0a20a

File tree

5 files changed

+114
-124
lines changed

5 files changed

+114
-124
lines changed

exercises/practice/simple-cipher/.docs/instructions.append.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

exercises/practice/simple-cipher/.meta/config.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
"src/main/java/Cipher.java"
2626
],
2727
"test": [
28-
"src/test/java/SimpleCipherStepTwoSubsitutionTest.java",
29-
"src/test/java/SimpleCipherStepOneTest.java"
28+
"src/test/java/SimpleCipherTest.java"
3029
],
3130
"example": [
3231
".meta/src/reference/java/Cipher.java"

exercises/practice/simple-cipher/src/test/java/SimpleCipherStepOneTest.java

Lines changed: 0 additions & 48 deletions
This file was deleted.

exercises/practice/simple-cipher/src/test/java/SimpleCipherStepTwoSubsitutionTest.java

Lines changed: 0 additions & 66 deletions
This file was deleted.
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import org.junit.Before;
2+
import org.junit.Ignore;
3+
import org.junit.Test;
4+
import org.junit.experimental.runners.Enclosed;
5+
import org.junit.runner.RunWith;
6+
7+
import static org.assertj.core.api.Assertions.assertThat;
8+
9+
10+
@RunWith(Enclosed.class)
11+
public class SimpleCipherTest {
12+
public static class RandomKeyCipher {
13+
private Cipher cipherWithDefaultKey;
14+
15+
@Before
16+
public void setup() {
17+
cipherWithDefaultKey = new Cipher();
18+
}
19+
20+
/**
21+
* Here we take advantage of the fact that plaintext of "aaa..." doesn't output the key. This is a critical
22+
* problem with shift ciphers, some characters will always output the key verbatim.
23+
*/
24+
@Test
25+
public void cipherCanEncode() {
26+
String plainText = "aaaaaaaaaa";
27+
String cipherText = cipherWithDefaultKey.getKey().substring(0, 10);
28+
assertThat(cipherWithDefaultKey.encode(plainText)).isEqualTo(cipherText);
29+
}
30+
31+
@Ignore("Remove to run test")
32+
@Test
33+
public void cipherCanDecode() {
34+
String cipherText = "aaaaaaaaaa";
35+
assertThat(cipherWithDefaultKey.decode(cipherWithDefaultKey.getKey().substring(0, 10)))
36+
.isEqualTo(cipherText);
37+
}
38+
39+
@Ignore("Remove to run test")
40+
@Test
41+
public void cipherIsReversible() {
42+
String plainText = "abcdefghij";
43+
assertThat(cipherWithDefaultKey.decode(cipherWithDefaultKey.encode(plainText))).isEqualTo(plainText);
44+
}
45+
46+
@Ignore("Remove to run test")
47+
@Test
48+
public void keyIsLowercaseLetters() {
49+
assertThat(cipherWithDefaultKey.getKey()).matches("^[a-z]+$");
50+
}
51+
}
52+
53+
public static class SubstitutionCipher {
54+
private Cipher cipherWithDefaultKey = new Cipher("abcdefghij");
55+
56+
@Ignore("Remove to run test")
57+
@Test
58+
public void cipherCanEncode() {
59+
String plainText = "aaaaaaaaaa";
60+
String cipherText = "abcdefghij";
61+
assertThat(cipherWithDefaultKey.encode(plainText)).isEqualTo(cipherText);
62+
}
63+
64+
@Ignore("Remove to run test")
65+
@Test
66+
public void cipherCanDecode() {
67+
String plainText = "abcdefghij";
68+
String cipherText = "aaaaaaaaaa";
69+
assertThat(cipherWithDefaultKey.decode(plainText)).isEqualTo(cipherText);
70+
}
71+
72+
@Ignore("Remove to run test")
73+
@Test
74+
public void cipherIsReversibleGivenKey() {
75+
String plainText = "abcdefghij";
76+
assertThat(cipherWithDefaultKey.decode(cipherWithDefaultKey.encode(plainText))).isEqualTo(plainText);
77+
}
78+
79+
@Ignore("Remove to run test")
80+
@Test
81+
public void cipherCanDoubleShiftEncode() {
82+
String plainText = "iamapandabear";
83+
String cipherText = "qayaeaagaciai";
84+
assertThat(new Cipher(plainText).encode(plainText)).isEqualTo(cipherText);
85+
}
86+
87+
@Ignore("Remove to run test")
88+
@Test
89+
public void cipherCanWrapEncode() {
90+
String plainText = "zzzzzzzzzz";
91+
String cipherText = "zabcdefghi";
92+
assertThat(cipherWithDefaultKey.encode(plainText)).isEqualTo(cipherText);
93+
}
94+
95+
@Ignore("Remove to run test")
96+
@Test
97+
public void cipherCanWrapDecode() {
98+
String plainText = "zabcdefghi";
99+
String cipherText = "zzzzzzzzzz";
100+
assertThat(cipherWithDefaultKey.decode(plainText)).isEqualTo(cipherText);
101+
}
102+
103+
@Ignore("Remove to run test")
104+
@Test
105+
public void cipherMessageLongerThanKey() {
106+
String plainText = "iamapandabear";
107+
String key = "abc";
108+
String cipherText = "iboaqcnecbfcr";
109+
assertThat(new Cipher(key).encode(plainText)).isEqualTo(cipherText);
110+
}
111+
}
112+
}
113+

0 commit comments

Comments
 (0)