Files
2024-05-05 20:48:56 +02:00

47 lines
1.0 KiB
Java

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]);
}
}