lots of exercises in java... from https://github.com/exercism/java

SimpleCipherStepOneTest.java 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import org.junit.Before;
  2. import org.junit.Ignore;
  3. import org.junit.Test;
  4. import static org.junit.Assert.assertEquals;
  5. /**
  6. * Step 1: Make a simple shift cipher
  7. */
  8. public class SimpleCipherStepOneTest {
  9. private Cipher cipherWithDefaultKey;
  10. @Before
  11. public void setup() {
  12. cipherWithDefaultKey = new Cipher();
  13. }
  14. /**
  15. * Here we take advantage of the fact that plaintext of "aaa..." doesn't output the key. This is a critical problem
  16. * with shift ciphers, some characters will always output the key verbatim.
  17. */
  18. @Test
  19. public void cipherCanEncode() {
  20. String cipherText = cipherWithDefaultKey.getKey().substring(0, 10);
  21. assertEquals(cipherText, cipherWithDefaultKey.encode("aaaaaaaaaa"));
  22. }
  23. @Ignore("Remove to run test")
  24. @Test
  25. public void cipherCanDecode() {
  26. String cipherText = "aaaaaaaaaa";
  27. assertEquals(cipherText, cipherWithDefaultKey.decode(cipherWithDefaultKey.getKey().substring(0, 10)));
  28. }
  29. @Ignore("Remove to run test")
  30. @Test
  31. public void cipherIsReversible() {
  32. String plainText = "abcdefghij";
  33. assertEquals(plainText, cipherWithDefaultKey.decode(cipherWithDefaultKey.encode(plainText)));
  34. }
  35. }