-
-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bracket-push exercise in Erlang #241
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
Given a string containing brackets `[]`, braces `{}` and parentheses `()`, | ||
verify that all the pairs are matched and nested correctly. | ||
|
||
## Running tests | ||
|
||
In order to run the tests, issue the following command from the exercise | ||
directory: | ||
|
||
For running the tests provided, `rebar3` is used as it is the official build and | ||
dependency management tool for erlang now. Please refer to [the tracks installation | ||
instructions](http://exercism.io/languages/erlang/installation) on how to do that. | ||
|
||
In order to run the tests, you can issue the following command from the exercise | ||
directory. | ||
|
||
```bash | ||
$ rebar3 eunit | ||
``` | ||
|
||
### Test versioning | ||
|
||
Each problem defines a macro `TEST_VERSION` in the test file and | ||
verifies that the solution defines and exports a function `test_version` | ||
returning that same value. | ||
|
||
To make tests pass, add the following to your solution: | ||
|
||
```erlang | ||
-export([test_version/0]). | ||
|
||
test_version() -> | ||
1. | ||
``` | ||
|
||
The benefit of this is that reviewers can see against which test version | ||
an iteration was written if, for example, a previously posted solution | ||
does not solve the current problem or passes current tests. | ||
|
||
## Questions? | ||
|
||
For detailed information about the Erlang track, please refer to the | ||
[help page](http://exercism.io/languages/erlang) on the Exercism site. | ||
This covers the basic information on setting up the development | ||
environment expected by the exercises. | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
%% Erlang compiler options | ||
{erl_opts, [debug_info]}. | ||
|
||
{deps, [{erl_exercism, "0.1.1"}]}. | ||
|
||
{dialyzer, [ | ||
{warnings, [underspecs, no_return]}, | ||
{get_warnings, true}, | ||
{plt_apps, top_level_deps}, % top_level_deps | all_deps | ||
{plt_extra_apps, []}, | ||
{plt_location, local}, % local | "/my/file/name" | ||
{plt_prefix, "rebar3"}, | ||
{base_plt_apps, [stdlib, kernel, crypto]}, | ||
{base_plt_location, global}, % global | "/my/file/name" | ||
{base_plt_prefix, "rebar3"} | ||
]}. | ||
|
||
%% eunit:test(Tests) | ||
{eunit_tests, []}. | ||
%% Options for eunit:test(Tests, Opts) | ||
{eunit_opts, [verbose]}. | ||
|
||
%% == xref == | ||
|
||
{xref_warnings, true}. | ||
|
||
%% xref checks to run | ||
{xref_checks, [undefined_function_calls, undefined_functions, | ||
locals_not_used, exports_not_used, | ||
deprecated_function_calls, deprecated_functions]}. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{application, bracket_push, | ||
[{description, "exercism.io - bracket-push"}, | ||
{vsn, "0.0.1"}, | ||
{modules, []}, | ||
{registered, []}, | ||
{applications, [kernel, | ||
stdlib]}, | ||
{env, []} | ||
]}. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-module(bracket_push). | ||
|
||
-export([is_paired/1, test_version/0]). | ||
|
||
is_paired(Str) -> undefined. | ||
|
||
test_version() -> 1. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
-module(bracket_push). | ||
|
||
-export([is_paired/1, test_version/0]). | ||
|
||
is_paired(Str) -> is_paired(Str, []). | ||
|
||
is_paired([], Stack) -> Stack=:=[]; | ||
is_paired([C|More], Stack) when C=:=${ orelse C=:=$[ orelse C=:=$( -> is_paired(More, [C|Stack]); | ||
is_paired([$}|More], [${|Stack]) -> is_paired(More, Stack); | ||
is_paired([$]|More], [$[|Stack]) -> is_paired(More, Stack); | ||
is_paired([$)|More], [$(|Stack]) -> is_paired(More, Stack); | ||
is_paired([C|_], _) when C=:=$} orelse C=:=$] orelse C=:=$)-> false; | ||
is_paired([_|More], Stack) -> is_paired(More, Stack). | ||
|
||
test_version() -> 1. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
% based on canonical data version 1.3.0 | ||
% https://raw.githubusercontent.com/exercism/problem-specifications/master/exercises/bracket-push/canonical-data.json | ||
|
||
-module(bracket_push_tests). | ||
|
||
-include_lib("erl_exercism/include/exercism.hrl"). | ||
-include_lib("eunit/include/eunit.hrl"). | ||
|
||
paired_square_brackets_test() -> | ||
?assert(bracket_push:is_paired("[]")). | ||
|
||
empty_string_test() -> | ||
?assert(bracket_push:is_paired("")). | ||
|
||
unpaired_brackets_test() -> | ||
?assertNot(bracket_push:is_paired("[[")). | ||
|
||
wrong_ordered_brackets_test() -> | ||
?assertNot(bracket_push:is_paired("}{")). | ||
|
||
wrong_closing_bracket_test() -> | ||
?assertNot(bracket_push:is_paired("{]")). | ||
|
||
paired_with_whitespace_test() -> | ||
?assert(bracket_push:is_paired("{ }")). | ||
|
||
partially_paired_brackets_test() -> | ||
?assertNot(bracket_push:is_paired("{[])")). | ||
|
||
simple_nested_brackets_test() -> | ||
?assert(bracket_push:is_paired("{[]}")). | ||
|
||
several_paired_brackets_test() -> | ||
?assert(bracket_push:is_paired("{}[]")). | ||
|
||
paired_and_nested_brackets_test() -> | ||
?assert(bracket_push:is_paired("([{}({}[])])")). | ||
|
||
unopened_closing_brackets_test() -> | ||
?assertNot(bracket_push:is_paired("{[)][]}")). | ||
|
||
unpaired_and_nested_brackets_test() -> | ||
?assertNot(bracket_push:is_paired("([{])")). | ||
|
||
paired_and_wrong_nested_brackets_test() -> | ||
?assertNot(bracket_push:is_paired("[({]})")). | ||
|
||
math_expression_test() -> | ||
?assert(bracket_push:is_paired("(((185 + 223.85) * 15) - 543)/2")). | ||
|
||
complex_latex_expression_test() -> | ||
?assert(bracket_push:is_paired("\\left(\\begin{array}{cc} \\frac{1}{3} & x\\\\ \\mathrm{e}^{x} &... x^2 \\end{array}\\right)")). | ||
|
||
version_test() -> ?assertMatch(1, bracket_push:test_version()). | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these tests based on the canonical data? If so, could you please specify the exact version of the specification in a comment like this?