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

SubstitutionCipherTest.java 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import org.junit.Before;
  2. import org.junit.Test;
  3. import static org.junit.Assert.assertEquals;
  4. public class SubstitutionCipherTest {
  5. private static final String KEY = "abcdefghij";
  6. private Cipher cipher;
  7. @Before
  8. public void setup() {
  9. this.cipher = new Cipher(KEY);
  10. }
  11. @Test
  12. public void cipherKeepsTheSubmittedKey() {
  13. assertEquals(KEY, cipher.getKey());
  14. }
  15. @Test
  16. public void cipherCanEncodeWithGivenKey() {
  17. String expectedOutput = "abcdefghij";
  18. assertEquals(expectedOutput, cipher.encode("aaaaaaaaaa"));
  19. }
  20. @Test
  21. public void cipherCanDecodeWithGivenKey() {
  22. String expectedOutput = "aaaaaaaaaa";
  23. assertEquals(expectedOutput, cipher.decode("abcdefghij"));
  24. }
  25. @Test
  26. public void cipherIsReversibleGivenKey() {
  27. String plainText = "abcdefghij";
  28. assertEquals(plainText, cipher.decode(cipher.encode("abcdefghij")));
  29. }
  30. @Test
  31. public void cipherCanDoubleShiftEncode() {
  32. String plainText = "iamapandabear";
  33. String expectedOutput = "qayaeaagaciai";
  34. assertEquals(expectedOutput, new Cipher(plainText).encode(plainText));
  35. }
  36. @Test
  37. public void cipherCanWrapEncode() {
  38. String expectedOutput = "zabcdefghi";
  39. assertEquals(expectedOutput, cipher.encode("zzzzzzzzzz"));
  40. }
  41. @Test
  42. public void cipherCanEncodeMessageThatIsShorterThanTheKey() {
  43. String expectedOutput = "abcde";
  44. assertEquals(expectedOutput, cipher.encode("aaaaa"));
  45. }
  46. @Test
  47. public void cipherCanDecodeMessageThatIsShorterThanTheKey() {
  48. String expectedOutput = "aaaaa";
  49. assertEquals(expectedOutput, cipher.decode("abcde"));
  50. }
  51. }