Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@
]
},
{
"slug": "bracket-push",
"slug": "matching-brackets",
"uuid": "b455f96b-329d-4dec-ac31-599b02c0b2e5",
"core": false,
"unlocked_by": null,
Expand Down
73 changes: 0 additions & 73 deletions exercises/bracket-push/bracket-push.test.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Bracket Push
# Matching Brackets

Given a string containing brackets `[]`, braces `{}`, parentheses `()`,
or any combination thereof, verify that any and all pairs are matched
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class BracketPush {
class MatchingBrackets {
bracketPairs: Map<string, string>
expression: string

Expand Down Expand Up @@ -47,4 +47,4 @@ class BracketPush {
}
}

export default BracketPush
export default MatchingBrackets
73 changes: 73 additions & 0 deletions exercises/matching-brackets/matching-brackets.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import MatchingBrackets from './matching-brackets'

describe('Matching Brackets', () => {
it('paired square brackets', () => {
const matchingBrackets = new MatchingBrackets('[]')
expect(matchingBrackets.isPaired()).toBeTruthy()
})

xit('empty string', () => {
const matchingBrackets = new MatchingBrackets('')
expect(matchingBrackets.isPaired()).toBeTruthy()
})

xit('unpaired brackets', () => {
const matchingBrackets = new MatchingBrackets('[[')
expect(matchingBrackets.isPaired()).toBeFalsy()
})

xit('wrong ordered brackets', () => {
const matchingBrackets = new MatchingBrackets('}{')
expect(matchingBrackets.isPaired()).toBeFalsy()
})

xit('wrong closing bracket', () => {
const matchingBrackets = new MatchingBrackets('{]')
expect(matchingBrackets.isPaired()).toBeFalsy()
})

xit('paired with whitespace', () => {
const matchingBrackets = new MatchingBrackets('{ }')
expect(matchingBrackets.isPaired()).toBeTruthy()
})

xit('simple nested brackets', () => {
const matchingBrackets = new MatchingBrackets('{[]}')
expect(matchingBrackets.isPaired()).toBeTruthy()
})

xit('several paired brackets', () => {
const matchingBrackets = new MatchingBrackets('{}[]')
expect(matchingBrackets.isPaired()).toBeTruthy()
})

xit('paired and nested brackets', () => {
const matchingBrackets = new MatchingBrackets('([{}({}[])])')
expect(matchingBrackets.isPaired()).toBeTruthy()
})

xit('unopened closing brackets', () => {
const matchingBrackets = new MatchingBrackets('{[)][]}')
expect(matchingBrackets.isPaired()).toBeFalsy()
})

xit('unpaired and nested brackets', () => {
const matchingBrackets = new MatchingBrackets('([{])')
expect(matchingBrackets.isPaired()).toBeFalsy()
})

xit('paired and wrong nested brackets', () => {
const matchingBrackets = new MatchingBrackets('[({]})')
expect(matchingBrackets.isPaired()).toBeFalsy()
})

xit('math expression', () => {
const matchingBrackets = new MatchingBrackets('(((185 + 223.85) * 15) - 543)/2')
expect(matchingBrackets.isPaired()).toBeTruthy()
})

xit('complex latex expression', () => {
const matchingBrackets = new MatchingBrackets('\\left(\\begin{array}{cc} \\frac{1}{3} & x\\\\ \\mathrm{e}^{x} &... x^2 \\end{array}\\right)')
expect(matchingBrackets.isPaired()).toBeTruthy()
})
})
File renamed without changes.
File renamed without changes.