mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-09 12:11:28 +08:00
Add unit tests for Caesar cipher (#3665)
Co-authored-by: Yang Libin <contact@yanglibin.info>
This commit is contained in:

committed by
GitHub

parent
7ef75980d5
commit
f8897f166d
47
src/test/java/com/thealgorithms/ciphers/CaesarTest.java
Normal file
47
src/test/java/com/thealgorithms/ciphers/CaesarTest.java
Normal 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]);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user