Add unit tests for Caesar cipher (#3665)

Co-authored-by: Yang Libin <contact@yanglibin.info>
This commit is contained in:
Alexandre Velloso
2022-10-26 02:01:35 +01:00
committed by GitHub
parent 7ef75980d5
commit f8897f166d
2 changed files with 56 additions and 54 deletions

View File

@ -0,0 +1,47 @@
package com.thealgorithms.ciphers;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
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]);
}
}