Skip to content

Commit

Permalink
Merge pull request #223 from AtelesPaniscus/pangram
Browse files Browse the repository at this point in the history
WIP - reserve #187 - pangram
  • Loading branch information
NobbZ authored Nov 9, 2017
2 parents 5786cfc + 65bd224 commit f017299
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 0 deletions.
10 changes: 10 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@

]
},
{
"uuid": "ceb71cdc-098f-d580-179c-732dd8258f8a76cf2be",
"slug": "pangram",
"core": false,
"unlocked_by": null,
"difficulty": 2,
"topics": [

]
},
{
"uuid": "d3cbfc9a-a495-4bf2-87d0-811d5f71fda6",
"slug": "nucleotide-count",
Expand Down
60 changes: 60 additions & 0 deletions exercises/pangram/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Pangram

Determine if a sentence is a pangram.
A pangram (Greek: παν γράμμα, pan gramma, "every letter") is a sentence using
every letter of the alphabet at least once.
The best known English pangram is:
> The quick brown fox jumps over the lazy dog.
The alphabet used consists of ASCII letters `a` to `z`, inclusive, and is case
insensitive. Input will not contain non-ASCII symbols.

## Source

Wikipedia [https://en.wikipedia.org/wiki/Pangram](https://en.wikipedia.org/wiki/Pangram)

## 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.

## Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.
11 changes: 11 additions & 0 deletions exercises/pangram/include/exercism.hrl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-include_lib("eunit/include/eunit.hrl").

sut(Module) ->
{ok, Files} = file:list_dir("./src"),
case lists:member("example.erl", Files) of
true -> example;
false -> Module
end.

version_test() ->
?assertMatch(?TEST_VERSION, ?TESTED_MODULE:test_version()).
30 changes: 30 additions & 0 deletions exercises/pangram/rebar.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
%% Erlang compiler options
{erl_opts, [debug_info]}.

{deps, []}.

{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]}.
11 changes: 11 additions & 0 deletions exercises/pangram/src/example.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-module(example).

-export([is_pangram/1, test_version/0]).

is_pangram(Sentence) ->
Alpha = "abcdefghijklmnopqrstuvwxyz",
Lower = string:to_lower(Sentence),

lists:all(fun (A) -> lists:any(fun (L) -> A == L end, Lower) end, Alpha).

test_version() -> 1.
9 changes: 9 additions & 0 deletions exercises/pangram/src/pangram.app.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{application, pangram,
[{description, "exercism.io - pangram"},
{vsn, "0.0.1"},
{modules, []},
{registered, []},
{applications, [kernel,
stdlib]},
{env, []}
]}.
8 changes: 8 additions & 0 deletions exercises/pangram/src/pangram.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-module(pangram).

-export([is_pangram/1, test_version/0]).

is_pangram(Sentence) ->
undefined.

test_version() -> 1.
38 changes: 38 additions & 0 deletions exercises/pangram/test/pangram_tests.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
-module(pangram_tests).

-define(TESTED_MODULE, (sut(pangram))).
-define(TEST_VERSION, 1).
-include("exercism.hrl").


% test cases adapted from `x-common//canonical-data.json` @ version: 1.3.0

empty_sentence_test() ->
?assertNot(?TESTED_MODULE:is_pangram("")).

perfect_lower_case_pangram_test() ->
?assert(?TESTED_MODULE:is_pangram("abcdefghijklmnopqrstuvwxyz")).

pangram_with_only_lower_case_test() ->
?assert(?TESTED_MODULE:is_pangram("the quick brown fox jumps over the lazy dog")).

missing_character_x_test() ->
?assertNot(?TESTED_MODULE:is_pangram("a quick movement of the enemy will jeopardize five gunboats")).

missing_character_h_test() ->
?assertNot(?TESTED_MODULE:is_pangram("five boxing wizards jump quickly at it")).

pangram_with_underscores_test() ->
?assert(?TESTED_MODULE:is_pangram("the_quick_brown_fox_jumps_over_the_lazy_dog")).

pangram_with_numbers_test() ->
?assert(?TESTED_MODULE:is_pangram("the 1 quick brown fox jumps over the 2 lazy dogs")).

missing_letters_replaced_by_numbers_test() ->
?assertNot(?TESTED_MODULE:is_pangram("7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog")).

pangram_with_mixed_case_and_punctuation_test() ->
?assert(?TESTED_MODULE:is_pangram("\"Five quacking Zephyrs jolt my wax bed.\"")).

upper_and_lower_case_characters_are_not_counted_separately_test() ->
?assertNot(?TESTED_MODULE:is_pangram("the quick brown fox jumps over with lazy FX")).

0 comments on commit f017299

Please sign in to comment.