Skip to content
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

atbash-cipher: make class use instance method [Fix #366] #421

Merged
merged 1 commit into from
Apr 12, 2017
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
10 changes: 5 additions & 5 deletions exercises/atbash-cipher/src/example/java/Atbash.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class Atbash {
private static final String PLAIN = "abcdefghijklmnopqrstuvwxyz";
private static final String CIPHER = "zyxwvutsrqponmlkjihgfedcba";

public static String encode(String input) {
public String encode(String input) {
String encoded = stripInvalidCharacters(input).toLowerCase();
String cyphered = "";

Expand All @@ -18,7 +18,7 @@ public static String encode(String input) {
return splitIntoFiveLetterWords(cyphered);
}

public static String decode(String input) {
public String decode(String input) {
String encoded = stripInvalidCharacters(input).toLowerCase();
String deciphered = "";

Expand All @@ -29,7 +29,7 @@ public static String decode(String input) {
return deciphered;
}

private static String stripInvalidCharacters(String input) {
private String stripInvalidCharacters(String input) {
String filteredValue = "";

for (char c : input.toCharArray()) {
Expand All @@ -41,13 +41,13 @@ private static String stripInvalidCharacters(String input) {
return filteredValue;
}

private static char applyCipher(char input) {
private char applyCipher(char input) {
int idx = PLAIN.indexOf(input);

return idx >= 0 ? CIPHER.toCharArray()[idx] : input;
}

private static String splitIntoFiveLetterWords(String value) {
private String splitIntoFiveLetterWords(String value) {
List<String> words = new ArrayList<>();

for (int i = 0; i < value.length(); i += GROUP_SIZE) {
Expand Down
36 changes: 18 additions & 18 deletions exercises/atbash-cipher/src/test/java/AtbashTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import org.junit.Test;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
Expand All @@ -20,14 +20,14 @@ public static class EncodeTest {

@Parameters(name = "{index}: expected plaintext \"{0}\" to encode to ciphertext \"{1}\".")
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] {
{ "no", "ml" },
{ "yes", "bvh" },
{ "OMG", "lnt" },
{ "mindblowingly", "nrmwy oldrm tob" },
{ "Testing, 1 2 3, testing.", "gvhgr mt123 gvhgr mt" },
{ "Truth is fiction.", "gifgs rhurx grlm" },
{ "The quick brown fox jumps over the lazy dog.", "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt" }
return Arrays.asList(new Object[][]{
{"no", "ml"},
{"yes", "bvh"},
{"OMG", "lnt"},
{"mindblowingly", "nrmwy oldrm tob"},
{"Testing, 1 2 3, testing.", "gvhgr mt123 gvhgr mt"},
{"Truth is fiction.", "gifgs rhurx grlm"},
{"The quick brown fox jumps over the lazy dog.", "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt"}
});
}

Expand All @@ -37,9 +37,9 @@ public EncodeTest(String plaintext, String ciphertext) {
}


@Test
@Test
public void test() {
assertEquals(ciphertext, Atbash.encode(plaintext));
assertEquals(ciphertext, new Atbash().encode(plaintext));
}
}

Expand All @@ -50,11 +50,11 @@ public static class DecodeTest {

@Parameters(name = "{index}: expected ciphertext \"{0}\" to decode to plaintext \"{1}\".")
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] {
{ "vcvix rhn", "exercism" },
{ "zmlyh gzxov rhlug vmzhg vkkrm thglm v", "anobstacleisoftenasteppingstone" },
{ "gvhgr mt123 gvhgr mt", "testing123testing" },
{ "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt", "thequickbrownfoxjumpsoverthelazydog" }
return Arrays.asList(new Object[][]{
{"vcvix rhn", "exercism"},
{"zmlyh gzxov rhlug vmzhg vkkrm thglm v", "anobstacleisoftenasteppingstone"},
{"gvhgr mt123 gvhgr mt", "testing123testing"},
{"gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt", "thequickbrownfoxjumpsoverthelazydog"}
});
}

Expand All @@ -64,9 +64,9 @@ public DecodeTest(String ciphertext, String plaintext) {
}

@Ignore
@Test
@Test
public void test() {
assertEquals(plaintext, Atbash.decode(ciphertext));
assertEquals(plaintext, new Atbash().decode(ciphertext));
}
}
}