1
exercism fetch swift secret-handshake

Tests/LinuxMain.swift

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

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

Tests/SecretHandshakeTests/SecretHandshakeTests.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
import XCTest
@testable import SecretHandshake

class SecretHandshakeTests: XCTestCase {
    func testHandshake1ToWink() {
        let handshake = SecretHandshake(1)
        XCTAssertEqual(["wink"], handshake.commands)
    }

    func testHandshake10ToDoubleBlink() {
        let handshake = SecretHandshake(2)
        XCTAssertEqual(["double blink"], handshake.commands)
    }

    func testHandshake100ToCloseYourEyes() {
        let handshake = SecretHandshake(4)
        XCTAssertEqual(["close your eyes"], handshake.commands)
    }

    func testHandshake1000ToJump() {
        let handshake = SecretHandshake(8)
        XCTAssertEqual(["jump"], handshake.commands)
    }

    func testHandshake11ToWinkAndDoubleBlink() {
        let handshake = SecretHandshake(3)
        XCTAssertEqual(["wink", "double blink"], handshake.commands)
    }

    func testHandshake10011ToDoubleBlinkAndWink() {
        let handshake = SecretHandshake(19)
        XCTAssertEqual(["double blink", "wink"], handshake.commands)
    }

    func testHandshake11111ToDoubleBlinkAndWink() {
        let handshake = SecretHandshake(31)
        let expected = ["jump", "close your eyes", "double blink", "wink"]
        XCTAssertEqual(expected, handshake.commands)
    }

    func testNonValidHandshake() {
        let handshake = SecretHandshake(0)
        XCTAssertEqual([], handshake.commands)
    }

    static var allTests: [(String, (SecretHandshakeTests) -> () throws -> Void)] {
        return [
            ("testHandshake1ToWink", testHandshake1ToWink),
            ("testHandshake10ToDoubleBlink", testHandshake10ToDoubleBlink),
            ("testHandshake100ToCloseYourEyes", testHandshake100ToCloseYourEyes),
            ("testHandshake1000ToJump", testHandshake1000ToJump),
            ("testHandshake11ToWinkAndDoubleBlink", testHandshake11ToWinkAndDoubleBlink),
            ("testHandshake10011ToDoubleBlinkAndWink", testHandshake10011ToDoubleBlinkAndWink),
            ("testHandshake11111ToDoubleBlinkAndWink", testHandshake11111ToDoubleBlinkAndWink),
            ("testNonValidHandshake", testNonValidHandshake),
        ]
    }
}