さて、複数のテストケースをセットアップして、最後にグループ化しました。 コードの一部をアップするのを忘れていたので、追加しました
問題は、たとえば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
]