Skip to content

Commit cd054b6

Browse files
intergalactic-transmission, isbn-verifier, isogram (#3011)
* intergalactic-transmission, isbn-verifier, isogram * Update IsbnVerifierTest.java [no important files changed] --------- Co-authored-by: Jagdish Prajapati <[email protected]>
1 parent dfba4ad commit cd054b6

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

exercises/practice/intergalactic-transmission/src/test/java/IntergalacticTransmissionTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import org.junit.jupiter.api.Test;
22
import org.junit.jupiter.api.Disabled;
3+
import org.junit.jupiter.api.DisplayName;
34

45
import java.util.List;
56

@@ -9,6 +10,7 @@
910
public class IntergalacticTransmissionTest {
1011

1112
@Test
13+
@DisplayName("calculate transmit sequences")
1214
public void calculateTransmitSequencesEmptyMessage() {
1315
List<Integer> input = List.of();
1416
List<Integer> expected = List.of();
@@ -18,6 +20,7 @@ public void calculateTransmitSequencesEmptyMessage() {
1820

1921
@Disabled("Remove to run test")
2022
@Test
23+
@DisplayName("0x00 is transmitted as 0x0000")
2124
public void calculateTransmitSequences0x00IsTransmittedAs0x0000() {
2225
List<Integer> input = List.of(0x00);
2326
List<Integer> expected = List.of(0x00, 0x00);
@@ -27,6 +30,7 @@ public void calculateTransmitSequences0x00IsTransmittedAs0x0000() {
2730

2831
@Disabled("Remove to run test")
2932
@Test
33+
@DisplayName("0x02 is transmitted as 0x0300")
3034
public void calculateTransmitSequences0x02IsTransmittedAs0x0300() {
3135
List<Integer> input = List.of(0x02);
3236
List<Integer> expected = List.of(0x03, 0x00);
@@ -36,6 +40,7 @@ public void calculateTransmitSequences0x02IsTransmittedAs0x0300() {
3640

3741
@Disabled("Remove to run test")
3842
@Test
43+
@DisplayName("0x06 is transmitted as 0x0600")
3944
public void calculateTransmitSequences0x06IsTransmittedAs0x0600() {
4045
List<Integer> input = List.of(0x06);
4146
List<Integer> expected = List.of(0x06, 0x00);
@@ -45,6 +50,7 @@ public void calculateTransmitSequences0x06IsTransmittedAs0x0600() {
4550

4651
@Disabled("Remove to run test")
4752
@Test
53+
@DisplayName("0x05 is transmitted as 0x0581")
4854
public void calculateTransmitSequences0x05IsTransmittedAs0x0581() {
4955
List<Integer> input = List.of(0x05);
5056
List<Integer> expected = List.of(0x05, 0x81);
@@ -54,6 +60,7 @@ public void calculateTransmitSequences0x05IsTransmittedAs0x0581() {
5460

5561
@Disabled("Remove to run test")
5662
@Test
63+
@DisplayName("0x29 is transmitted as 0x2881")
5764
public void calculateTransmitSequences0x29IsTransmittedAs0x2881() {
5865
List<Integer> input = List.of(0x29);
5966
List<Integer> expected = List.of(0x28, 0x81);
@@ -63,6 +70,7 @@ public void calculateTransmitSequences0x29IsTransmittedAs0x2881() {
6370

6471
@Disabled("Remove to run test")
6572
@Test
73+
@DisplayName("0xc001c0de is transmitted as 0xc000711be1")
6674
public void calculateTransmitSequences0xc001c0deIsTransmittedAs0xc000711be1() {
6775
List<Integer> input = List.of(0xc0, 0x01, 0xc0, 0xde);
6876
List<Integer> expected = List.of(0xc0, 0x00, 0x71, 0x1b, 0xe1);
@@ -72,6 +80,7 @@ public void calculateTransmitSequences0xc001c0deIsTransmittedAs0xc000711be1() {
7280

7381
@Disabled("Remove to run test")
7482
@Test
83+
@DisplayName("six byte message")
7584
public void calculateTransmitSequencesSixByteMessage() {
7685
List<Integer> input = List.of(0x47, 0x72, 0x65, 0x61, 0x74, 0x21);
7786
List<Integer> expected = List.of(0x47, 0xb8, 0x99, 0xac, 0x17, 0xa0, 0x84);
@@ -81,6 +90,7 @@ public void calculateTransmitSequencesSixByteMessage() {
8190

8291
@Disabled("Remove to run test")
8392
@Test
93+
@DisplayName("at 7 bytes long, no padding is required")
8494
public void calculateTransmitSequencesSevenByteMessage() {
8595
List<Integer> input = List.of(0x47, 0x72, 0x65, 0x61, 0x74, 0x31, 0x21);
8696
List<Integer> expected = List.of(0x47, 0xb8, 0x99, 0xac, 0x17, 0xa0, 0xc5, 0x42);
@@ -90,6 +100,7 @@ public void calculateTransmitSequencesSevenByteMessage() {
90100

91101
@Disabled("Remove to run test")
92102
@Test
103+
@DisplayName("eight byte message")
93104
public void calculateTransmitSequencesEightByteMessage() {
94105
List<Integer> input = List.of(0xc0, 0x01, 0x13, 0x37, 0xc0, 0xde, 0x21, 0x21);
95106
List<Integer> expected = List.of(0xc0, 0x00, 0x44, 0x66, 0x7d, 0x06, 0x78, 0x42, 0x21, 0x81);
@@ -99,6 +110,7 @@ public void calculateTransmitSequencesEightByteMessage() {
99110

100111
@Disabled("Remove to run test")
101112
@Test
113+
@DisplayName("twenty byte message")
102114
public void calculateTransmitSequencesTwentyByteMessage() {
103115
List<Integer> input = List.of(
104116
0x45, 0x78, 0x65, 0x72, 0x63, 0x69, 0x73, 0x6d, 0x20, 0x69,
@@ -113,6 +125,7 @@ public void calculateTransmitSequencesTwentyByteMessage() {
113125

114126
@Disabled("Remove to run test")
115127
@Test
128+
@DisplayName("empty message")
116129
public void decodeReceivedMessagesEmptyMessage() {
117130
List<Integer> input = List.of();
118131
List<Integer> expected = List.of();
@@ -122,6 +135,7 @@ public void decodeReceivedMessagesEmptyMessage() {
122135

123136
@Disabled("Remove to run test")
124137
@Test
138+
@DisplayName("zero message")
125139
public void decodeReceivedMessagesZeroMessage() {
126140
List<Integer> input = List.of(0x00, 0x00);
127141
List<Integer> expected = List.of(0x00);
@@ -131,6 +145,7 @@ public void decodeReceivedMessagesZeroMessage() {
131145

132146
@Disabled("Remove to run test")
133147
@Test
148+
@DisplayName("0x0300 is decoded to 0x02")
134149
public void decodeReceivedMessages0x0300IsDecodedTo0x02() {
135150
List<Integer> input = List.of(0x03, 0x00);
136151
List<Integer> expected = List.of(0x02);
@@ -140,6 +155,7 @@ public void decodeReceivedMessages0x0300IsDecodedTo0x02() {
140155

141156
@Disabled("Remove to run test")
142157
@Test
158+
@DisplayName("0x0581 is decoded to 0x05")
143159
public void decodeReceivedMessages0x0581IsDecodedTo0x05() {
144160
List<Integer> input = List.of(0x05, 0x81);
145161
List<Integer> expected = List.of(0x05);
@@ -149,6 +165,7 @@ public void decodeReceivedMessages0x0581IsDecodedTo0x05() {
149165

150166
@Disabled("Remove to run test")
151167
@Test
168+
@DisplayName("0x2881 is decoded to 0x29")
152169
public void decodeReceivedMessages0x2881IsDecodedTo0x29() {
153170
List<Integer> input = List.of(0x28, 0x81);
154171
List<Integer> expected = List.of(0x29);
@@ -158,6 +175,7 @@ public void decodeReceivedMessages0x2881IsDecodedTo0x29() {
158175

159176
@Disabled("Remove to run test")
160177
@Test
178+
@DisplayName("first byte has wrong parity")
161179
public void decodeFirstByteWrongParity() {
162180
List<Integer> input = List.of(0x07, 0x00);
163181
assertThrows(IllegalArgumentException.class, ()
@@ -166,6 +184,7 @@ public void decodeFirstByteWrongParity() {
166184

167185
@Disabled("Remove to run test")
168186
@Test
187+
@DisplayName("second byte has wrong parity")
169188
public void decodeSecondByteWrongParity() {
170189
List<Integer> input = List.of(0x03, 0x68);
171190
assertThrows(IllegalArgumentException.class, ()
@@ -174,6 +193,7 @@ public void decodeSecondByteWrongParity() {
174193

175194
@Disabled("Remove to run test")
176195
@Test
196+
@DisplayName("0xcf4b00 is decoded to 0xce94")
177197
public void decode0xcf4b00To0xce94() {
178198
List<Integer> input = List.of(0xcf, 0x4b, 0x00);
179199
List<Integer> expected = List.of(0xce, 0x94);
@@ -183,6 +203,7 @@ public void decode0xcf4b00To0xce94() {
183203

184204
@Disabled("Remove to run test")
185205
@Test
206+
@DisplayName("0xe2566500 is decoded to 0xe2ad90")
186207
public void decode0xe2566500To0xe2ad90() {
187208
List<Integer> input = List.of(0xe2, 0x56, 0x65, 0x00);
188209
List<Integer> expected = List.of(0xe2, 0xad, 0x90);
@@ -192,6 +213,7 @@ public void decode0xe2566500To0xe2ad90() {
192213

193214
@Disabled("Remove to run test")
194215
@Test
216+
@DisplayName("six byte message")
195217
public void decodeSixByteMessage() {
196218
List<Integer> input = List.of(0x47, 0xb8, 0x99, 0xac, 0x17, 0xa0, 0x84);
197219
List<Integer> expected = List.of(0x47, 0x72, 0x65, 0x61, 0x74, 0x21);
@@ -201,6 +223,7 @@ public void decodeSixByteMessage() {
201223

202224
@Disabled("Remove to run test")
203225
@Test
226+
@DisplayName("seven byte message")
204227
public void decodeSevenByteMessage() {
205228
List<Integer> input = List.of(0x47, 0xb8, 0x99, 0xac, 0x17, 0xa0, 0xc5, 0x42);
206229
List<Integer> expected = List.of(0x47, 0x72, 0x65, 0x61, 0x74, 0x31, 0x21);
@@ -210,6 +233,7 @@ public void decodeSevenByteMessage() {
210233

211234
@Disabled("Remove to run test")
212235
@Test
236+
@DisplayName("last byte has wrong parity")
213237
public void decodeLastByteWrongParity() {
214238
List<Integer> input = List.of(0x47, 0xb8, 0x99, 0xac, 0x17, 0xa0, 0xc5, 0x43);
215239
assertThrows(IllegalArgumentException.class, ()
@@ -218,6 +242,7 @@ public void decodeLastByteWrongParity() {
218242

219243
@Disabled("Remove to run test")
220244
@Test
245+
@DisplayName("eight byte message")
221246
public void decodeEightByteMessage() {
222247
List<Integer> input = List.of(0xc0, 0x00, 0x44, 0x66, 0x7d, 0x06, 0x78, 0x42, 0x21, 0x81);
223248
List<Integer> expected = List.of(0xc0, 0x01, 0x13, 0x37, 0xc0, 0xde, 0x21, 0x21);
@@ -227,6 +252,7 @@ public void decodeEightByteMessage() {
227252

228253
@Disabled("Remove to run test")
229254
@Test
255+
@DisplayName("twenty byte message")
230256
public void decodeTwentyByteMessage() {
231257
List<Integer> input = List.of(
232258
0x44, 0xbd, 0x18, 0xaf, 0x27, 0x1b, 0xa5, 0xe7, 0x6c, 0x90, 0x1b,
@@ -240,6 +266,7 @@ public void decodeTwentyByteMessage() {
240266

241267
@Disabled("Remove to run test")
242268
@Test
269+
@DisplayName("wrong parity on 16th byte")
243270
public void decodeWrongParityOn16thByte() {
244271
List<Integer> input = List.of(
245272
0x44, 0xbd, 0x18, 0xaf, 0x27, 0x1b, 0xa5, 0xe7, 0x6c, 0x90,

exercises/practice/isbn-verifier/src/test/java/IsbnVerifierTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import org.junit.jupiter.api.BeforeEach;
22
import org.junit.jupiter.api.Disabled;
3+
import org.junit.jupiter.api.DisplayName;
34
import org.junit.jupiter.api.Test;
45

56
import static org.assertj.core.api.Assertions.assertThat;
@@ -13,120 +14,140 @@ public void setUp() {
1314
}
1415

1516
@Test
17+
@DisplayName("valid isbn")
1618
public void validIsbnNumber() {
1719
assertThat(isbnVerifier.isValid("3-598-21508-8")).isTrue();
1820
}
1921

2022
@Disabled("Remove to run test")
2123
@Test
24+
@DisplayName("invalid isbn check digit")
2225
public void invalidIsbnCheckDigit() {
2326
assertThat(isbnVerifier.isValid("3-598-21508-9")).isFalse();
2427
}
2528

2629
@Disabled("Remove to run test")
2730
@Test
31+
@DisplayName("valid isbn with a check digit of 10")
2832
public void validIsbnNumberWithCheckDigitOfTen() {
2933
assertThat(isbnVerifier.isValid("3-598-21507-X")).isTrue();
3034
}
3135

3236
@Disabled("Remove to run test")
3337
@Test
38+
@DisplayName("valid isbn with check digit padded with letters is invalid")
3439
public void validIsbnNumberWithCheckDigitPaddedWithLettersIsInvalid() {
3540
assertThat(isbnVerifier.isValid("ABCDEFG3-598-21507-XQWERTYUI")).isFalse();
3641
}
3742

3843
@Disabled("Remove to run test")
3944
@Test
45+
@DisplayName("check digit is a character other than X")
4046
public void checkDigitIsACharacterOtherThanX() {
4147
assertThat(isbnVerifier.isValid("3-598-21507-A")).isFalse();
4248
}
4349

4450
@Disabled("Remove to run test")
4551
@Test
52+
@DisplayName("invalid check digit in isbn is not treated as zero")
4653
public void invalidCheckDigitInIsbn() {
4754
assertThat(isbnVerifier.isValid("4-598-21507-B")).isFalse();
4855
}
4956

5057
@Disabled("Remove to run test")
5158
@Test
59+
@DisplayName("invalid character in isbn is not treated as zero")
5260
public void invalidCharacterInIsbn() {
5361
assertThat(isbnVerifier.isValid("3-598-P1581-X")).isFalse();
5462
}
5563

5664
@Disabled("Remove to run test")
5765
@Test
66+
@DisplayName("X is only valid as a check digit")
5867
public void xIsOnlyValidAsACheckDigit() {
5968
assertThat(isbnVerifier.isValid("3-598-2X507-9")).isFalse();
6069
}
6170

6271
@Disabled("Remove to run test")
6372
@Test
73+
@DisplayName("valid isbn without separating dashes")
6474
public void validIsbnWithoutSeparatingDashes() {
6575
assertThat(isbnVerifier.isValid("3598215088")).isTrue();
6676
}
6777

6878
@Disabled("Remove to run test")
6979
@Test
80+
@DisplayName("isbn without separating dashes and X as check digit")
7081
public void isbnWithoutSeparatingDashesAndXAsCheckDigit() {
7182
assertThat(isbnVerifier.isValid("359821507X")).isTrue();
7283
}
7384

7485
@Disabled("Remove to run test")
7586
@Test
87+
@DisplayName("isbn without check digit and dashes")
7688
public void isbnWithoutCheckDigitAndDashes() {
7789
assertThat(isbnVerifier.isValid("359821507")).isFalse();
7890
}
7991

8092
@Disabled("Remove to run test")
8193
@Test
94+
@DisplayName("too long isbn and no dashes")
8295
public void tooLongIsbnAndNoDashes() {
8396
assertThat(isbnVerifier.isValid("3598215078X")).isFalse();
8497
}
8598

8699
@Disabled("Remove to run test")
87100
@Test
101+
@DisplayName("too short isbn")
88102
public void tooShortIsbn() {
89103
assertThat(isbnVerifier.isValid("00")).isFalse();
90104
}
91105

92106
@Disabled("Remove to run test")
93107
@Test
108+
@DisplayName("isbn without check digit")
94109
public void isbnWithoutCheckDigit() {
95110
assertThat(isbnVerifier.isValid("3-598-21507")).isFalse();
96111
}
97112

98113
@Disabled("Remove to run test")
99114
@Test
115+
@DisplayName("check digit of X should not be used for 0")
100116
public void checkDigitOfXShouldNotBeUsedForZero() {
101117
assertThat(isbnVerifier.isValid("3-598-21515-X")).isFalse();
102118
}
103119

104120
@Disabled("Remove to run test")
105121
@Test
122+
@DisplayName("empty isbn")
106123
public void emptyIsbn() {
107124
assertThat(isbnVerifier.isValid("")).isFalse();
108125
}
109126

110127
@Disabled("Remove to run test")
111128
@Test
129+
@DisplayName("input is 9 characters")
112130
public void inputIsNineCharacters() {
113131
assertThat(isbnVerifier.isValid("134456729")).isFalse();
114132
}
115133

116134
@Disabled("Remove to run test")
117135
@Test
136+
@DisplayName("invalid characters are not ignored after checking length")
118137
public void invalidCharactersAreNotIgnoredAfterCheckingLength() {
119138
assertThat(isbnVerifier.isValid("3132P34035")).isFalse();
120139
}
121140

122141
@Disabled("Remove to run test")
123142
@Test
143+
@DisplayName("invalid characters are not ignored before checking length")
124144
public void invalidCharactersAreNotIgnoredBeforeCheckingLength() {
125145
assertThat(isbnVerifier.isValid("3598P215088")).isFalse();
126146
}
127147

128148
@Disabled("Remove to run test")
129149
@Test
150+
@DisplayName("input is too long but contains a valid isbn")
130151
public void inputIsTooLongButContainsAValidIsbn() {
131152
assertThat(isbnVerifier.isValid("98245726788")).isFalse();
132153
}

0 commit comments

Comments
 (0)