Skip to content

Commit

Permalink
Rename bracket-push exercise to matching-brackets. (#609)
Browse files Browse the repository at this point in the history
* Rename bracket-push exercise to matching-brackets.
Refs #607

* Remove unneeded build.properties. Refs #607

* Put pending annotations back in test cases. Refs #607
  • Loading branch information
ricemery authored and ErikSchierboom committed Apr 25, 2019
1 parent 5a2c43e commit 301997c
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 23 deletions.
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
File renamed without changes.
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

0 comments on commit 301997c

Please sign in to comment.