Skip to content

Commit 71012d8

Browse files
committed
Solve 'Oh, so you like programming? Name all of the keywords!' kata
1 parent f9cae56 commit 71012d8

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

src/Keywords.hs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module Keywords (keywords) where
2+
3+
-- https://www.codewars.com/kata/634ac4e77611b9f57dff456d/train/haskell
4+
5+
keywords :: [String]
6+
keywords =
7+
[ "_",
8+
"module",
9+
"where",
10+
"let",
11+
"if",
12+
"else",
13+
"case",
14+
"in",
15+
"infix",
16+
"infixl",
17+
"infixr",
18+
"of",
19+
"import",
20+
"foreign",
21+
"then",
22+
"do",
23+
"default",
24+
"class",
25+
"newtype",
26+
"instance",
27+
"deriving",
28+
"type",
29+
"data"
30+
]

test/KeywordsSpec.hs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
module KeywordsSpec where
2+
3+
import qualified Data.Set as S
4+
import Keywords (keywords)
5+
import Test.Hspec (Spec, it, shouldBe, shouldContain)
6+
import Test.Hspec.Core.Spec (Expectation)
7+
8+
spec :: Spec
9+
spec = do
10+
it "Do you have the correct number of keywords in your list?" $ do
11+
length keywords `shouldBe` 23
12+
it "Missing a word that is used when making a family of methods that can be used with related data types" $ do
13+
keywords `shouldContainAll` ["module", "where"]
14+
it "Missing a conditional word used in pattern matching (first word of a pair)" $ do
15+
keywords `shouldContainAll` ["case"]
16+
it "Missing a word that is used when making a family of methods that can be used with related data types" $ do
17+
keywords `shouldContainAll` ["data", "type", "newtype", "instance", "class"]
18+
it "Missing a word that defines the requirements for an instance to use a fallback method" $ do
19+
keywords `shouldContainAll` ["default"]
20+
it "Missing a word that allows you to write monadic computations in a more imperative style" $ do
21+
keywords `shouldContainAll` ["do"]
22+
it "Missing a conditional word that goes at the end" $ do
23+
keywords `shouldContainAll` ["then", "else"]
24+
it "Missing a word that is used when interfacing with C code" $ do
25+
keywords `shouldContainAll` ["foreign"]
26+
it "Missing a conditional word that determines a possibility" $ do
27+
keywords `shouldContainAll` ["if"]
28+
it "Missing a word used to obtain external modules" $ do
29+
keywords `shouldContainAll` ["import"]
30+
it "Missing a word used when substituting a name for a value (second word of a pair)" $ do
31+
keywords `shouldContainAll` ["in"]
32+
it "Missing a word used for functions that can be used in-between it's arguments" $ do
33+
keywords `shouldContainAll` ["infix"]
34+
it "Missing a word used at the top level that lets other files know what the current one is called" $ do
35+
keywords `shouldContainAll` ["module"]
36+
it "Missing a word used for functions that can be used in-between it's arguments (and can chain together from left-to-right)" $ do
37+
keywords `shouldContainAll` ["infixl"]
38+
it "Missing a word used for functions that can be used in-between it's arguments (and can chain together from right-to-left)" $ do
39+
keywords `shouldContainAll` ["infixr"]
40+
it "Missing a word used as a placeholder for data that you don't care about" $ do
41+
keywords `shouldContainAll` ["_"]
42+
it "Missing a conditional word used in pattern matching (second word of a pair)" $ do
43+
keywords `shouldContainAll` ["of"]
44+
it "Missing a word that saves a lot of boilerplate when defining behavior of new data types" $ do
45+
keywords `shouldContainAll` ["deriving"]
46+
47+
shouldContainAll :: (Show a, Ord a) => [a] -> [a] -> Expectation
48+
shouldContainAll actual expected =
49+
S.fromList expected `S.isSubsetOf` S.fromList actual `shouldBe` True

0 commit comments

Comments
 (0)