Skip to content

Commit 065fb59

Browse files
committed
atbash-cipher: make class use instance method
Fixes issue exercism#366.
1 parent 165511f commit 065fb59

2 files changed

Lines changed: 23 additions & 23 deletions

File tree

‎exercises/atbash-cipher/src/example/java/Atbash.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class Atbash {
77
private static final String PLAIN = "abcdefghijklmnopqrstuvwxyz";
88
private static final String CIPHER = "zyxwvutsrqponmlkjihgfedcba";
99

10-
public static String encode(String input) {
10+
public String encode(String input) {
1111
String encoded = stripInvalidCharacters(input).toLowerCase();
1212
String cyphered = "";
1313

@@ -18,7 +18,7 @@ public static String encode(String input) {
1818
return splitIntoFiveLetterWords(cyphered);
1919
}
2020

21-
public static String decode(String input) {
21+
public String decode(String input) {
2222
String encoded = stripInvalidCharacters(input).toLowerCase();
2323
String deciphered = "";
2424

@@ -29,7 +29,7 @@ public static String decode(String input) {
2929
return deciphered;
3030
}
3131

32-
private static String stripInvalidCharacters(String input) {
32+
private String stripInvalidCharacters(String input) {
3333
String filteredValue = "";
3434

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

44-
private static char applyCipher(char input) {
44+
private char applyCipher(char input) {
4545
int idx = PLAIN.indexOf(input);
4646

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

50-
private static String splitIntoFiveLetterWords(String value) {
50+
private String splitIntoFiveLetterWords(String value) {
5151
List<String> words = new ArrayList<>();
5252

5353
for (int i = 0; i < value.length(); i += GROUP_SIZE) {

‎exercises/atbash-cipher/src/test/java/AtbashTest.java‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import org.junit.Test;
21
import org.junit.Ignore;
2+
import org.junit.Test;
33
import org.junit.experimental.runners.Enclosed;
44
import org.junit.runner.RunWith;
55
import org.junit.runners.Parameterized;
@@ -20,14 +20,14 @@ public static class EncodeTest {
2020

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

@@ -37,9 +37,9 @@ public EncodeTest(String plaintext, String ciphertext) {
3737
}
3838

3939

40-
@Test
40+
@Test
4141
public void test() {
42-
assertEquals(ciphertext, Atbash.encode(plaintext));
42+
assertEquals(ciphertext, new Atbash().encode(plaintext));
4343
}
4444
}
4545

@@ -50,11 +50,11 @@ public static class DecodeTest {
5050

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

@@ -64,9 +64,9 @@ public DecodeTest(String ciphertext, String plaintext) {
6464
}
6565

6666
@Ignore
67-
@Test
67+
@Test
6868
public void test() {
69-
assertEquals(plaintext, Atbash.decode(ciphertext));
69+
assertEquals(plaintext, new Atbash().decode(ciphertext));
7070
}
7171
}
7272
}

0 commit comments

Comments
 (0)