Skip to content

Add SimpleSubstitutionCipherTest #3857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}