diff --git a/src/main/java/com/thealgorithms/ciphers/SimpleSubstitutionCipher.java b/src/main/java/com/thealgorithms/ciphers/SimpleSubstitutionCipher.java index 4795638d38f3..6ce3c564abc7 100644 --- a/src/main/java/com/thealgorithms/ciphers/SimpleSubstitutionCipher.java +++ b/src/main/java/com/thealgorithms/ciphers/SimpleSubstitutionCipher.java @@ -80,16 +80,4 @@ public static String decode(String encryptedMessage, String cipherSmall) { return decoded.toString(); } - - /** - * TODO remove main and make JUnit Testing - */ - public static void main(String[] args) { - String a = encode( - "defend the east wall of the castle", - "phqgiumeaylnofdxjkrcvstzwb" - ); - String b = decode(a, "phqgiumeaylnofdxjkrcvstzwb"); - System.out.println(b); - } } diff --git a/src/test/java/com/thealgorithms/ciphers/SimpleSubstitutionCipherTest.java b/src/test/java/com/thealgorithms/ciphers/SimpleSubstitutionCipherTest.java new file mode 100644 index 000000000000..59fb9c072ba5 --- /dev/null +++ b/src/test/java/com/thealgorithms/ciphers/SimpleSubstitutionCipherTest.java @@ -0,0 +1,48 @@ +package com.thealgorithms.ciphers; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class SimpleSubstitutionCipherTest { + + @Test + void testEncode() { + // Given + String message = "HELLOWORLD"; + String key = "phqgiumeaylnofdxjkrcvstzwb"; + + // When + String actual = SimpleSubstitutionCipher.encode(message, key); + + // Then + assertEquals("EINNDTDKNG", actual); + } + + @Test + void testDecode() { + // Given + String message = "EINNDTDKNG"; + String key = "phqgiumeaylnofdxjkrcvstzwb"; + + // When + String actual = SimpleSubstitutionCipher.decode(message, key); + + // Then + assertEquals("HELLOWORLD", actual); + } + + @Test + void testIsTextTheSameAfterEncodeAndDecode() { + // Given + String text = "HELLOWORLD"; + String key = "phqgiumeaylnofdxjkrcvstzwb"; + + // When + String encodedText = SimpleSubstitutionCipher.encode(text, key); + String decodedText = SimpleSubstitutionCipher.decode(encodedText, key); + + // Then + assertEquals(text, decodedText); + } +}