1
exercism fetch haskell nucleotide-count

test/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
{-# OPTIONS_GHC -fno-warn-type-defaults #-}

import Data.Either       (isLeft)
import Data.Map          (fromList)
import Test.Hspec        (Spec, describe, it, shouldBe, shouldSatisfy)
import Test.Hspec.Runner (configFastFail, defaultConfig, hspecWith)

import DNA (nucleotideCounts)

main :: IO ()
main = hspecWith defaultConfig {configFastFail = True} specs

specs :: Spec
specs = do

          let x `matchesMap` y = x `shouldBe` (Right . fromList) y

          describe "nucleotideCounts" $ do

            it "empty dna strand has no nucleotides" $
              nucleotideCounts "" `matchesMap` [ ('A', 0)
                                               , ('C', 0)
                                               , ('G', 0)
                                               , ('T', 0) ]

            it "can count one nucleotide in single-character input" $
              nucleotideCounts "G" `matchesMap` [ ('A', 0)
                                                , ('C', 0)
                                                , ('G', 1)
                                                , ('T', 0) ]

            it "repetitive-sequence-has-only-guanosine" $
              nucleotideCounts "GGGGGGGG" `matchesMap` [ ('A', 0)
                                                       , ('C', 0)
                                                       , ('G', 8)
                                                       , ('T', 0) ]

            it "counts all nucleotides" $
              nucleotideCounts "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC"
              `matchesMap` [ ('A', 20)
                           , ('C', 12)
                           , ('G', 17)
                           , ('T', 21) ]

            it "validates strand" $
              nucleotideCounts "AGXXACT" `shouldSatisfy` isLeft