-
Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathCaesarTest.java
46 lines (33 loc) · 1.02 KB
/
CaesarTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.thealgorithms.ciphers;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
class CaesarTest {
Caesar caesar = new Caesar();
@Test
void caesarEncryptTest() {
// given
String textToEncrypt = "Encrypt this text";
// when
String cipherText = caesar.encode(textToEncrypt, 5);
// then
assertEquals("Jshwduy ymnx yjcy", cipherText);
}
@Test
void caesarDecryptTest() {
// given
String encryptedText = "Jshwduy ymnx yjcy";
// when
String cipherText = caesar.decode(encryptedText, 5);
// then
assertEquals("Encrypt this text", cipherText);
}
@Test
void caesarBruteForce() {
// given
String encryptedText = "Jshwduy ymnx yjcy";
// when
String[] allPossibleAnswers = caesar.bruteforce(encryptedText);
assertEquals(27, allPossibleAnswers.length);
assertEquals("Encrypt this text", allPossibleAnswers[5]);
}
}