From c3a8a8ec8537e3c1ca66037361689efc07929908 Mon Sep 17 00:00:00 2001 From: Erik Simmler Date: Sun, 28 May 2017 20:41:40 -0400 Subject: [PATCH] Add etl exercise --- config.json | 7 ++ exercises/etl/Etl.elm | 1 + exercises/etl/Etl.example.elm | 15 +++++ exercises/etl/elm-package.json | 15 +++++ exercises/etl/package.json | 14 ++++ exercises/etl/tests/Tests.elm | 97 ++++++++++++++++++++++++++++ exercises/etl/tests/elm-package.json | 16 +++++ 7 files changed, 165 insertions(+) create mode 100644 exercises/etl/Etl.elm create mode 100644 exercises/etl/Etl.example.elm create mode 100644 exercises/etl/elm-package.json create mode 100644 exercises/etl/package.json create mode 100644 exercises/etl/tests/Tests.elm create mode 100644 exercises/etl/tests/elm-package.json diff --git a/config.json b/config.json index 095c381..f580358 100644 --- a/config.json +++ b/config.json @@ -219,6 +219,13 @@ "difficulty": 1, "topics": [ + ] + }, + { + "slug": "etl", + "difficulty": 1, + "topics": [ + ] } ], diff --git a/exercises/etl/Etl.elm b/exercises/etl/Etl.elm new file mode 100644 index 0000000..0883b14 --- /dev/null +++ b/exercises/etl/Etl.elm @@ -0,0 +1 @@ +module Etl exposing (transform) diff --git a/exercises/etl/Etl.example.elm b/exercises/etl/Etl.example.elm new file mode 100644 index 0000000..f7ffdd9 --- /dev/null +++ b/exercises/etl/Etl.example.elm @@ -0,0 +1,15 @@ +module Etl exposing (transform) + +import Dict exposing (Dict) + + +transform : Dict Int (List String) -> Dict String Int +transform input = + Dict.foldl addLetters Dict.empty input + + +addLetters : Int -> List String -> Dict String Int -> Dict String Int +addLetters score letters output = + letters + |> List.map String.toLower + |> List.foldl (\letter output -> Dict.insert letter score output) output diff --git a/exercises/etl/elm-package.json b/exercises/etl/elm-package.json new file mode 100644 index 0000000..8f73600 --- /dev/null +++ b/exercises/etl/elm-package.json @@ -0,0 +1,15 @@ +{ + "version": "3.0.0", + "summary": "Exercism problems in Elm.", + "repository": "https://github.com/exercism/elm.git", + "license": "BSD3", + "source-directories": [ + "." + ], + "exposed-modules": [], + "dependencies": { + "elm-lang/core": "5.0.0 <= v < 6.0.0" + }, + "elm-version": "0.18.0 <= v < 0.19.0" +} + diff --git a/exercises/etl/package.json b/exercises/etl/package.json new file mode 100644 index 0000000..31d6fb3 --- /dev/null +++ b/exercises/etl/package.json @@ -0,0 +1,14 @@ +{ + "description": "Exercism/Elm", + "repository": "https://github.com/exercism/elm.git", + "license": "MIT", + "scripts": { + "postinstall": "elm-package install -y", + "watch": "elm-test --watch", + "test": "elm-test" + }, + "dependencies": { + "elm": "0.18.0", + "elm-test": "0.18.3" + } +} diff --git a/exercises/etl/tests/Tests.elm b/exercises/etl/tests/Tests.elm new file mode 100644 index 0000000..56479bc --- /dev/null +++ b/exercises/etl/tests/Tests.elm @@ -0,0 +1,97 @@ +module Tests exposing (..) + +import Dict +import Etl +import Expect +import Test exposing (..) + + +tests : Test +tests = + describe "Etl.transform" + [ test "a single letter" <| + \() -> + Expect.equal + (Dict.fromList [ ( "a", 1 ) ]) + (Etl.transform <| + Dict.fromList [ ( 1, [ "A" ] ) ] + ) + , skip <| + test "single score with multiple letters" <| + \() -> + Expect.equal + (Dict.fromList + [ ( "a", 1 ) + , ( "e", 1 ) + , ( "i", 1 ) + , ( "o", 1 ) + , ( "u", 1 ) + ] + ) + (Etl.transform <| + Dict.fromList + [ ( 1, [ "A", "E", "I", "O", "U" ] ) + ] + ) + , skip <| + test "multiple scores with multiple letters" <| + \() -> + Expect.equal + (Dict.fromList + [ ( "a", 1 ) + , ( "d", 2 ) + , ( "e", 1 ) + , ( "g", 2 ) + ] + ) + (Etl.transform <| + Dict.fromList + [ ( 1, [ "A", "E" ] ) + , ( 2, [ "D", "G" ] ) + ] + ) + , skip <| + test "multiple scores with differing numbers of letters" <| + \() -> + Expect.equal + (Dict.fromList + [ ( "a", 1 ) + , ( "b", 3 ) + , ( "c", 3 ) + , ( "d", 2 ) + , ( "e", 1 ) + , ( "f", 4 ) + , ( "g", 2 ) + , ( "h", 4 ) + , ( "i", 1 ) + , ( "j", 8 ) + , ( "k", 5 ) + , ( "l", 1 ) + , ( "m", 3 ) + , ( "n", 1 ) + , ( "o", 1 ) + , ( "p", 3 ) + , ( "q", 10 ) + , ( "r", 1 ) + , ( "s", 1 ) + , ( "t", 1 ) + , ( "u", 1 ) + , ( "v", 4 ) + , ( "w", 4 ) + , ( "x", 8 ) + , ( "y", 4 ) + , ( "z", 10 ) + ] + ) + (Etl.transform <| + Dict.fromList + [ ( 1, [ "A", "E", "I", "O", "U", "L", "N", "R", "S", "T" ] ) + , ( 2, [ "D", "G" ] ) + , ( 3, [ "B", "C", "M", "P" ] ) + , ( 4, [ "F", "H", "V", "W", "Y" ] ) + , ( 5, [ "K" ] ) + , ( 8, [ "J", "X" ] ) + , ( 10, [ "Q", "Z" ] ) + ] + ) + ] diff --git a/exercises/etl/tests/elm-package.json b/exercises/etl/tests/elm-package.json new file mode 100644 index 0000000..3e92515 --- /dev/null +++ b/exercises/etl/tests/elm-package.json @@ -0,0 +1,16 @@ +{ + "version": "3.0.0", + "summary": "Exercism problems in Elm.", + "repository": "https://github.com/exercism/elm.git", + "license": "BSD3", + "source-directories": [ + ".", + ".." + ], + "exposed-modules": [], + "dependencies": { + "elm-lang/core": "5.0.0 <= v < 6.0.0", + "elm-community/elm-test": "4.0.0 <= v < 5.0.0" + }, + "elm-version": "0.18.0 <= v < 0.19.0" +}