|
2 | 2 |
|
3 | 3 | import org.junit.jupiter.api.Test; |
4 | 4 |
|
| 5 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 6 | + |
5 | 7 | class CodeCrackerTest { |
6 | 8 |
|
7 | 9 | @Test |
8 | | - void should_doSomething_whenSomeCondition() { |
| 10 | + void should_returnLetterA_whenDecryptExclamationPoint() { |
| 11 | + // Arrange |
| 12 | + CodeCracker codeCracker = new CodeCracker(); |
| 13 | + |
| 14 | + // Act |
| 15 | + char decryptedExclamationPoint = codeCracker.decryptChar('!'); |
| 16 | + |
| 17 | + // Assert |
| 18 | + assertEquals('a', decryptedExclamationPoint); |
| 19 | + } |
| 20 | + |
| 21 | + @Test |
| 22 | + void should_returnLetterB_whenDecryptEndParenthesis() { |
| 23 | + // Arrange |
| 24 | + CodeCracker codeCracker = new CodeCracker(); |
| 25 | + |
| 26 | + // Act |
| 27 | + char decryptedEndParenthesis = codeCracker.decryptChar(')'); |
| 28 | + |
| 29 | + // Assert |
| 30 | + assertEquals('b', decryptedEndParenthesis); |
| 31 | + } |
| 32 | + |
| 33 | + @Test |
| 34 | + void should_returnWordAB_whenDecryptExclamationPointAndEndParenthesis() { |
| 35 | + // Arrange |
| 36 | + CodeCracker codeCracker = new CodeCracker(); |
| 37 | + |
| 38 | + // Act |
| 39 | + String decryptedString = codeCracker.decryptString("!)"); |
| 40 | + |
| 41 | + // Assert |
| 42 | + assertEquals("ab", decryptedString); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + void should_decryptWordHello() { |
| 47 | + // Arrange |
| 48 | + CodeCracker codeCracker = new CodeCracker(); |
| 49 | + |
| 50 | + // Act |
| 51 | + String decryptedString = codeCracker.decryptString("&£aad"); |
| 52 | + |
| 53 | + // Assert |
| 54 | + assertEquals("hello", decryptedString); |
| 55 | + } |
| 56 | + |
| 57 | + @Test |
| 58 | + void should_decryptWordWorld() { |
| 59 | + // Arrange |
| 60 | + CodeCracker codeCracker = new CodeCracker(); |
| 61 | + |
| 62 | + // Act |
| 63 | + String decryptedString = codeCracker.decryptString("ldga("); |
| 64 | + |
| 65 | + // Assert |
| 66 | + assertEquals("world", decryptedString); |
| 67 | + } |
| 68 | + |
| 69 | + @Test |
| 70 | + void should_returnExclamationPoint_whenEncryptLetterA() { |
| 71 | + // Arrange |
| 72 | + CodeCracker codeCracker = new CodeCracker(); |
| 73 | + |
| 74 | + // Act |
| 75 | + char encryptedLetterA = codeCracker.encryptLetter('a'); |
| 76 | + |
| 77 | + // Assert |
| 78 | + assertEquals('!', encryptedLetterA); |
| 79 | + } |
| 80 | + |
| 81 | + @Test |
| 82 | + void should_returnEndParenthesis_whenEncryptLetterB() { |
| 83 | + // Arrange |
| 84 | + CodeCracker codeCracker = new CodeCracker(); |
| 85 | + |
| 86 | + // Act |
| 87 | + char encryptedLetterB = codeCracker.encryptLetter('b'); |
| 88 | + |
| 89 | + // Assert |
| 90 | + assertEquals(')', encryptedLetterB); |
| 91 | + } |
| 92 | + |
| 93 | + @Test |
| 94 | + void should_returnExclamationPointAndEndParenthesis_whenEncryptAB() { |
| 95 | + // Arrange |
| 96 | + CodeCracker codeCracker = new CodeCracker(); |
| 97 | + |
| 98 | + // Act |
| 99 | + String encryptedAB = codeCracker.encryptString("ab"); |
| 100 | + |
| 101 | + // Assert |
| 102 | + assertEquals("!)", encryptedAB); |
| 103 | + } |
| 104 | + |
| 105 | + @Test |
| 106 | + void should_encryptWordHello() { |
| 107 | + // Arrange |
| 108 | + CodeCracker codeCracker = new CodeCracker(); |
| 109 | + |
| 110 | + // Act |
| 111 | + String encryptedHello = codeCracker.encryptString("hello"); |
| 112 | + |
| 113 | + // Assert |
| 114 | + assertEquals("&£aad", encryptedHello); |
| 115 | + } |
| 116 | + |
| 117 | + @Test |
| 118 | + void should_encryptWordWorld() { |
9 | 119 | // Arrange |
10 | 120 | CodeCracker codeCracker = new CodeCracker(); |
11 | 121 |
|
12 | 122 | // Act |
| 123 | + String encryptedWorld = codeCracker.encryptString("world"); |
| 124 | + |
13 | 125 | // Assert |
| 126 | + assertEquals("ldga(", encryptedWorld); |
14 | 127 | } |
15 | 128 |
|
| 129 | + @Test |
| 130 | + void should_handleUpperCaseInEncrypt() { |
| 131 | + // Arrange |
| 132 | + CodeCracker codeCracker = new CodeCracker(); |
| 133 | + |
| 134 | + // Act |
| 135 | + String encryptedHello = codeCracker.encryptString("Hello"); |
| 136 | + |
| 137 | + // Assert |
| 138 | + assertEquals("&£aad", encryptedHello); |
| 139 | + } |
| 140 | + |
| 141 | + @Test |
| 142 | + void should_handleUnknownCharacters() { |
| 143 | + // Arrange |
| 144 | + CodeCracker codeCracker = new CodeCracker(); |
| 145 | + |
| 146 | + // Act |
| 147 | + String encryptedHello = codeCracker.encryptString("Hello !"); |
| 148 | + |
| 149 | + // Assert |
| 150 | + assertEquals("&£aad", encryptedHello); |
| 151 | + } |
16 | 152 | } |
0 commit comments