Created
February 20, 2017 15:32
-
-
Save tracehelms/805dff1a6ec8dd9912a972502ea2a8c7 to your computer and use it in GitHub Desktop.
Bracket Push Exercism
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
defmodule BracketPush do | |
@doc """ | |
Checks that all the brackets and braces in the string are matched correctly, and nested correctly | |
""" | |
@spec check_brackets(String.t) :: boolean | |
def check_brackets(str) do | |
end | |
end |
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
ExUnit.start | |
ExUnit.configure exclude: :pending, trace: true | |
defmodule BracketPushTest do | |
use ExUnit.Case | |
# @tag :pending | |
test "empty string" do | |
assert BracketPush.check_brackets("") | |
end | |
@tag :pending | |
test "appropriate bracketing in a set of brackets" do | |
assert BracketPush.check_brackets("{}") | |
end | |
@tag :pending | |
test "unclosed brackets" do | |
refute BracketPush.check_brackets("{{") | |
end | |
@tag :pending | |
test "more than one pair of brackets" do | |
assert BracketPush.check_brackets("{}[]") | |
end | |
@tag :pending | |
test "brackets are out of order" do | |
refute BracketPush.check_brackets("}{") | |
end | |
@tag :pending | |
test "nested brackets" do | |
assert BracketPush.check_brackets("{[()]}") | |
end | |
@tag :pending | |
test "unbalanced nested brackets" do | |
refute BracketPush.check_brackets("{[}]") | |
end | |
@tag :pending | |
test "bracket closure with deeper nesting" do | |
refute BracketPush.check_brackets("{[)][]}") | |
end | |
@tag :pending | |
test "bracket closure in a long string of brackets" do | |
assert BracketPush.check_brackets("{[]([()])}") | |
end | |
@tag :pending | |
test "should ignore non-bracket characters" do | |
assert BracketPush.check_brackets("{hello[]([a()])b}c") | |
end | |
@tag :pending | |
test "string with newlines" do | |
assert BracketPush.check_brackets("[]\n{()}\n[(({}))]\n") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment