1
- import Test.HUnit (Assertion , (@=?) , runTestTT , assertFailure , Test (.. ), Counts (.. ))
1
+ import Test.HUnit (Assertion , (@=?) , runTestTT , Test (.. ), Counts (.. ))
2
2
import System.Exit (ExitCode (.. ), exitWith )
3
3
import DNA (count , nucleotideCounts )
4
4
import Data.Map (fromList )
5
- import qualified Control.Exception as E
6
5
7
6
exitProperly :: IO Counts -> IO ()
8
7
exitProperly m = do
9
8
counts <- m
10
9
exitWith $ if failures counts /= 0 || errors counts /= 0 then ExitFailure 1 else ExitSuccess
11
10
12
- assertError :: String -> a -> IO ()
13
- assertError err f =
14
- do r <- E. try (E. evaluate f)
15
- case r of
16
- Left (E. ErrorCall s) | err == s -> return ()
17
- _ -> assertFailure (" expecting error " ++ show err)
18
-
19
11
testCase :: String -> Assertion -> Test
20
12
testCase label assertion = TestLabel label (TestCase assertion)
21
13
@@ -27,29 +19,29 @@ main = exitProperly $ runTestTT $ TestList
27
19
countTests :: [Test ]
28
20
countTests =
29
21
[ testCase " empty dna strand has no adenosine" $
30
- 0 @=? count ' A' " "
22
+ Right 0 @=? count ' A' " "
31
23
, testCase " repetitive cytidine gets counted" $
32
- 5 @=? count ' C' " CCCCC"
24
+ Right 5 @=? count ' C' " CCCCC"
33
25
, testCase " counts only thymidine" $
34
- 1 @=? count ' T' " GGGGGTAACCCGG"
26
+ Right 1 @=? count ' T' " GGGGGTAACCCGG"
35
27
, testCase " validates nucleotides" $
36
- assertError " invalid nucleotide 'X'" $ count ' X' " GACT"
28
+ Left " invalid nucleotide 'X'" @=? count ' X' " GACT"
37
29
, testCase " validates strand" $
38
- assertError " invalid nucleotide 'Y'" $ count ' G' " GACYT"
30
+ Left " invalid nucleotide 'Y'" @=? count ' G' " GACYT"
39
31
]
40
32
41
33
nucleotideCountTests :: [Test ]
42
34
nucleotideCountTests =
43
35
[ testCase " empty dna strand has no nucleotides" $
44
- fromList [(' A' , 0 ), (' T' , 0 ), (' C' , 0 ), (' G' , 0 )] @=?
36
+ Right ( fromList [(' A' , 0 ), (' T' , 0 ), (' C' , 0 ), (' G' , 0 )]) @=?
45
37
nucleotideCounts " "
46
38
, testCase " repetitive-sequence-has-only-guanosine" $
47
- fromList [(' A' , 0 ), (' T' , 0 ), (' C' , 0 ), (' G' , 8 )] @=?
39
+ Right ( fromList [(' A' , 0 ), (' T' , 0 ), (' C' , 0 ), (' G' , 8 )]) @=?
48
40
nucleotideCounts " GGGGGGGG"
49
41
, testCase " counts all nucleotides" $
50
- fromList [(' A' , 20 ), (' T' , 21 ), (' C' , 12 ), (' G' , 17 )] @=?
42
+ Right ( fromList [(' A' , 20 ), (' T' , 21 ), (' C' , 12 ), (' G' , 17 )]) @=?
51
43
nucleotideCounts (" AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAA" ++
52
44
" GAGTGTCTGATAGCAGC" )
53
45
, testCase " validates strand" $
54
- assertError " invalid nucleotide 'P'" $ nucleotideCounts " GPAC"
46
+ Left " invalid nucleotide 'P'" @=? nucleotideCounts " GPAC"
55
47
]
0 commit comments