Add Junit tests for AffineCipher.java, improve documentation (#5598)

This commit is contained in:
Hardik Pawar
2024-10-07 20:38:55 +05:30
committed by GitHub
parent 99d7f80a61
commit f80850b244
3 changed files with 80 additions and 11 deletions

View File

@ -0,0 +1,39 @@
package com.thealgorithms.ciphers;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
public class AffineCipherTest {
@Test
public void testEncryptMessage() {
String plaintext = "AFFINE CIPHER";
char[] msg = plaintext.toCharArray();
String expectedCiphertext = "UBBAHK CAPJKX"; // Expected ciphertext after encryption
String actualCiphertext = AffineCipher.encryptMessage(msg);
assertEquals(expectedCiphertext, actualCiphertext, "The encryption result should match the expected ciphertext.");
}
@Test
public void testEncryptDecrypt() {
String plaintext = "HELLO WORLD";
char[] msg = plaintext.toCharArray();
String ciphertext = AffineCipher.encryptMessage(msg);
String decryptedText = AffineCipher.decryptCipher(ciphertext);
assertEquals(plaintext, decryptedText, "Decrypted text should match the original plaintext.");
}
@Test
public void testSpacesHandledInEncryption() {
String plaintext = "HELLO WORLD";
char[] msg = plaintext.toCharArray();
String expectedCiphertext = "JKZZY EYXZT";
String actualCiphertext = AffineCipher.encryptMessage(msg);
assertEquals(expectedCiphertext, actualCiphertext, "The encryption should handle spaces correctly.");
}
}