Created
June 14, 2012 17:34
-
-
Save eldesh/2931648 to your computer and use it in GitHub Desktop.
QCheck sample solution
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
library | |
structure Sample | |
is | |
$/basis.cm | |
$/qcheck.cm | |
qcheck_sample.sml |
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
$(SML_LIB)/basis/basis.mlb | |
$(QCHECK_LIB)/qcheck.mlb | |
qcheck_sample.sml | |
structure Sample |
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
structure Sample = | |
struct | |
open QCheck infix ==> | |
(* 実装した(テストする)関数 *) | |
fun succ x = x + 1 | |
fun even x = x mod 2 = 0 | |
fun odd x = x mod 2 = 1 | |
(* 満たすべき性質 *) | |
fun even_xor_odd x = even x <> odd x | |
(* 生成する入力の型と (可能なら)toStringを指定 *) | |
val int = (Gen.Int.int, SOME Int.toString) | |
(* チェック *) | |
val _ = checkGen int ("even<>odd", pred even_xor_odd) | |
(* 条件付きの性質をチェック *) | |
val _ = checkGen int ("even+1=odd", even ==> odd o succ) | |
(* 偶奇を逆にした性質 *) | |
val _ = checkGen int ("odd+1=even", odd ==> even o succ) (* 恐らく失敗する *) | |
(* 前提に上限を設定する *) | |
val _ = checkGen int ("odd+1=even", (fn x=>odd x andalso x<valOf(Int.maxInt)) ==> even o succ) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://d.hatena.ne.jp/eldesh/20120615/1339697355 で使ったサンプルコード