1
ショートバージョン:おいしいクイックチェックでquickCheckAll
機能を使用できますか?おいしいクイックチェックでquickCheckAll関数を使用する
ロングバージョン:
quickCheckAll
関数は、次の例を示しているように、現在のモジュールにprop_
始まる全て特性をテスト:
{-# LANGUAGE TemplateHaskell #-}
module Main where
import Test.QuickCheck (quickCheckAll)
prop_1 :: Int -> Bool
prop_1 x = x + x == 2 * x
prop_2 :: Int -> Int -> Bool
prop_2 x y = x + y == y + x
-- Template Haskell hack to make the following $quickCheckAll work
-- under GHC >= 7.8.
return []
-- All properties as collected by 'quickCheckAll'.
runTests :: IO Bool
runTests = $quickCheckAll
main :: IO()
main = runTests >> return()
一方、IはQuickCheckを使用することができおいしいクイックチェックパッケージを使ったおいしいテストフレームワークで、次の例を示します。
module Main where
import Test.Tasty (defaultMain, testGroup, TestTree)
import qualified Test.Tasty.QuickCheck as QC
prop_1 :: Int -> Bool
prop_1 x = x + x == 2 * x
prop_2 :: Int -> Int -> Bool
prop_2 x y = x + y == y + x
tests :: TestTree
tests = testGroup "Tested by QuickCheck"
[ QC.testProperty "prop_1" prop_1
, QC.testProperty "prop_2" prop_2
]
main :: IO()
main = defaultMain tests
上記の例でquickCheckAll
関数を使用して、を明示的にのQuickCheckとTastyを使用しているすべてのプロパティをリストするのを避けることができますか?
バージョン:上記の例は、GHC 8.2.2、QuickCheck 2.10.1およびtasty-quickcheck 0.9.1を使用してテストされました。