Skip to content

Commit afdf7e4

Browse files
authored
Create MonoAlphabeticTest.java
1 parent db4d4dc commit afdf7e4

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.thealgorithms.ciphers;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import org.junit.jupiter.api.BeforeEach;
5+
import org.junit.jupiter.api.Test;
6+
7+
public class MonoAlphabeticTest {
8+
private MonoAlphabetic monoAlphabetic;
9+
10+
@BeforeEach
11+
public void setUp() {
12+
// Initialize the MonoAlphabetic cipher with a sample key
13+
String key = "QWERTYUIOPASDFGHJKLZXCVBNM"; // Example key
14+
monoAlphabetic = new MonoAlphabetic(key);
15+
}
16+
17+
@Test
18+
public void testEncrypt() {
19+
String plaintext = "HELLO";
20+
String expectedCiphertext = "ITSSG"; // Expected result based on the key
21+
String actualCiphertext = monoAlphabetic.encrypt(plaintext);
22+
23+
assertEquals(expectedCiphertext, actualCiphertext, "Encryption should match the expected ciphertext.");
24+
}
25+
26+
@Test
27+
public void testDecrypt() {
28+
String ciphertext = "ITSSG";
29+
String expectedPlaintext = "HELLO"; // Expected result based on the key
30+
String actualPlaintext = monoAlphabetic.decrypt(ciphertext);
31+
32+
assertEquals(expectedPlaintext, actualPlaintext, "Decryption should match the expected plaintext.");
33+
}
34+
35+
@Test
36+
public void testEncryptAndDecrypt() {
37+
String plaintext = "HELLO";
38+
String ciphertext = monoAlphabetic.encrypt(plaintext);
39+
String decryptedText = monoAlphabetic.decrypt(ciphertext);
40+
41+
assertEquals(plaintext, decryptedText, "Decrypting the ciphertext should return the original plaintext.");
42+
}
43+
44+
@Test
45+
public void testEncryptWithSpecialCharacters() {
46+
String plaintext = "HELLO, WORLD!";
47+
String expectedCiphertext = "ITSSG, GQHSG!";
48+
String actualCiphertext = monoAlphabetic.encrypt(plaintext);
49+
50+
assertEquals(expectedCiphertext, actualCiphertext, "Encryption should correctly handle special characters.");
51+
}
52+
53+
@Test
54+
public void testDecryptWithSpecialCharacters() {
55+
String ciphertext = "ITSSG, GQHSG!";
56+
String expectedPlaintext = "HELLO, WORLD!";
57+
String actualPlaintext = monoAlphabetic.decrypt(ciphertext);
58+
59+
assertEquals(expectedPlaintext, actualPlaintext, "Decryption should correctly handle special characters.");
60+
}
61+
}

0 commit comments

Comments
 (0)