mirror of
https://github.com/correl/elm.git
synced 2025-03-10 17:00:07 -09:00
Add pangram exercise (closes #24)
This commit is contained in:
parent
153caf22f2
commit
0b3ae4f8b8
6 changed files with 84 additions and 0 deletions
|
@ -7,6 +7,7 @@
|
|||
"problems": [
|
||||
"hello-world",
|
||||
"leap",
|
||||
"pangram",
|
||||
"bob"
|
||||
],
|
||||
"deprecated": [
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
".",
|
||||
"./exercises/hello_world",
|
||||
"./exercises/leap",
|
||||
"./exercises/pangram",
|
||||
"./exercises/bob"
|
||||
],
|
||||
"exposed-modules": [],
|
||||
|
|
1
exercises/pangram/Pangram.elm
Normal file
1
exercises/pangram/Pangram.elm
Normal file
|
@ -0,0 +1 @@
|
|||
module Pangram where
|
17
exercises/pangram/Pangram.example
Normal file
17
exercises/pangram/Pangram.example
Normal file
|
@ -0,0 +1,17 @@
|
|||
module Pangram (..) where
|
||||
|
||||
import String exposing (toLower, contains, fromChar)
|
||||
|
||||
|
||||
isPangram : String -> Bool
|
||||
isPangram sentence =
|
||||
let
|
||||
normalized =
|
||||
toLower sentence
|
||||
in
|
||||
String.all (\c -> contains (fromChar c) normalized) alphabet
|
||||
|
||||
|
||||
alphabet : String
|
||||
alphabet =
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
48
exercises/pangram/PangramTests.elm
Normal file
48
exercises/pangram/PangramTests.elm
Normal file
|
@ -0,0 +1,48 @@
|
|||
module Main (..) where
|
||||
|
||||
import Task
|
||||
import Console
|
||||
import ElmTest exposing (..)
|
||||
import Pangram exposing (isPangram)
|
||||
|
||||
|
||||
tests : Test
|
||||
tests =
|
||||
suite
|
||||
"Pangram"
|
||||
[ test
|
||||
"sentence empty"
|
||||
(assertEqual
|
||||
False
|
||||
(isPangram "")
|
||||
)
|
||||
, test
|
||||
"pangram with only lower case"
|
||||
(assertEqual
|
||||
True
|
||||
(isPangram "the quick brown fox jumps over the lazy dog")
|
||||
)
|
||||
, test
|
||||
"missing character 'x'"
|
||||
(assertEqual
|
||||
False
|
||||
(isPangram "a quick movement of the enemy will jeopardize five gunboats")
|
||||
)
|
||||
, test
|
||||
"pangram with mixed case and punctuation"
|
||||
(assertEqual
|
||||
True
|
||||
(isPangram "\"Five quacking Zephyrs jolt my wax bed.\"")
|
||||
)
|
||||
, test
|
||||
"pangram with non ascii characters"
|
||||
(assertEqual
|
||||
True
|
||||
(isPangram "Victor jagt zwölf Boxkämpfer quer über den großen Sylter Deich.")
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
port runner : Signal (Task.Task x ())
|
||||
port runner =
|
||||
Console.run (consoleRunner tests)
|
16
exercises/pangram/elm-package.json
Normal file
16
exercises/pangram/elm-package.json
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"version": "1.0.0",
|
||||
"summary": "Exercism problems in Elm.",
|
||||
"repository": "https://github.com/exercism/xelm.git",
|
||||
"license": "BSD3",
|
||||
"source-directories": [
|
||||
"."
|
||||
],
|
||||
"exposed-modules": [],
|
||||
"dependencies": {
|
||||
"deadfoxygrandpa/elm-test": "3.0.1 <= v < 4.0.0",
|
||||
"elm-lang/core": "2.0.0 <= v < 4.0.0",
|
||||
"laszlopandy/elm-console": "1.1.0 <= v < 2.0.0"
|
||||
},
|
||||
"elm-version": "0.15.0 <= v < 0.17.0"
|
||||
}
|
Loading…
Add table
Reference in a new issue