Skip to content

Instantly share code, notes, and snippets.

@tracehelms
Created February 20, 2017 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tracehelms/805dff1a6ec8dd9912a972502ea2a8c7 to your computer and use it in GitHub Desktop.
Save tracehelms/805dff1a6ec8dd9912a972502ea2a8c7 to your computer and use it in GitHub Desktop.
Bracket Push Exercism
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
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