Skip to content

Instantly share code, notes, and snippets.

@eldesh
Created June 14, 2012 17:34
Show Gist options
  • Save eldesh/2931648 to your computer and use it in GitHub Desktop.
Save eldesh/2931648 to your computer and use it in GitHub Desktop.
QCheck sample solution
library
structure Sample
is
$/basis.cm
$/qcheck.cm
qcheck_sample.sml
$(SML_LIB)/basis/basis.mlb
$(QCHECK_LIB)/qcheck.mlb
qcheck_sample.sml
structure Sample
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
@eldesh
Copy link
Author

eldesh commented Jun 14, 2012

http://d.hatena.ne.jp/eldesh/20120615/1339697355 で使ったサンプルコード

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment