Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;

import java.util.List;

Expand All @@ -9,6 +10,7 @@
public class IntergalacticTransmissionTest {

@Test
@DisplayName("calculate transmit sequences")
public void calculateTransmitSequencesEmptyMessage() {
List<Integer> input = List.of();
List<Integer> expected = List.of();
Expand All @@ -18,6 +20,7 @@ public void calculateTransmitSequencesEmptyMessage() {

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

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

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

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

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

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

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

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

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

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

@Disabled("Remove to run test")
@Test
@DisplayName("empty message")
public void decodeReceivedMessagesEmptyMessage() {
List<Integer> input = List.of();
List<Integer> expected = List.of();
Expand All @@ -122,6 +135,7 @@ public void decodeReceivedMessagesEmptyMessage() {

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

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

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

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

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

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

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

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

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

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

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

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

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

@Disabled("Remove to run test")
@Test
@DisplayName("wrong parity on 16th byte")
public void decodeWrongParityOn16thByte() {
List<Integer> input = List.of(
0x44, 0xbd, 0x18, 0xaf, 0x27, 0x1b, 0xa5, 0xe7, 0x6c, 0x90,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

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

@Test
@DisplayName("valid isbn")
public void validIsbnNumber() {
assertThat(isbnVerifier.isValid("3-598-21508-8")).isTrue();
}

@Disabled("Remove to run test")
@Test
@DisplayName("invalid isbn check digit")
public void invalidIsbnCheckDigit() {
assertThat(isbnVerifier.isValid("3-598-21508-9")).isFalse();
}

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

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

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

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

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

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

@Disabled("Remove to run test")
@Test
@DisplayName("valid isbn without separating dashes")
public void validIsbnWithoutSeparatingDashes() {
assertThat(isbnVerifier.isValid("3598215088")).isTrue();
}

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

@Disabled("Remove to run test")
@Test
@DisplayName("isbn without check digit and dashes")
public void isbnWithoutCheckDigitAndDashes() {
assertThat(isbnVerifier.isValid("359821507")).isFalse();
}

@Disabled("Remove to run test")
@Test
@DisplayName("too long isbn and no dashes")
public void tooLongIsbnAndNoDashes() {
assertThat(isbnVerifier.isValid("3598215078X")).isFalse();
}

@Disabled("Remove to run test")
@Test
@DisplayName("too short isbn")
public void tooShortIsbn() {
assertThat(isbnVerifier.isValid("00")).isFalse();
}

@Disabled("Remove to run test")
@Test
@DisplayName("isbn without check digit")
public void isbnWithoutCheckDigit() {
assertThat(isbnVerifier.isValid("3-598-21507")).isFalse();
}

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

@Disabled("Remove to run test")
@Test
@DisplayName("empty isbn")
public void emptyIsbn() {
assertThat(isbnVerifier.isValid("")).isFalse();
}

@Disabled("Remove to run test")
@Test
@DisplayName("input is 9 characters")
public void inputIsNineCharacters() {
assertThat(isbnVerifier.isValid("134456729")).isFalse();
}

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

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

@Disabled("Remove to run test")
@Test
@DisplayName("input is too long but contains a valid isbn")
public void inputIsTooLongButContainsAValidIsbn() {
assertThat(isbnVerifier.isValid("98245726788")).isFalse();
}
Expand Down
Loading