Created
August 9, 2015 21:18
-
-
Save jacobappleton/324b3b9405a8c21165a4 to your computer and use it in GitHub Desktop.
Tests for the Shunting Yard algorithm with parentheses
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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