Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
unhammer committed May 21, 2015
1 parent ad0cafe commit 5af6b00
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions .merlin
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ S src
B _build/**

PKG cmdliner
PKG qcheck
14 changes: 14 additions & 0 deletions _oasis
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ Executable "find-similar-docs"
CompiledObject: best


Executable "run_qcheck"
Path: tests/
Install: false
CompiledObject: native
Build$: flag(tests)
MainIs: run_qcheck.ml
BuildDepends: wshiml, qcheck

Test all
Command: $run_qcheck
TestTools: run_qcheck
Run$: flag(tests)


AlphaFeatures: ocamlbuild_more_args

Document "wshiml_api"
Expand Down
40 changes: 40 additions & 0 deletions tests/run_qcheck.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

let rem_some threshold =
let open QCheck.Arbitrary in
let rec aux acc =
function
| [] -> return (List.rev acc)
| hd::tl ->
float 1.0 >>= (fun f ->
if f<threshold then aux acc tl
else aux (hd::acc) tl)
in aux []

let pair_rem_some threshold l =
let open QCheck.Arbitrary in
rem_some threshold l >>= (fun l2 -> return (l,l2))

let document = QCheck.Arbitrary.(list ~len:(int_range ~start:700 ~stop:1500) string)

let compare_score blists =
let docs = List.map (Bytes.concat " ") blists in
Wshiml.sketch_docs ~n:3 docs |> Wshiml.score_sketches

let tests = [ QCheck.mk_test ~n:100
~name:"random_docs_differ"
QCheck.Arbitrary.(list_repeat 5 document)
(fun blists ->
let scores = compare_score blists in
List.length scores = 0)
;
QCheck.mk_test ~n:100
~name:"still_similar_after_some_removals"
QCheck.Arbitrary.(document >>= pair_rem_some 0.01)
(fun (l1,l2) ->
let scores = compare_score [l1; l2] in
List.length scores = 1)
]


let () =
QCheck.run_tests tests |> ignore

0 comments on commit 5af6b00

Please sign in to comment.