好的,所以我设置了多个测试用例,然后最后将它们组合在一起。 忘记放一些代码,所以我添加了它
问题是,例如,当我输入Main>tests 1 时,会显示正确答案,但是如果我尝试单独运行测试用例,例如main>test0 ,我的输出将变为“TestCase _”
或main>Alltests我的输出是“ TestList [TestLabel test1 TestCase _,TestLabel test0 TestCase _,TestLabel test7 TestCase _,TestLabel est51 TestCase _]”
我的问题是是什么导致了 _ 以及为什么它不能识别测试用例
assertException :: (Exception e, Eq e) => e -> IO a -> IO ()
assertException ex action =
handleJust isWanted (const $ return ()) $ do
action
assertFailure $ "Expected exception: " ++ show ex
where isWanted = guard . (== ex)
assertError ex f =
assertException (ErrorCall ex) $ evaluate f
tests :: Integer -> [Integer]
tests n | n == 0 = error "Not positive"
| n == 1 = [1]
| (n `div` 2 == 0) = n:tests(n*2)
| otherwise = n:tests(3*n)
test0 =
TestCase ( assertError
"tests 0"
( tests 0 )
)
test7 =
TestCase ( assertEqual
"tests 7"
[7,18,9]
( tests 7 )
)
test51 =
TestCase ( assertEqual
[9,8,9]
"tests 51"
( tests 51 )
)
alltests =
TestList [
-- TestLabel "test1" test1
TestLabel "test0" test0
, TestLabel "test7" test7
, TestLabel "test51"test51
]