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. #609

Merged
merged 3 commits into from
Apr 25, 2019
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 @@ -665,7 +665,7 @@
]
},
{
"slug": "bracket-push",
"slug": "matching-brackets",
"uuid": "9d25bf46-52d6-435e-a384-38c25517f8ee",
"core": false,
"unlocked_by": "hello-world",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Bracket Push
# Matching Brackets

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.

The Scala exercises assume an SBT project scheme. The exercise solution source
should be placed within the exercise directory/src/main/scala. The exercise
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import scala.util.parsing.combinator.RegexParsers

object BracketPush extends RegexParsers {
object MatchingBrackets extends RegexParsers {
lazy val t = "[^\\[\\]\\(\\)\\{\\}]+".r

private def paren: Parser[String] =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,80 +1,80 @@
import org.scalatest.{Matchers, FunSuite}

/** @version 1.3.0 */
class BracketPushTest extends FunSuite with Matchers {
class MatchingBracketsTest extends FunSuite with Matchers {

test("paired square brackets") {
BracketPush.isPaired("[]") should be(true)
MatchingBrackets.isPaired("[]") should be(true)
}

test("empty string") {
pending
BracketPush.isPaired("") should be(true)
MatchingBrackets.isPaired("") should be(true)
}

test("unpaired brackets") {
pending
BracketPush.isPaired("[[") should be(false)
MatchingBrackets.isPaired("[[") should be(false)
}

test("wrong ordered brackets") {
pending
BracketPush.isPaired("}{") should be(false)
MatchingBrackets.isPaired("}{") should be(false)
}

test("wrong closing bracket") {
pending
BracketPush.isPaired("{]") should be(false)
MatchingBrackets.isPaired("{]") should be(false)
}

test("paired with whitespace") {
pending
BracketPush.isPaired("{ }") should be(true)
MatchingBrackets.isPaired("{ }") should be(true)
}

test("partially paired brackets") {
pending
BracketPush.isPaired("{[])") should be(false)
MatchingBrackets.isPaired("{[])") should be(false)
}

test("simple nested brackets") {
pending
BracketPush.isPaired("{[]}") should be(true)
MatchingBrackets.isPaired("{[]}") should be(true)
}

test("several paired brackets") {
pending
BracketPush.isPaired("{}[]") should be(true)
MatchingBrackets.isPaired("{}[]") should be(true)
}

test("paired and nested brackets") {
pending
BracketPush.isPaired("([{}({}[])])") should be(true)
MatchingBrackets.isPaired("([{}({}[])])") should be(true)
}

test("unopened closing brackets") {
pending
BracketPush.isPaired("{[)][]}") should be(false)
MatchingBrackets.isPaired("{[)][]}") should be(false)
}

test("unpaired and nested brackets") {
pending
BracketPush.isPaired("([{])") should be(false)
MatchingBrackets.isPaired("([{])") should be(false)
}

test("paired and wrong nested brackets") {
pending
BracketPush.isPaired("[({]})") should be(false)
MatchingBrackets.isPaired("[({]})") should be(false)
}

test("math expression") {
pending
BracketPush.isPaired("(((185 + 223.85) * 15) - 543)/2") should be(true)
MatchingBrackets.isPaired("(((185 + 223.85) * 15) - 543)/2") should be(true)
}

test("complex latex expression") {
pending
BracketPush.isPaired(
MatchingBrackets.isPaired(
"""\left(\begin{array}{cc} \frac{1}{3} & x\ \mathrm{e}^{x} &... x^2 \end{array}\right)""") should be(
true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import java.io.File
import testgen.TestSuiteBuilder._
import testgen._

object BracketPushTestGenerator {
object MatchingBracketsTestGenerator {
def main(args: Array[String]): Unit = {
val file = new File("src/main/resources/bracket-push.json")
val file = new File("src/main/resources/matching-brackets.json")

val code = TestSuiteBuilder.build(file, fromLabeledTestFromInput("value"))
println(s"-------------")
Expand Down