|
| 1 | +import org.junit.Before; |
| 2 | +import org.junit.Ignore; |
| 3 | +import org.junit.Rule; |
| 4 | +import org.junit.Test; |
| 5 | +import org.junit.rules.ExpectedException; |
| 6 | + |
| 7 | +import static org.junit.Assert.assertEquals; |
| 8 | + |
| 9 | +public class AffineCipherTest { |
| 10 | + |
| 11 | + private AffineCipher affineCipher; |
| 12 | + |
| 13 | + @Before |
| 14 | + public void genAffineCipher() { |
| 15 | + affineCipher = new AffineCipher(); |
| 16 | + } |
| 17 | + |
| 18 | + @Rule |
| 19 | + public ExpectedException expectedException = ExpectedException.none(); |
| 20 | + |
| 21 | + @Test |
| 22 | + public void testEncodeYes() { |
| 23 | + assertEquals("xbt", affineCipher.encode("yes", 5, 7)); |
| 24 | + } |
| 25 | + |
| 26 | + @Ignore("Remove to run test") |
| 27 | + @Test |
| 28 | + public void testEncodeNo() { |
| 29 | + assertEquals("fu", affineCipher.encode("no", 15, 18)); |
| 30 | + } |
| 31 | + |
| 32 | + |
| 33 | + @Ignore("Remove to run test") |
| 34 | + @Test |
| 35 | + public void testEncodeOMG() { |
| 36 | + assertEquals("lvz", affineCipher.encode("OMG", 21, 3)); |
| 37 | + } |
| 38 | + |
| 39 | + @Ignore("Remove to run test") |
| 40 | + @Test |
| 41 | + public void testEncodeO_M_G() { |
| 42 | + assertEquals("hjp", affineCipher.encode("O M G", 25, 47)); |
| 43 | + } |
| 44 | + |
| 45 | + @Ignore("Remove to run test") |
| 46 | + @Test |
| 47 | + public void testEncodeMindBlowingly() { |
| 48 | + assertEquals("rzcwa gnxzc dgt", affineCipher.encode("mindblowingly", 11, 15)); |
| 49 | + } |
| 50 | + |
| 51 | + @Ignore("Remove to run test") |
| 52 | + @Test |
| 53 | + public void testEncodeNumbers() { |
| 54 | + assertEquals("jqgjc rw123 jqgjc rw", |
| 55 | + affineCipher.encode("Testing,1 2 3, testing.", 3, 4)); |
| 56 | + } |
| 57 | + |
| 58 | + @Ignore("Remove to run test") |
| 59 | + @Test |
| 60 | + public void testEncodeDeepThought() { |
| 61 | + assertEquals("iynia fdqfb ifje", |
| 62 | + affineCipher.encode("Truth is fiction.", 5, 17)); |
| 63 | + } |
| 64 | + |
| 65 | + @Ignore("Remove to run test") |
| 66 | + @Test |
| 67 | + public void testEncodeAllTheLetters() { |
| 68 | + assertEquals("swxtj npvyk lruol iejdc blaxk swxmh qzglf", |
| 69 | + affineCipher.encode("The quick brown fox jumps over the lazy dog.", 17, 33)); |
| 70 | + } |
| 71 | + |
| 72 | + @Ignore("Remove to run test") |
| 73 | + @Test |
| 74 | + public void testEncodeThrowsMeaningfulException() throws IllegalArgumentException { |
| 75 | + expectedException.expect(IllegalArgumentException.class); |
| 76 | + expectedException.expectMessage("Error: keyA and alphabet size must be coprime."); |
| 77 | + |
| 78 | + affineCipher.encode("This is a test", 6, 17); |
| 79 | + } |
| 80 | + |
| 81 | + @Ignore("Remove to run test") |
| 82 | + @Test |
| 83 | + public void testDecodeExercism() { |
| 84 | + assertEquals("exercism", affineCipher.decode("tytgn fjr", 3, 7)); |
| 85 | + } |
| 86 | + |
| 87 | + @Ignore("Remove to run test") |
| 88 | + @Test |
| 89 | + public void testDecodeSentence() { |
| 90 | + assertEquals("anobstacleisoftenasteppingstone", |
| 91 | + affineCipher.decode("qdwju nqcro muwhn odqun oppmd aunwd o", 19, 16)); |
| 92 | + } |
| 93 | + |
| 94 | + @Ignore("Remove to run test") |
| 95 | + @Test |
| 96 | + public void testDecodeNumbers() { |
| 97 | + assertEquals("testing123testing", affineCipher.decode("odpoz ub123 odpoz ub", 25, 7)); |
| 98 | + } |
| 99 | + |
| 100 | + @Ignore("Remove to run test") |
| 101 | + @Test |
| 102 | + public void testDecodeAllTheLetters() { |
| 103 | + assertEquals("thequickbrownfoxjumpsoverthelazydog", |
| 104 | + affineCipher.decode("swxtj npvyk lruol iejdc blaxk swxmh qzglf", 17, 33)); |
| 105 | + } |
| 106 | + |
| 107 | + @Ignore("Remove to run test") |
| 108 | + @Test |
| 109 | + public void testDecodeWithNoSpaces() { |
| 110 | + assertEquals("thequickbrownfoxjumpsoverthelazydog", |
| 111 | + affineCipher.decode("swxtjnpvyklruoliejdcblaxkswxmhqzglf", 17, 33)); |
| 112 | + } |
| 113 | + |
| 114 | + @Ignore("Remove to run test") |
| 115 | + @Test |
| 116 | + public void testDecodeWithTooManySpaces() { |
| 117 | + assertEquals("jollygreengiant", affineCipher.decode("vszzm cly yd cg qdp", 15, 16)); |
| 118 | + } |
| 119 | + |
| 120 | + @Ignore("Remove to run test") |
| 121 | + @Test |
| 122 | + public void testDecodeThrowsMeaningfulException() { |
| 123 | + expectedException.expect(IllegalArgumentException.class); |
| 124 | + expectedException.expectMessage("Error: keyA and alphabet size must be coprime."); |
| 125 | + |
| 126 | + affineCipher.decode("Test", 13, 5); |
| 127 | + } |
| 128 | + |
| 129 | +} |
0 commit comments