1
exercism fetch swift bracket-push

Tests/BracketPushTests/BracketPushTests.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
import XCTest
@testable import BracketPush

class BracketPushTests: XCTestCase {

    func testPairedSquareBrackets() {
        XCTAssertTrue(BracketPush.paired(text: "[]"))
    }

    func testEmptyString() {
        XCTAssertTrue(BracketPush.paired(text: ""))
    }

    func testUnpairedBrackets() {
        XCTAssertFalse(BracketPush.paired(text: "[["))
    }

    func testWrongOrderedBrackets() {
        XCTAssertFalse(BracketPush.paired(text: "}{"))
    }

    func testPairedWithWhitespace() {
        XCTAssertTrue(BracketPush.paired(text: "{ }"))
    }

    func testSimpleNestedBrackets() {
        XCTAssertTrue(BracketPush.paired(text: "{[]}"))
    }

    func testSeveralPairedBrackets() {
        XCTAssertTrue(BracketPush.paired(text: "{}[]()"))
    }

    func testPairedAndNestedBrackets() {
        XCTAssertTrue(BracketPush.paired(text: "([{}({}[])])"))
    }

    func testUnopenedClosingBrackets() {
        XCTAssertFalse(BracketPush.paired(text: "{[)][]}"))
    }

    func testUnpairedAndNestedBrackets() {
        XCTAssertFalse(BracketPush.paired(text: "([{])"))
    }

    func testPairedAndWrongNestedBrackets() {
        XCTAssertFalse(BracketPush.paired(text: "[({]})"))
    }

    func testMathExpression() {
        XCTAssertTrue(BracketPush.paired(text: "(((185 + 223.85) * 15) - 543)/2"))
    }

    func testComplexLatexExpression() {
        let text = "\\left(\\begin{array}{cc} \\frac{1}{3} & x\\\\ \\mathrm{e}^{x} &... x^2 \\end{array}\\right)"
        XCTAssertTrue(BracketPush.paired(text: text))
    }

    static var allTests: [(String, (BracketPushTests) -> () throws -> Void)] {
        return [
            ("testPairedSquareBrackets", testPairedSquareBrackets),
            ("testEmptyString", testEmptyString),
            ("testUnpairedBrackets", testUnpairedBrackets),
            ("testWrongOrderedBrackets", testWrongOrderedBrackets),
            ("testPairedWithWhitespace", testPairedWithWhitespace),
            ("testSimpleNestedBrackets", testSimpleNestedBrackets),
            ("testSeveralPairedBrackets", testSeveralPairedBrackets),
            ("testPairedAndNestedBrackets", testPairedAndNestedBrackets),
            ("testUnopenedClosingBrackets", testUnopenedClosingBrackets),
            ("testUnpairedAndNestedBrackets", testUnpairedAndNestedBrackets),
            ("testPairedAndWrongNestedBrackets", testPairedAndWrongNestedBrackets),
            ("testMathExpression", testMathExpression),
            ("testComplexLatexExpression", testComplexLatexExpression),
        ]
    }
}

Tests/LinuxMain.swift

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

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