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

CryptoSquareTest.java 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import org.junit.Test;
  2. import org.junit.Ignore;
  3. import java.util.Arrays;
  4. import java.util.List;
  5. import static org.junit.Assert.assertEquals;
  6. public class CryptoSquareTest {
  7. @Test
  8. public void strangeCharactersAreStrippedDuringNormalization() {
  9. Crypto crypto = new Crypto("s#$%^&plunk");
  10. String expectedOutput = "splunk";
  11. assertEquals(expectedOutput, crypto.getNormalizedPlaintext());
  12. }
  13. @Ignore("Remove to run test")
  14. @Test
  15. public void lettersAreLowerCasedDuringNormalization() {
  16. Crypto crypto = new Crypto("WHOA HEY!");
  17. String expectedOutput = "whoahey";
  18. assertEquals(expectedOutput, crypto.getNormalizedPlaintext());
  19. }
  20. @Ignore("Remove to run test")
  21. @Test
  22. public void numbersAreKeptDuringNormalization() {
  23. Crypto crypto = new Crypto("1, 2, 3, GO!");
  24. String expectedOutput = "123go";
  25. assertEquals(expectedOutput, crypto.getNormalizedPlaintext());
  26. }
  27. @Ignore("Remove to run test")
  28. @Test
  29. public void smallestSquareSizeIs2() {
  30. Crypto crypto = new Crypto("1234");
  31. int expectedOutput = 2;
  32. assertEquals(expectedOutput, crypto.getSquareSize());
  33. }
  34. @Ignore("Remove to run test")
  35. @Test
  36. public void sizeOfTextWhoseLengthIsPerfectSquareIsItsSquareRoot() {
  37. Crypto crypto = new Crypto("123456789");
  38. int expectedOutput = 3;
  39. assertEquals(expectedOutput, crypto.getSquareSize());
  40. }
  41. @Ignore("Remove to run test")
  42. @Test
  43. public void sizeOfTextWhoseLengthIsNoPerfectSquareIsNextBiggestSquareRoot() {
  44. Crypto crypto = new Crypto("123456789abc");
  45. int expectedOutput = 4;
  46. assertEquals(expectedOutput, crypto.getSquareSize());
  47. }
  48. @Ignore("Remove to run test")
  49. @Test
  50. public void sizeIsDeterminedByNormalizedText() {
  51. Crypto crypto = new Crypto("Oh hey, this is nuts!");
  52. int expectedOutput = 4;
  53. assertEquals(expectedOutput, crypto.getSquareSize());
  54. }
  55. @Ignore("Remove to run test")
  56. @Test
  57. public void segmentsAreSplitBySquareSize() {
  58. Crypto crypto = new Crypto("Never vex thine heart with idle woes");
  59. List<String> expectedOutput = Arrays.asList(new String[]{"neverv", "exthin", "eheart", "withid", "lewoes"});
  60. assertEquals(expectedOutput, crypto.getPlaintextSegments());
  61. }
  62. @Ignore("Remove to run test")
  63. @Test
  64. public void segmentsAreSplitBySquareSizeUntilTextRunsOut() {
  65. Crypto crypto = new Crypto("ZOMG! ZOMBIES!!!");
  66. List<String> expectedOutput = Arrays.asList(new String[]{"zomg", "zomb", "ies"});
  67. assertEquals(expectedOutput, crypto.getPlaintextSegments());
  68. }
  69. @Ignore("Remove to run test")
  70. @Test
  71. public void cipherTextCombinesTextByColumn() {
  72. Crypto crypto = new Crypto("First, solve the problem. Then, write the code.");
  73. String expectedOutput = "foeewhilpmrervrticseohtottbeedshlnte";
  74. assertEquals(expectedOutput, crypto.getCipherText());
  75. }
  76. @Ignore("Remove to run test")
  77. @Test
  78. public void cipherTextSkipsCellsWithNoText() {
  79. Crypto crypto = new Crypto("Time is an illusion. Lunchtime doubly so.");
  80. String expectedOutput = "tasneyinicdsmiohooelntuillibsuuml";
  81. assertEquals(expectedOutput, crypto.getCipherText());
  82. }
  83. @Ignore("Remove to run test")
  84. @Test
  85. public void normalizedCipherTextIsSplitByHeightOfSquare() {
  86. Crypto crypto = new Crypto("Vampires are people too!");
  87. String expectedOutput = "vrel aepe mset paoo irpo";
  88. assertEquals(expectedOutput, crypto.getNormalizedCipherText());
  89. }
  90. @Ignore("Remove to run test")
  91. @Test
  92. public void normalizedCipherNotExactlyDivisibleBy5SpillsIntoSmallerSegment() {
  93. Crypto crypto = new Crypto("Madness, and then illumination.");
  94. String expectedOutput = "msemo aanin dnin ndla etlt shui";
  95. assertEquals(expectedOutput, crypto.getNormalizedCipherText());
  96. }
  97. @Ignore("Remove to run test")
  98. @Test
  99. public void normalizedCipherIsSplitIntoSegmentsOfCorrectSize() {
  100. Crypto crypto = new Crypto("If man was meant to stay on the ground god would have given us roots");
  101. String expectedOutput = "imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau";
  102. assertEquals(expectedOutput, crypto.getNormalizedCipherText());
  103. }
  104. @Ignore("Remove to run test")
  105. @Test
  106. public void normalizedCipherTextIsSplitIntoSegmentsOfCorrectSizeWithPunctuation() {
  107. Crypto crypto = new Crypto("Have a nice day. Feed the dog & chill out!");
  108. String expectedOutput = "hifei acedl veeol eddgo aatcu nyhht";
  109. assertEquals(expectedOutput, crypto.getNormalizedCipherText());
  110. }
  111. }