Skip to content

Commit b326840

Browse files
authored
Merge pull request exercism#703 from FridaTveit/RotationalCipherEstimate
rotational-cipher: estimate and tidy
2 parents 3038fcc + 3c5bd63 commit b326840

3 files changed

Lines changed: 18 additions & 24 deletions

File tree

‎config.json‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,16 @@
204204

205205
]
206206
},
207+
{
208+
"uuid": "9eb41883-55ef-4681-b5ac-5c2259302772",
209+
"slug": "rotational-cipher",
210+
"core": false,
211+
"unlocked_by": null,
212+
"difficulty": 4,
213+
"topics": [
214+
215+
]
216+
},
207217
{
208218
"uuid": "0b92ffee-c092-4ab1-ad78-76c8cf80e1b5",
209219
"slug": "kindergarten-garden",
@@ -768,16 +778,6 @@
768778

769779
]
770780
},
771-
{
772-
"uuid": "9eb41883-55ef-4681-b5ac-5c2259302772",
773-
"slug": "rotational-cipher",
774-
"core": false,
775-
"unlocked_by": null,
776-
"difficulty": 1,
777-
"topics": [
778-
779-
]
780-
},
781781
{
782782
"uuid": "e58c29d2-80a7-40ef-bed0-4a184ae35f34",
783783
"slug": "accumulate",

‎exercises/rotational-cipher/src/example/java/RotationalCipher.java‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1+
class RotationalCipher {
12

2-
public class RotationalCipher {
3-
4-
int shiftKey;
3+
private int shiftKey;
54

65
RotationalCipher(int shiftKey) {
76
this.shiftKey = shiftKey;
87
}
98

10-
public String rotate(String data) {
9+
String rotate(String data) {
1110
StringBuilder dataStringBuilder = new StringBuilder();
1211
for (char c : data.toCharArray()) {
1312
if (Character.isUpperCase(c)) {
@@ -25,12 +24,10 @@ public String rotate(String data) {
2524
* For Uppercase CaseStart = 'A' and CaseEnd = 'Z'
2625
* For Lowercase CaseStart = 'a' and CaseEnd = 'z'
2726
*/
28-
private char getReplacementCharacter(char characterToReplace,
29-
char alphabetCaseStart, char alphabetCaseEnd) {
27+
private char getReplacementCharacter(char characterToReplace, char alphabetCaseStart, char alphabetCaseEnd) {
3028
char replacementCharacter = (char) (characterToReplace + shiftKey);
3129
if (replacementCharacter > alphabetCaseEnd) {
32-
replacementCharacter = (char) ((alphabetCaseStart - 1) +
33-
(replacementCharacter % alphabetCaseEnd));
30+
replacementCharacter = (char) ((alphabetCaseStart - 1) + (replacementCharacter % alphabetCaseEnd));
3431
}
3532
return replacementCharacter;
3633
}

‎exercises/rotational-cipher/src/test/java/RotationalCipherTest.java‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
21
import org.junit.Assert;
3-
import org.junit.Before;
42
import org.junit.Ignore;
53
import org.junit.Test;
64

@@ -13,7 +11,7 @@ public void rotateSingleCharacterBy1() {
1311
rotationalCipher = new RotationalCipher(1);
1412
Assert.assertEquals("b", rotationalCipher.rotate("a"));
1513
}
16-
14+
1715
@Ignore("Remove to run test")
1816
@Test
1917
public void rotateSingleCharacterBy26() {
@@ -75,7 +73,6 @@ public void rotatePunctuation() {
7573
public void rotateAllLetters() {
7674
rotationalCipher = new RotationalCipher(13);
7775
Assert.assertEquals("The quick brown fox jumps over the lazy dog.",
78-
rotationalCipher.rotate("Gur dhvpx oebja sbk whzcf bire gur ynml qbt."));
79-
}
80-
76+
rotationalCipher.rotate("Gur dhvpx oebja sbk whzcf bire gur ynml qbt."));
77+
}
8178
}

0 commit comments

Comments
 (0)