Skip to content

Commit 03ffb00

Browse files
committed
affine-cipher,all-your-base,allergies
1 parent 301df04 commit 03ffb00

File tree

3 files changed

+91
-3
lines changed

3 files changed

+91
-3
lines changed

exercises/practice/affine-cipher/src/test/java/AffineCipherTest.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import org.junit.jupiter.api.Disabled;
2+
import org.junit.jupiter.api.DisplayName;
23
import org.junit.jupiter.api.Test;
34

45
import static org.assertj.core.api.Assertions.assertThat;
@@ -8,57 +9,65 @@ public class AffineCipherTest {
89

910
private AffineCipher affineCipher = new AffineCipher();
1011

12+
@DisplayName("encode yes")
1113
@Test
1214
public void testEncodeYes() {
1315
assertThat(affineCipher.encode("yes", 5, 7)).isEqualTo("xbt");
1416
}
1517

18+
@DisplayName("encode no")
1619
@Disabled("Remove to run test")
1720
@Test
1821
public void testEncodeNo() {
1922
assertThat(affineCipher.encode("no", 15, 18)).isEqualTo("fu");
2023
}
2124

22-
25+
@DisplayName("encode OMG")
2326
@Disabled("Remove to run test")
2427
@Test
2528
public void testEncodeOMG() {
2629
assertThat(affineCipher.encode("OMG", 21, 3)).isEqualTo("lvz");
2730
}
2831

32+
@DisplayName("encode O M G")
2933
@Disabled("Remove to run test")
3034
@Test
3135
public void testEncodeO_M_G() {
3236
assertThat(affineCipher.encode("O M G", 25, 47)).isEqualTo("hjp");
3337
}
3438

39+
@DisplayName("encode mindblowingly")
3540
@Disabled("Remove to run test")
3641
@Test
3742
public void testEncodeMindBlowingly() {
3843
assertThat(affineCipher.encode("mindblowingly", 11, 15)).isEqualTo("rzcwa gnxzc dgt");
3944
}
4045

46+
@DisplayName("encode numbers")
4147
@Disabled("Remove to run test")
4248
@Test
4349
public void testEncodeNumbers() {
4450
assertThat(affineCipher.encode("Testing,1 2 3, testing.", 3, 4))
4551
.isEqualTo("jqgjc rw123 jqgjc rw");
4652
}
4753

54+
@DisplayName("encode deep thought")
4855
@Disabled("Remove to run test")
4956
@Test
5057
public void testEncodeDeepThought() {
5158
assertThat(affineCipher.encode("Truth is fiction.", 5, 17))
5259
.isEqualTo("iynia fdqfb ifje");
5360
}
5461

62+
@DisplayName("encode all the letters")
5563
@Disabled("Remove to run test")
5664
@Test
5765
public void testEncodeAllTheLetters() {
5866
assertThat(affineCipher.encode("The quick brown fox jumps over the lazy dog.", 17, 33))
5967
.isEqualTo("swxtj npvyk lruol iejdc blaxk swxmh qzglf");
6068
}
6169

70+
@DisplayName("encode with a not coprime to m")
6271
@Disabled("Remove to run test")
6372
@Test
6473
public void testEncodeThrowsMeaningfulException() {
@@ -67,48 +76,55 @@ public void testEncodeThrowsMeaningfulException() {
6776
.withMessage("Error: keyA and alphabet size must be coprime.");
6877
}
6978

79+
@DisplayName("decode exercism")
7080
@Disabled("Remove to run test")
7181
@Test
7282
public void testDecodeExercism() {
7383
assertThat(affineCipher.decode("tytgn fjr", 3, 7))
7484
.isEqualTo("exercism");
7585
}
7686

87+
@DisplayName("decode a sentence")
7788
@Disabled("Remove to run test")
7889
@Test
7990
public void testDecodeSentence() {
8091
assertThat(affineCipher.decode("qdwju nqcro muwhn odqun oppmd aunwd o", 19, 16))
8192
.isEqualTo("anobstacleisoftenasteppingstone");
8293
}
8394

95+
@DisplayName("decode numbers")
8496
@Disabled("Remove to run test")
8597
@Test
8698
public void testDecodeNumbers() {
8799
assertThat(affineCipher.decode("odpoz ub123 odpoz ub", 25, 7))
88100
.isEqualTo("testing123testing");
89101
}
90102

103+
@DisplayName("decode all the letters")
91104
@Disabled("Remove to run test")
92105
@Test
93106
public void testDecodeAllTheLetters() {
94107
assertThat(affineCipher.decode("swxtj npvyk lruol iejdc blaxk swxmh qzglf", 17, 33))
95108
.isEqualTo("thequickbrownfoxjumpsoverthelazydog");
96109
}
97110

111+
@DisplayName("decode with no spaces in input")
98112
@Disabled("Remove to run test")
99113
@Test
100114
public void testDecodeWithNoSpaces() {
101115
assertThat(affineCipher.decode("swxtjnpvyklruoliejdcblaxkswxmhqzglf", 17, 33))
102116
.isEqualTo("thequickbrownfoxjumpsoverthelazydog");
103117
}
104118

119+
@DisplayName("decode with too many spaces")
105120
@Disabled("Remove to run test")
106121
@Test
107122
public void testDecodeWithTooManySpaces() {
108123
assertThat(affineCipher.decode("vszzm cly yd cg qdp", 15, 16))
109124
.isEqualTo("jollygreengiant");
110125
}
111126

127+
@DisplayName("decode with a not coprime to m")
112128
@Disabled("Remove to run test")
113129
@Test
114130
public void testDecodeThrowsMeaningfulException() {

exercises/practice/all-your-base/src/test/java/BaseConverterTest.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import org.junit.jupiter.api.Disabled;
2+
import org.junit.jupiter.api.DisplayName;
23
import org.junit.jupiter.api.Test;
34

45
import static org.assertj.core.api.Assertions.assertThat;
56
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
67

78
public class BaseConverterTest {
89

10+
@DisplayName("single bit one to decimal")
911
@Test
1012
public void testSingleBitOneToDecimal() {
1113
BaseConverter baseConverter = new BaseConverter(2, new int[]{1});
@@ -14,6 +16,7 @@ public void testSingleBitOneToDecimal() {
1416
.containsExactly(1);
1517
}
1618

19+
@DisplayName("binary to single decimal")
1720
@Disabled("Remove to run test")
1821
@Test
1922
public void testBinaryToSingleDecimal() {
@@ -23,6 +26,7 @@ public void testBinaryToSingleDecimal() {
2326
.containsExactly(5);
2427
}
2528

29+
@DisplayName("single decimal to binary")
2630
@Disabled("Remove to run test")
2731
@Test
2832
public void testSingleDecimalToBinary() {
@@ -32,6 +36,7 @@ public void testSingleDecimalToBinary() {
3236
.containsExactly(1, 0, 1);
3337
}
3438

39+
@DisplayName("binary to multiple decimal")
3540
@Disabled("Remove to run test")
3641
@Test
3742
public void testBinaryToMultipleDecimal() {
@@ -41,6 +46,7 @@ public void testBinaryToMultipleDecimal() {
4146
.containsExactly(4, 2);
4247
}
4348

49+
@DisplayName("decimal to binary")
4450
@Disabled("Remove to run test")
4551
@Test
4652
public void testDecimalToBinary() {
@@ -50,6 +56,7 @@ public void testDecimalToBinary() {
5056
.containsExactly(1, 0, 1, 0, 1, 0);
5157
}
5258

59+
@DisplayName("trinary to hexadecimal")
5360
@Disabled("Remove to run test")
5461
@Test
5562
public void testTrinaryToHexadecimal() {
@@ -59,6 +66,7 @@ public void testTrinaryToHexadecimal() {
5966
.containsExactly(2, 10);
6067
}
6168

69+
@DisplayName("hexadecimal to trinary")
6270
@Disabled("Remove to run test")
6371
@Test
6472
public void testHexadecimalToTrinary() {
@@ -68,6 +76,7 @@ public void testHexadecimalToTrinary() {
6876
.containsExactly(1, 1, 2, 0);
6977
}
7078

79+
@DisplayName("15-bit integer")
7180
@Disabled("Remove to run test")
7281
@Test
7382
public void test15BitInteger() {
@@ -77,6 +86,7 @@ public void test15BitInteger() {
7786
.containsExactly(6, 10, 45);
7887
}
7988

89+
@DisplayName("empty list")
8090
@Disabled("Remove to run test")
8191
@Test
8292
public void testEmptyDigits() {
@@ -86,6 +96,7 @@ public void testEmptyDigits() {
8696
.containsExactly(0);
8797
}
8898

99+
@DisplayName("single zero")
89100
@Disabled("Remove to run test")
90101
@Test
91102
public void testSingleZero() {
@@ -95,6 +106,7 @@ public void testSingleZero() {
95106
.containsExactly(0);
96107
}
97108

109+
@DisplayName("multiple zeros")
98110
@Disabled("Remove to run test")
99111
@Test
100112
public void testMultipleZeros() {
@@ -104,6 +116,7 @@ public void testMultipleZeros() {
104116
.containsExactly(0);
105117
}
106118

119+
@DisplayName("leading zeros")
107120
@Disabled("Remove to run test")
108121
@Test
109122
public void testLeadingZeros() {
@@ -113,22 +126,25 @@ public void testLeadingZeros() {
113126
.containsExactly(4, 2);
114127
}
115128

129+
@DisplayName("input base is one")
116130
@Disabled("Remove to run test")
117131
@Test
118132
public void testFirstBaseIsOne() {
119133
assertThatExceptionOfType(IllegalArgumentException.class)
120-
.isThrownBy(() -> new BaseConverter(1, new int[]{1}))
134+
.isThrownBy(() -> new BaseConverter(1, new int[]{0}))
121135
.withMessage("Bases must be at least 2.");
122136
}
123137

138+
@DisplayName("input base is zero")
124139
@Disabled("Remove to run test")
125140
@Test
126141
public void testFirstBaseIsZero() {
127142
assertThatExceptionOfType(IllegalArgumentException.class)
128-
.isThrownBy(() -> new BaseConverter(0, new int[]{1}))
143+
.isThrownBy(() -> new BaseConverter(0, new int[]{}))
129144
.withMessage("Bases must be at least 2.");
130145
}
131146

147+
@DisplayName("input base is negative")
132148
@Disabled("Remove to run test")
133149
@Test
134150
public void testFirstBaseIsNegative() {
@@ -137,6 +153,7 @@ public void testFirstBaseIsNegative() {
137153
.withMessage("Bases must be at least 2.");
138154
}
139155

156+
@DisplayName("negative digit")
140157
@Disabled("Remove to run test")
141158
@Test
142159
public void testNegativeDigit() {
@@ -145,6 +162,7 @@ public void testNegativeDigit() {
145162
.withMessage("Digits may not be negative.");
146163
}
147164

165+
@DisplayName("invalid positive digit")
148166
@Disabled("Remove to run test")
149167
@Test
150168
public void testInvalidPositiveDigit() {
@@ -153,6 +171,7 @@ public void testInvalidPositiveDigit() {
153171
.withMessage("All digits must be strictly less than the base.");
154172
}
155173

174+
@DisplayName("output base is one")
156175
@Disabled("Remove to run test")
157176
@Test
158177
public void testSecondBaseIsOne() {
@@ -164,6 +183,7 @@ public void testSecondBaseIsOne() {
164183
.withMessage("Bases must be at least 2.");
165184
}
166185

186+
@DisplayName("output base is zero")
167187
@Disabled("Remove to run test")
168188
@Test
169189
public void testSecondBaseIsZero() {
@@ -174,6 +194,7 @@ public void testSecondBaseIsZero() {
174194
.withMessage("Bases must be at least 2.");
175195
}
176196

197+
@DisplayName("output base is negative")
177198
@Disabled("Remove to run test")
178199
@Test
179200
public void testSecondBaseIsNegative() {

0 commit comments

Comments
 (0)