mirror of
https://github.com/correl/elm.git
synced 2024-12-22 11:09:08 +00:00
Add etl exercise
This commit is contained in:
parent
eeeab525b9
commit
c3a8a8ec85
7 changed files with 165 additions and 0 deletions
|
@ -219,6 +219,13 @@
|
|||
"difficulty": 1,
|
||||
"topics": [
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
"slug": "etl",
|
||||
"difficulty": 1,
|
||||
"topics": [
|
||||
|
||||
]
|
||||
}
|
||||
],
|
||||
|
|
1
exercises/etl/Etl.elm
Normal file
1
exercises/etl/Etl.elm
Normal file
|
@ -0,0 +1 @@
|
|||
module Etl exposing (transform)
|
15
exercises/etl/Etl.example.elm
Normal file
15
exercises/etl/Etl.example.elm
Normal file
|
@ -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
|
15
exercises/etl/elm-package.json
Normal file
15
exercises/etl/elm-package.json
Normal file
|
@ -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"
|
||||
}
|
||||
|
14
exercises/etl/package.json
Normal file
14
exercises/etl/package.json
Normal file
|
@ -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"
|
||||
}
|
||||
}
|
97
exercises/etl/tests/Tests.elm
Normal file
97
exercises/etl/tests/Tests.elm
Normal file
|
@ -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" ] )
|
||||
]
|
||||
)
|
||||
]
|
16
exercises/etl/tests/elm-package.json
Normal file
16
exercises/etl/tests/elm-package.json
Normal file
|
@ -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"
|
||||
}
|
Loading…
Reference in a new issue