-
-
Notifications
You must be signed in to change notification settings - Fork 194
/
Tests.hs
81 lines (74 loc) · 3.13 KB
/
Tests.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE OverloadedStrings #-}
import Data.Foldable (for_)
import Data.String (fromString)
import Test.Hspec (Spec, describe, it, shouldBe)
import Test.Hspec.Runner (configFailFast, defaultConfig, hspecWith)
import Pangram (isPangram)
main :: IO ()
main = hspecWith defaultConfig {configFailFast = True} specs
specs :: Spec
specs = describe "isPangram" $ for_ cases test
where
test Case{..} = it description $ isPangram (fromString input) `shouldBe` expected
data Case = Case { description :: String
, input :: String
, expected :: Bool
}
cases :: [Case]
cases = [ Case { description = "with empty sentence"
, input = ""
, expected = False
}
, Case { description = "with perfect lower case"
, input = "abcdefghijklmnopqrstuvwxyz"
, expected = True
}
, Case { description = "with only lower case"
, input = "the quick brown fox jumps over the lazy dog"
, expected = True
}
, Case { description = "with missing character 'x'"
, input = "a quick movement of the enemy will jeopardize five gunboats"
, expected = False
}
, Case { description = "with missing character 'h'"
, input = "five boxing wizards jump quickly at it"
, expected = False
}
, Case { description = "with underscores"
, input = "the_quick_brown_fox_jumps_over_the_lazy_dog"
, expected = True
}
, Case { description = "with numbers"
, input = "the 1 quick brown fox jumps over the 2 lazy dogs"
, expected = True
}
, Case { description = "with missing letters replaced by numbers"
, input = "7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog"
, expected = False
}
, Case { description = "with mixed case and punctuation"
, input = "\"Five quacking Zephyrs jolt my wax bed.\""
, expected = True
}
, Case { description = "with mixed case"
, input = "the quick brown fox jumps over with lazy FX"
, expected = False
}
, Case { description = "with missing character and non-ascii letters"
, input = "abcdefghijklmnopqrstuvwxyÃ"
, expected = False
}
, Case { description = "with additional non-ascii letters"
, input = "abcdefghijklmnopqrstuvwxyzÃ"
, expected = True
}
{-
-- The following test can be enabled for String-based solutions:
, Case { description = "with termination as soon as all letters have occurred"
, input = "abcdefghijklmnopqrstuvwxyz" ++ [undefined]
, expected = True
}
-- -}
]