-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathStringsSpec.hs
42 lines (35 loc) · 1.46 KB
/
StringsSpec.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
module Inter.Quora.StringsSpec where
import Test.Hspec
import Test.QuickCheck hiding (shuffle)
import qualified Data.Vector as V
import Data.Random (runRVar, StdRandom(..))
import Data.Random.List (shuffle)
import Inter.Quora.Strings
spec :: Spec
spec = do
describe "First non-repeated character" $ do
it "None in empty string" $
firstUniqueChar "" `shouldBe` Nothing
it "None for string of dups" $
firstUniqueChar "abcabc" `shouldBe` Nothing
it "One at end of string" $
firstUniqueChar "aabbc" `shouldBe` Just 'c'
it "Choses first of multiple possibilities" $
firstUniqueChar "aabc" `shouldBe` Just 'b'
describe "Reversing a vector" $ do
it "doing so with recursion behaves the same as std lib" $ property $ \s ->
let v = V.fromList (s::String) in
revRecursive (v::V.Vector Char) `shouldBe` V.reverse v
it "doing so with mutation behaves the same as std lib" $ property $ \s ->
let v = V.fromList (s::String) in
revIterative (v::V.Vector Char) `shouldBe` V.reverse v
describe "Detecting anagrams" $ do
it "works for a shuffled vector" $ property $ \s -> do
ana <- runRVar (shuffle (s::String)) StdRandom
anagrams s ana `shouldBe` True
it "identifies a non-anagram" $
anagrams "abb" "a" `shouldBe` False
describe "Detecting palindromes" $ do
it "works on crazy things" $ property $ \s ->
let v = V.fromList (s::String) in
palindrome v `shouldBe` (v == V.reverse v)