Skip to content

Commit a8f58f6

Browse files
authored
Update MonoAlphabeticTest.java
1 parent cdb0c91 commit a8f58f6

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

src/test/java/com/thealgorithms/ciphers/MonoAlphabeticTest.java

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,20 @@
99

1010
public class MonoAlphabeticTest {
1111

12-
private static final String KEY = "MNBVCXZLKJHGFDSAPOIUYTREWQ";
13-
14-
// Test for encryption
12+
// Test for both encryption and decryption with different keys
1513
@ParameterizedTest
16-
@MethodSource("provideEncryptionData")
17-
public void testEncrypt(String data, String key, String expected) {
18-
assertEquals(expected, MonoAlphabetic.encrypt(data, key));
19-
}
20-
21-
// Test for decryption
22-
@ParameterizedTest
23-
@MethodSource("provideDecryptionData")
24-
public void testDecrypt(String data, String key, String expected) {
25-
assertEquals(expected, MonoAlphabetic.decrypt(data, key));
26-
}
14+
@MethodSource("provideTestData")
15+
public void testEncryptDecrypt(String plainText, String key, String encryptedText) {
16+
// Test encryption
17+
assertEquals(encryptedText, MonoAlphabetic.encrypt(plainText, key));
2718

28-
// Provide test data for encryption
29-
private static Stream<Arguments> provideEncryptionData() {
30-
return Stream.of(Arguments.of("HELLO", KEY, "LCGGS"), Arguments.of("JAVA", KEY, "JMTM"));
19+
// Test decryption
20+
assertEquals(plainText, MonoAlphabetic.decrypt(encryptedText, key));
3121
}
3222

33-
// Provide test data for decryption
34-
private static Stream<Arguments> provideDecryptionData() {
35-
return Stream.of(Arguments.of("LCGGS", KEY, "HELLO"), Arguments.of("JMTM", KEY, "JAVA"));
23+
// Provide test data for both encryption and decryption
24+
private static Stream<Arguments> provideTestData() {
25+
return Stream.of(
26+
Arguments.of("HELLO", "MNBVCXZLKJHGFDSAPOIUYTREWQ", "LCGGS"), Arguments.of("JAVA", "MNBVCXZLKJHGFDSAPOIUYTREWQ", "JMTM"), Arguments.of("HELLO", "QWERTYUIOPLKJHGFDSAZXCVBNM", "UJJYU"), Arguments.of("JAVA", "QWERTYUIOPLKJHGFDSAZXCVBNM", "KZHS"));
3627
}
3728
}

0 commit comments

Comments
 (0)