-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b29788
commit 71a51cf
Showing
10 changed files
with
170 additions
and
10 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,5 @@ node_modules/ | |
.github | ||
.gitignore | ||
.gitattributes | ||
/tests/ | ||
/smoke-tests/ |
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 |
---|---|---|
|
@@ -15,3 +15,5 @@ src/main.js | |
.DS_Store | ||
.coverage | ||
/example-output/ | ||
/smoke-tests/*/mapping.json | ||
/smoke-tests/*/representation.txt |
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,28 @@ | ||
#!/usr/bin/env sh | ||
|
||
# Synopsis: | ||
# Test the representer Docker image by running it against a predefined set of | ||
# solutions with an expected output. | ||
# The representer Docker image is built automatically. | ||
|
||
# Output: | ||
# Outputs the diff of the expected representation and mapping against the | ||
# actual representation and mapping generated by the representer. | ||
|
||
# Example: | ||
# ./bin/run-tests-in-docker.sh | ||
|
||
# Build the Docker image | ||
docker build --rm -t exercism/elm-representer . | ||
|
||
# Run the Docker image using the settings mimicking the production environment | ||
docker run \ | ||
--rm \ | ||
--network none \ | ||
--read-only \ | ||
--mount type=bind,source="${PWD}/smoke-tests",destination=/opt/representer/smoke-tests \ | ||
--mount type=tmpfs,destination=/tmp \ | ||
--volume "${PWD}/bin/run-tests.sh:/opt/representer/bin/run-tests.sh" \ | ||
--workdir /opt/representer \ | ||
--entrypoint /opt/representer/bin/run-tests.sh \ | ||
exercism/elm-representer |
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,33 @@ | ||
#!/usr/bin/env sh | ||
|
||
# Synopsis: | ||
# Test the representer by running it against a predefined set of solutions | ||
# with an expected output. | ||
|
||
# Output: | ||
# Outputs the diff of the expected representation and mapping against the | ||
# actual representation and mapping generated by the representer. | ||
|
||
# Example: | ||
# ./bin/run-tests.sh | ||
|
||
exit_code=0 | ||
|
||
# Iterate over all test directories | ||
for test_dir in smoke-tests/*; do | ||
test_dir_name=$(basename "${test_dir}") | ||
test_dir_path=$(realpath "${test_dir}") | ||
|
||
bin/run.sh "${test_dir_name}" "${test_dir_path}" "${test_dir_path}" | ||
|
||
for file in representation.txt mapping.json; do | ||
expected_file="expected_${file}" | ||
echo "${test_dir_name}: comparing ${file} to ${expected_file}" | ||
|
||
if ! diff "${test_dir_path}/${file}" "${test_dir_path}/${expected_file}"; then | ||
exit_code=1 | ||
fi | ||
done | ||
done | ||
|
||
exit ${exit_code} |
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,25 @@ | ||
{ | ||
"authors": [ | ||
"tgecho" | ||
], | ||
"contributors": [ | ||
"nathanielknight", | ||
"parkerl", | ||
"thomchop", | ||
"tuxagon" | ||
], | ||
"files": { | ||
"solution": [ | ||
"src/Anagram.elm" | ||
], | ||
"test": [ | ||
"tests/Tests.elm" | ||
], | ||
"example": [ | ||
".meta/src/Anagram.example.elm" | ||
] | ||
}, | ||
"blurb": "Given a word and a list of possible anagrams, select the correct sublist.", | ||
"source": "Inspired by the Extreme Startup game", | ||
"source_url": "https://github.com/rchatley/extreme_startup" | ||
} |
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,10 @@ | ||
{ | ||
"identifier_1": "filterAnagramsOf", | ||
"identifier_2": "word", | ||
"identifier_3": "sortedLowercaseCharactersMatch", | ||
"identifier_4": "notExactlyTheSameWord", | ||
"identifier_5": "candidate", | ||
"identifier_6": "sortedLowercaseCharacters", | ||
"identifier_7": "word1", | ||
"identifier_8": "word2" | ||
} |
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,19 @@ | ||
module Anagram exposing (..) | ||
import List as List exposing (filter, sort) | ||
import String exposing (toList, toLower) | ||
|
||
identifier_1 : String -> (List String -> List String) | ||
identifier_1 identifier_2 = | ||
List.filter (identifier_3 identifier_2) >> List.filter (identifier_4 identifier_2) | ||
|
||
identifier_3 : String -> (String -> Bool) | ||
identifier_3 identifier_2 identifier_5 = | ||
identifier_6 identifier_2 == identifier_6 identifier_5 | ||
|
||
identifier_4 : String -> (String -> Bool) | ||
identifier_4 identifier_7 identifier_8 = | ||
String.toLower identifier_7 /= String.toLower identifier_8 | ||
|
||
identifier_6 : String -> List Char | ||
identifier_6 = | ||
String.toLower >> String.toList >> List.sort |
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,40 @@ | ||
-- This is a demonstration solution that I use when mentoring, any | ||
-- improvements / comments / suggestions welcome. | ||
|
||
-- I have changed the name of the exported function from `detect` to `filterAnagramsOf`, | ||
-- as I think it describes the intent better. Most times when you are using this module, | ||
-- this name / function definition will tell you all you need to know, and you won't need | ||
-- to read anything else. | ||
|
||
-- If you want to know how the algorithm works (the stipulation that idenitcal words be | ||
-- removed is a debatable point for example) then you only have to read the body of | ||
-- `filterAnaagramsOf`. | ||
|
||
-- So to understand what this does and how it does it there are only 4 lines to read, | ||
-- which I think is powerful. | ||
|
||
-- There is a solution available that uses more point free style | ||
module Anagram exposing (..) | ||
|
||
import List as List exposing (filter, sort) | ||
import String exposing (toList, toLower) | ||
|
||
filterAnagramsOf : String -> List String -> List String | ||
filterAnagramsOf word = | ||
List.filter (sortedLowercaseCharactersMatch word) | ||
>> List.filter (notExactlyTheSameWord word) | ||
|
||
|
||
sortedLowercaseCharactersMatch : String -> String -> Bool | ||
sortedLowercaseCharactersMatch word candidate = | ||
sortedLowercaseCharacters word == sortedLowercaseCharacters candidate | ||
|
||
notExactlyTheSameWord : String -> String -> Bool | ||
notExactlyTheSameWord word1 word2 = | ||
String.toLower word1 /= String.toLower word2 | ||
|
||
sortedLowercaseCharacters : String -> List Char | ||
sortedLowercaseCharacters = | ||
String.toLower | ||
>> String.toList | ||
>> List.sort |