Add pangram exercise (closes #24)

This commit is contained in:
Erik Simmler 2016-03-13 20:15:06 -04:00
parent 153caf22f2
commit 0b3ae4f8b8
6 changed files with 84 additions and 0 deletions

View file

@ -7,6 +7,7 @@
"problems": [
"hello-world",
"leap",
"pangram",
"bob"
],
"deprecated": [

View file

@ -7,6 +7,7 @@
".",
"./exercises/hello_world",
"./exercises/leap",
"./exercises/pangram",
"./exercises/bob"
],
"exposed-modules": [],

View file

@ -0,0 +1 @@
module Pangram where

View 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"

View 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)

View 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"
}