Skip to content

Commit 54d6f79

Browse files
authored
Add SimpleSubstitutionCipherTest (#3857)
1 parent b14f550 commit 54d6f79

File tree

2 files changed

+48
-12
lines changed

2 files changed

+48
-12
lines changed

src/main/java/com/thealgorithms/ciphers/SimpleSubstitutionCipher.java

-12
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,4 @@ public static String decode(String encryptedMessage, String cipherSmall) {
8080

8181
return decoded.toString();
8282
}
83-
84-
/**
85-
* TODO remove main and make JUnit Testing
86-
*/
87-
public static void main(String[] args) {
88-
String a = encode(
89-
"defend the east wall of the castle",
90-
"phqgiumeaylnofdxjkrcvstzwb"
91-
);
92-
String b = decode(a, "phqgiumeaylnofdxjkrcvstzwb");
93-
System.out.println(b);
94-
}
9583
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.thealgorithms.ciphers;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.assertEquals;
6+
7+
public class SimpleSubstitutionCipherTest {
8+
9+
@Test
10+
void testEncode() {
11+
// Given
12+
String message = "HELLOWORLD";
13+
String key = "phqgiumeaylnofdxjkrcvstzwb";
14+
15+
// When
16+
String actual = SimpleSubstitutionCipher.encode(message, key);
17+
18+
// Then
19+
assertEquals("EINNDTDKNG", actual);
20+
}
21+
22+
@Test
23+
void testDecode() {
24+
// Given
25+
String message = "EINNDTDKNG";
26+
String key = "phqgiumeaylnofdxjkrcvstzwb";
27+
28+
// When
29+
String actual = SimpleSubstitutionCipher.decode(message, key);
30+
31+
// Then
32+
assertEquals("HELLOWORLD", actual);
33+
}
34+
35+
@Test
36+
void testIsTextTheSameAfterEncodeAndDecode() {
37+
// Given
38+
String text = "HELLOWORLD";
39+
String key = "phqgiumeaylnofdxjkrcvstzwb";
40+
41+
// When
42+
String encodedText = SimpleSubstitutionCipher.encode(text, key);
43+
String decodedText = SimpleSubstitutionCipher.decode(encodedText, key);
44+
45+
// Then
46+
assertEquals(text, decodedText);
47+
}
48+
}

0 commit comments

Comments
 (0)