1
exercism fetch swift isbn-verifier

Tests/IsbnVerifierTests/IsbnVerifierTests.swift

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import XCTest
@testable import IsbnVerifier

class IsbnVerifierTests: XCTestCase {

    func testValidIsbnNumber() {
        XCTAssertTrue(IsbnVerifier.isValid("3-598-21508-8"))
    }

    func testInvalidIsbnCheckDigit() {
        XCTAssertFalse(IsbnVerifier.isValid("3-598-21508-9"))
    }

    func testValidIsbnNumberWithACheckDigitOf10() {
        XCTAssertTrue(IsbnVerifier.isValid("3-598-21507-X"))
    }

    func testCheckDigitIsACharacterOtherThanX() {
        XCTAssertFalse(IsbnVerifier.isValid("3-598-21507-A"))
    }

    func testInvalidCharacterInIsbn() {
        XCTAssertFalse(IsbnVerifier.isValid("3-598-2K507-0"))
    }

    func testXIsOnlyValidAsACheckDigit() {
        XCTAssertFalse(IsbnVerifier.isValid("3-598-2X507-9"))
    }

    func testValidIsbnWithoutSeparatingDashes() {
        XCTAssertTrue(IsbnVerifier.isValid("3598215088"))
    }

    func testIsbnWithoutSeparatingDashesAndXAsCheckDigit() {
        XCTAssertTrue(IsbnVerifier.isValid("359821507X"))
    }

    func testIsbnWithoutCheckDigitAndDashes() {
        XCTAssertFalse(IsbnVerifier.isValid("359821507"))
    }

    func testTooLongIsbnAndNoDashes() {
        XCTAssertFalse(IsbnVerifier.isValid("3598215078X"))
    }

    func testIsbnWithoutCheckDigit() {
        XCTAssertFalse(IsbnVerifier.isValid("3-598-21507"))
    }

    func testTooLongIsbn() {
        XCTAssertFalse(IsbnVerifier.isValid("3-598-21507-XX"))
    }

    func testCheckDigitOfXShouldNotBeUsedFor0() {
        XCTAssertFalse(IsbnVerifier.isValid("3-598-21515-X"))
    }

    static var allTests: [(String, (IsbnVerifierTests) -> () throws -> Void)] {
        return [
            ("testValidIsbnNumber", testValidIsbnNumber),
            ("testInvalidIsbnCheckDigit", testInvalidIsbnCheckDigit),
            ("testValidIsbnNumberWithACheckDigitOf10", testValidIsbnNumberWithACheckDigitOf10),
            ("testCheckDigitIsACharacterOtherThanX", testCheckDigitIsACharacterOtherThanX),
            ("testInvalidCharacterInIsbn", testInvalidCharacterInIsbn),
            ("testXIsOnlyValidAsACheckDigit", testXIsOnlyValidAsACheckDigit),
            ("testValidIsbnWithoutSeparatingDashes", testValidIsbnWithoutSeparatingDashes),
            ("testIsbnWithoutSeparatingDashesAndXAsCheckDigit", testIsbnWithoutSeparatingDashesAndXAsCheckDigit),
            ("testIsbnWithoutCheckDigitAndDashes", testIsbnWithoutCheckDigitAndDashes),
            ("testTooLongIsbnAndNoDashes", testTooLongIsbnAndNoDashes),
            ("testIsbnWithoutCheckDigit", testIsbnWithoutCheckDigit),
            ("testTooLongIsbn", testTooLongIsbn),
            ("testCheckDigitOfXShouldNotBeUsedFor0", testCheckDigitOfXShouldNotBeUsedFor0)
        ]
    }
}

Tests/LinuxMain.swift

1
2
3
4
5
6
import XCTest
@testable import IsbnVerifierTests

XCTMain([
    testCase(IsbnVerifierTests.allTests),
])