1
exercism fetch swift tournament

Tests/LinuxMain.swift

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

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

Tests/TournamentTests/TournamentTests.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
import XCTest
@testable import Tournament

class TournamentTests: XCTestCase {
    let input1 =
        "Allegoric Alaskians;Blithering Badgers;win\n" +
            "Devastating Donkeys;Courageous Californians;draw\n" +
            "Devastating Donkeys;Allegoric Alaskians;win\n" +
            "Courageous Californians;Blithering Badgers;loss\n" +
            "Blithering Badgers;Devastating Donkeys;loss\n" +
    "Allegoric Alaskians;Courageous Californians;win"

    let input2 =
        "Allegoric Alaskians;Blithering Badgers;win\n" +
            "Devastating Donkeys;Courageous Californians;draw\n" +
            "Devastating Donkeys;Allegoric Alaskians;win\n" +
            "\n" +
            "Courageous Californians;Blithering Badgers;loss\n" +
            "Bla;Bla;Bla\n" +
            "Blithering Badgers;Devastating Donkeys;loss\n" +
            "# Yackity yackity yack\n" +
            "Allegoric Alaskians;Courageous Californians;win\n"

    let input3 =
        "Allegoric Alaskians;Blithering Badgers;win\n" +
            "Devastating Donkeys;Allegoric Alaskians;win\n" +
            "Courageous Californians;Blithering Badgers;loss\n" +
    "Allegoric Alaskians;Courageous Californians;win"
    let expected1 =
        "Team                           | MP |  W |  D |  L |  P\n" +
            "Devastating Donkeys            |  3 |  2 |  1 |  0 |  7\n" +
            "Allegoric Alaskians            |  3 |  2 |  0 |  1 |  6\n" +
            "Blithering Badgers             |  3 |  1 |  0 |  2 |  3\n" +
    "Courageous Californians        |  3 |  0 |  1 |  2 |  1"

    let expected2 =
        "Team                           | MP |  W |  D |  L |  P\n" +
            "Devastating Donkeys            |  3 |  2 |  1 |  0 |  7\n" +
            "Allegoric Alaskians            |  3 |  2 |  0 |  1 |  6\n" +
            "Blithering Badgers             |  3 |  1 |  0 |  2 |  3\n" +
    "Courageous Californians        |  3 |  0 |  1 |  2 |  1"

    let expected3 =
        "Team                           | MP |  W |  D |  L |  P\n" +
            "Allegoric Alaskians            |  3 |  2 |  0 |  1 |  6\n" +
            "Blithering Badgers             |  2 |  1 |  0 |  1 |  3\n" +
            "Devastating Donkeys            |  1 |  1 |  0 |  0 |  3\n" +
    "Courageous Californians        |  2 |  0 |  0 |  2 |  0"

    func testGoodInput() {
        let tournament = Tournament()
        XCTAssertEqual(tournament.tally(input1), expected1)
    }

    func testIgnoreBadlines() {
        let tournament = Tournament()
        XCTAssertEqual(tournament.tally(input2), expected2)
    }

    func testinCompleteCompetition() {
        let tournament = Tournament()
        XCTAssertEqual(tournament.tally(input3), expected3)
    }

    static var allTests: [(String, (TournamentTests) -> () throws -> Void)] {
        return [
            ("testGoodInput", testGoodInput),
            ("testIgnoreBadlines", testIgnoreBadlines),
            ("testinCompleteCompetition", testinCompleteCompetition),
        ]
    }
}