Created
October 6, 2013 12:54
-
-
Save ikedaisuke/6853730 to your computer and use it in GitHub Desktop.
"^a$z" は数万回テスト回したんですが見つけられませんでした…犬も歩けば棒にあたる式テストで反例を探しています。正規表現に関する知識は一切実装していません。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- a lightweight pxeger with QuickCheck2 in Haskell | |
-- usage: | |
-- 1) find an example which satisfies the regex "a": | |
-- ghci> check (mkRegex "a") | |
-- *** Failed! Falsifiable (after 50 tests and 5 shrinks): | |
-- "a" | |
-- check tries at most 100 tests. here, we found within 50 tests. | |
-- 2) search more instances with the regex "a.b" | |
-- ghci> checkDeep 1000 (mkRegex "a.b") | |
-- *** Failed! Falsifiable (after 316 tests and 7 shrinks): | |
-- "aab" | |
-- see also the original: | |
-- https://github.com/leque/Gauche-pxeger | |
import Test.QuickCheck | |
import Text.Regex | |
-- the test which may not be satisfied with | |
test :: Regex -> String -> Bool | |
test r = ¥s -> matchRegex r s == Nothing | |
-- poor man's tester for matching with at most 100 tests | |
check :: Regex -> IO () | |
check = quickCheck . test | |
-- the default of n in QuickCheck equals 100. | |
-- use checkDeep at your own lisk! (Hint: type ^C to terminate) | |
checkDeep :: Int -> Regex -> IO () | |
checkDeep n = quickCheckWith args . test | |
where -- tuned arguments for QuickCheck2 | |
args :: Args | |
args = stdArgs { maxSuccess = n | |
, maxSize = maxSuccess args } | |
debug :: Regex -> IO Result | |
debug = quickCheckResult . test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment