Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Tests for the Shunting Yard algorithm with parentheses
package io.jacobappleton.compilers.regex
import org.scalatest.FlatSpec
import scala.language.postfixOps
class ShuntingYardTests extends FlatSpec {
it should "when given the Regex a.b|c.d the output should be ab.cd.|" in {
val parser = new ShuntingYard(Map('|' -> 0, '.' -> 1, '*' -> 2))
assert(parser.toPostfix("a.b|c.d") == "ab.cd.|")
}
it should "when given the Regex a.(b|c).d the output should be abc|.d." in {
val parser = new ShuntingYard(Map('|' -> 0, '.' -> 1, '*' -> 2))
assert(parser.toPostfix("a.(b|c).d") == "abc|.d.")
}
it should "when given the regex a.b*.c the output should be ab.*c." in {
val parser = new ShuntingYard(Map('|' -> 0, '.' -> 1, '*' -> 2))
assert(parser.toPostfix("a.b*.c") == "ab*.c.")
}
it should "when given the regex a.b**|c the output should be ab**.c|" in {
val parser = new ShuntingYard(Map('|' -> 0, '.' -> 1, '*' -> 2))
assert(parser.toPostfix("a.b**|c") == "ab**.c|")
}
it should "when given the regex a.b.c.d|e the output should be ab.c.d.e|" in {
val parser = new ShuntingYard(Map('|' -> 0, '.' -> 1, '*' -> 2))
assert(parser.toPostfix("a.b.c.d|e") == "ab.c.d.e|")
}
it should "when given the regex j.a(c|o).b the output should be ja.co|.b." in {
val parser = new ShuntingYard(Map('|' -> 0, '.' -> 1, '*' -> 2))
assert(parser.toPostfix("j.a.(c|o).b") == "ja.co|.b.")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.