Skip to content

Add Pangram Exercise #511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
"topics": [
]
},
{
"slug": "pangram",
"difficulty": 1,
"topics": [
]
},
{
"slug": "run-length-encoding",
"difficulty": 1,
Expand Down
16 changes: 16 additions & 0 deletions exercises/pangram/examples/success-standard/package.yaml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions exercises/pangram/examples/success-standard/src/Pangram.hs
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions exercises/pangram/package.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions exercises/pangram/src/Pangram.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Pangram (isPangram) where

isPangram :: String -> Bool
isPangram text = error "You need to implement this function."
1 change: 1 addition & 0 deletions exercises/pangram/stack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
resolver: lts-8.2
65 changes: 65 additions & 0 deletions exercises/pangram/test/Tests.hs
Original file line number Diff line number Diff line change
@@ -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
}
]