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

SubstitutionCipherTest.java 1.8KB

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