1
exercism fetch swift kindergarten-garden

Tests/KindergartenGardenTests/KindergartenGardenTests.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import XCTest
@testable import KindergartenGarden

class KindergartenGardenTests: XCTestCase {
    private let fullGarden = Garden("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV")
    private let disorderedGarden = Garden("VCRRGVRG\nRVGCCGCV", children: ["Samantha", "Patricia", "Xander", "Roger"])
    private static let diagram = "VCRRGVRG\nRVGCCGCV"
    private let garden1 = Garden(diagram, children: ["Alice", "Bob", "Charlie", "Dan"])
    private let garden2 = Garden(diagram, children: ["Bob", "Charlie", "Dan", "Erin"])

    func testAlicesGarden() {
        let garden = Garden("RC\nGG")
        XCTAssertEqual([.radishes, .clover, .grass, .grass], garden.plantsForChild("Alice"))
    }

    func testDifferentGardenForAlice() {
        let garden = Garden("VC\nRC")
        XCTAssertEqual([.violets, .clover, .radishes, .clover], garden.plantsForChild("Alice"))
    }

    func testBobsGarden() {
        let garden = Garden("VVCG\nVVRC")
        XCTAssertEqual([.clover, .grass, .radishes, .clover], garden.plantsForChild("Bob"))
    }

    func testBobAndCharliesGardens() {
        let garden = Garden("VVCCGG\nVVCCGG")
        XCTAssertEqual([.clover, .clover, .clover, .clover], garden.plantsForChild("Bob"))
        XCTAssertEqual([.grass, .grass, .grass, .grass], garden.plantsForChild("Charlie"))
    }

    // MARK: - Test full garden

    func testAlice() {
        XCTAssertEqual([.violets, .radishes, .violets, .radishes], fullGarden.plantsForChild("Alice"))
    }

    func testBob() {
        XCTAssertEqual([.clover, .grass, .clover, .clover], fullGarden.plantsForChild("Bob"))
    }

    func testCharlie() {
        XCTAssertEqual([.violets, .violets, .clover, .grass], fullGarden.plantsForChild("Charlie"))
    }

    func testDavid() {
        XCTAssertEqual([.radishes, .violets, .clover, .radishes], fullGarden.plantsForChild("David"))
    }

    func testEve() {
        XCTAssertEqual([.clover, .grass, .radishes, .grass], fullGarden.plantsForChild("Eve"))
    }

    func testFred() {
        XCTAssertEqual([.grass, .clover, .violets, .clover], fullGarden.plantsForChild("Fred"))
    }

    func testGinny() {
        XCTAssertEqual([.clover, .grass, .grass, .clover], fullGarden.plantsForChild("Ginny"))
    }

    func testHarriet() {
        XCTAssertEqual([.violets, .radishes, .radishes, .violets], fullGarden.plantsForChild("Harriet"))
    }

    func testIleana() {
        XCTAssertEqual([.grass, .clover, .violets, .clover], fullGarden.plantsForChild("Ileana"))
    }

    func testJoseph() {
        XCTAssertEqual([.violets, .clover, .violets, .grass], fullGarden.plantsForChild("Joseph"))
    }

    func testKincaid() {
        XCTAssertEqual([.grass, .clover, .clover, .grass], fullGarden.plantsForChild("Kincaid"))
    }

    func testLarry() {
        XCTAssertEqual([.grass, .violets, .clover, .violets], fullGarden.plantsForChild("Larry"))
    }

    // MARK: - Test disordered garden

    func testPatricia() {
        XCTAssertEqual([.violets, .clover, .radishes, .violets], disorderedGarden.plantsForChild("Patricia"))
    }

    func testRoger() {
        XCTAssertEqual([.radishes, .radishes, .grass, .clover], disorderedGarden.plantsForChild("Roger"))
    }

    func testSamantha() {
        XCTAssertEqual([.grass, .violets, .clover, .grass], disorderedGarden.plantsForChild("Samantha"))
    }

    func testXander() {
        XCTAssertEqual([.radishes, .grass, .clover, .violets], disorderedGarden.plantsForChild("Xander"))
    }

    // MARK: - Test two gardens, different students

    func testBobAndCharliePerGarden() {
        XCTAssertEqual([.radishes, .radishes, .grass, .clover], garden1.plantsForChild("Bob"))
        XCTAssertEqual([.violets, .clover, .radishes, .violets], garden2.plantsForChild("Bob"))
        XCTAssertEqual([.grass, .violets, .clover, .grass], garden1.plantsForChild("Charlie"))
        XCTAssertEqual([.radishes, .radishes, .grass, .clover], garden2.plantsForChild("Charlie"))
    }

    static var allTests: [(String, (KindergartenGardenTests) -> () throws -> Void)] {
        return [
            ("testAlicesGarden", testAlicesGarden),
            ("testDifferentGardenForAlice", testDifferentGardenForAlice),
            ("testBobsGarden", testBobsGarden),
            ("testBobAndCharliesGardens", testBobAndCharliesGardens),
            ("testAlice", testAlice),
            ("testBob", testBob),
            ("testCharlie", testCharlie),
            ("testDavid", testDavid),
            ("testEve", testEve),
            ("testFred", testFred),
            ("testGinny", testGinny),
            ("testHarriet", testHarriet),
            ("testIleana", testIleana),
            ("testJoseph", testJoseph),
            ("testKincaid", testKincaid),
            ("testLarry", testLarry),
            ("testPatricia", testPatricia),
            ("testRoger", testRoger),
            ("testSamantha", testSamantha),
            ("testXander", testXander),
            ("testBobAndCharliePerGarden", testBobAndCharliePerGarden),
        ]
    }
}

Tests/LinuxMain.swift

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

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