random constructor not thoroughly tested
This is inspired by this chunk of code, which works until the last tests for student. Barron reported.
public SubstitutionCipher(String ciphertext) {
this.ciphertext = ciphertext;
HashMap<Character, Character> key = new HashMap<Character, Character>();
for (char c : ciphertext.toCharArray()) {
key.putIfAbsent(c, c);
}
this.key = key;
for (int i = 0; i < 10000; i++) {
this.key = randomSwap().key;
}
}
I think they can get away with this because the test case for randomswap has long ciphertext and thus most letters actually get added in. Could fix by making an explicit case with a smaller ciphertext such that randomswap should hit an NPE or something of the sort relatively quickly from trying to get a letter that never actually got added to the key.