Add SimpleSubstitutionCipherTest (#3857)

This commit is contained in:
Hikmet Çakır 2023-01-17 23:05:24 +03:00 committed by GitHub
parent b14f55096d
commit 54d6f79acd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 12 deletions

View File

@ -80,16 +80,4 @@ public class SimpleSubstitutionCipher {
return decoded.toString(); 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);
}
} }

View File

@ -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);
}
}