Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename bracket-push exercise to matching-brackets #402

Merged
merged 11 commits into from
Aug 29, 2021
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@
]
},
{
"slug": "bracket-push",
"slug": "matching-brackets",
"uuid": "b3924cce-02f7-4962-85a5-e67d8b1ac1fa",
"core": false,
"unlocked_by": null,
Expand Down
21 changes: 0 additions & 21 deletions exercises/bracket-push/Package.swift

This file was deleted.

6 changes: 0 additions & 6 deletions exercises/bracket-push/Tests/LinuxMain.swift

This file was deleted.

21 changes: 21 additions & 0 deletions exercises/matching-brackets/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// swift-tools-version:4.2

import PackageDescription

let package = Package(
name: "MatchingBrackets",
products: [
.library(
name: "MatchingBrackets",
targets: ["MatchingBrackets"]),
],
dependencies: [],
targets: [
.target(
name: "MatchingBrackets",
dependencies: []),
.testTarget(
name: "MatchingBracketsTests",
dependencies: ["MatchingBrackets"]),
]
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Bracket Push
# Matching Brackets
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a change in requirements for practice exercises, and this file now needs to be in .docs/instructions.md instead of README.md (docs: https://github.com/exercism/docs/blob/main/building/tracks/practice-exercises.md#file-docsinstructionsmd)


Given a string containing brackets `[]`, braces `{}` and parentheses `()`,
verify that all the pairs are matched and nested correctly.
Given a string containing brackets `[]`, braces `{}`, parentheses `()`,
or any combination thereof, verify that any and all pairs are matched
and nested correctly.

## Setup

Expand All @@ -10,7 +11,7 @@ Go through the project setup instructions for Xcode using Swift:
http://exercism.io/languages/swift
http://exercism.io/languages/swift/tests

Notably from the source directory:
Notably, from the source directory:

`swift test` runs tests
`swift package generate-xcodeproj` creates an Xcode project
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
struct BracketPush {
struct MatchingBrackets {

private static let brackets: [Character: Character] = [
")": "(",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
import XCTest
@testable import BracketPush
@testable import MatchingBrackets

class BracketPushTests: XCTestCase {
class MatchingBracketsTests: XCTestCase {

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

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

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

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

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

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

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

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

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

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

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

func testMathExpression() {
XCTAssertTrue(BracketPush.paired(text: "(((185 + 223.85) * 15) - 543)/2"))
XCTAssertTrue(MatchingBrackets.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))
XCTAssertTrue(MatchingBrackets.paired(text: text))
}

static var allTests: [(String, (BracketPushTests) -> () throws -> Void)] {
static var allTests: [(String, (MatchingBracketsTests) -> () throws -> Void)] {
return [
("testPairedSquareBrackets", testPairedSquareBrackets),
("testEmptyString", testEmptyString),
Expand Down