mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-07 09:45:04 +08:00
Add Junit tests for AffineCipher.java
, improve documentation (#5598)
This commit is contained in:
@ -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.");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user