diff --git a/config.json b/config.json index dd05d7dac..c8425b289 100644 --- a/config.json +++ b/config.json @@ -28,6 +28,12 @@ "topics": [ ] }, + { + "slug": "pangram", + "difficulty": 1, + "topics": [ + ] + }, { "slug": "run-length-encoding", "difficulty": 1, diff --git a/exercises/pangram/examples/success-standard/package.yaml b/exercises/pangram/examples/success-standard/package.yaml new file mode 100644 index 000000000..0031f5c70 --- /dev/null +++ b/exercises/pangram/examples/success-standard/package.yaml @@ -0,0 +1,16 @@ +name: pangram + +dependencies: + - base + +library: + exposed-modules: Pangram + source-dirs: src + +tests: + test: + main: Tests.hs + source-dirs: test + dependencies: + - pangram + - hspec diff --git a/exercises/pangram/examples/success-standard/src/Pangram.hs b/exercises/pangram/examples/success-standard/src/Pangram.hs new file mode 100644 index 000000000..20f8a2f4d --- /dev/null +++ b/exercises/pangram/examples/success-standard/src/Pangram.hs @@ -0,0 +1,7 @@ +module Pangram (isPangram) where + +import Data.Char (toLower) + +isPangram :: String -> Bool +isPangram xs = all (`elem` fixedText) ['a'..'z'] + where fixedText = map toLower xs diff --git a/exercises/pangram/package.yaml b/exercises/pangram/package.yaml new file mode 100644 index 000000000..9071ec548 --- /dev/null +++ b/exercises/pangram/package.yaml @@ -0,0 +1,19 @@ +name: pangram + +dependencies: + - base + +library: + exposed-modules: Pangram + source-dirs: src + dependencies: + # - foo # List here the packages you + # - bar # want to use in your solution. + +tests: + test: + main: Tests.hs + source-dirs: test + dependencies: + - pangram + - hspec diff --git a/exercises/pangram/src/Pangram.hs b/exercises/pangram/src/Pangram.hs new file mode 100644 index 000000000..49bd3a01a --- /dev/null +++ b/exercises/pangram/src/Pangram.hs @@ -0,0 +1,4 @@ +module Pangram (isPangram) where + +isPangram :: String -> Bool +isPangram text = error "You need to implement this function." diff --git a/exercises/pangram/stack.yaml b/exercises/pangram/stack.yaml new file mode 100644 index 000000000..72bc099fa --- /dev/null +++ b/exercises/pangram/stack.yaml @@ -0,0 +1 @@ +resolver: lts-8.2 diff --git a/exercises/pangram/test/Tests.hs b/exercises/pangram/test/Tests.hs new file mode 100644 index 000000000..1ad70a453 --- /dev/null +++ b/exercises/pangram/test/Tests.hs @@ -0,0 +1,65 @@ +{-# LANGUAGE RecordWildCards #-} + +import Data.Foldable (for_) +import Test.Hspec (Spec, describe, it, shouldBe) +import Test.Hspec.Runner (configFastFail, defaultConfig, hspecWith) + +import Pangram (isPangram) + +main :: IO () +main = hspecWith defaultConfig {configFastFail = True} specs + +specs :: Spec +specs = describe "pangram" $ + describe "isPangram" $ for_ cases test + where + test Case{..} = it description $ isPangram input `shouldBe` expected + +-- Adapted from +-- Source: exercism/x-common/exercises/pangram/canonical-data.json +-- Version: 1.0.0 +-- Date: 2017-03-28. + +data Case = Case { description :: String + , input :: String + , expected :: Bool + } + +cases :: [Case] +cases = [ Case { description = "sentence empty" + , input = "" + , expected = False + } + , Case { description = "pangram with only lower case" + , input = "the quick brown fox jumps over the lazy dog" + , expected = True + } + , Case { description = "missing character 'x'" + , input = "a quick movement of the enemy will jeopardize five gunboats" + , expected = False + } + , Case { description = "another missing character 'x'" + , input = "the quick brown fish jumps over the lazy dog" + , expected = False + } + , Case { description = "pangram with underscores" + , input = "the_quick_brown_fox_jumps_over_the_lazy_dog" + , expected = True + } + , Case { description = "pangram with numbers" + , input = "the 1 quick brown fox jumps over the 2 lazy dogs" + , expected = True + } + , Case { description = "missing letters replaced by numbers" + , input = "7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog" + , expected = False + } + , Case { description = "pangram with mixed case and punctuation" + , input = "\"Five quacking Zephyrs jolt my wax bed.\"" + , expected = True + } + , Case { description = "upper and lower case versions of the same character should not be counted separately" + , input = "the quick brown fox jumped over the lazy FOX" + , expected = False + } + ]