mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
some more tests
This commit is contained in:
parent
b202db7049
commit
c2931edb4e
4 changed files with 99 additions and 0 deletions
|
|
@ -30,6 +30,9 @@ let suite =
|
|||
let props =
|
||||
QCheck.flatten
|
||||
[ Test_PersistentHashtbl.props
|
||||
; Test_BV.props
|
||||
; Test_bencode.props
|
||||
; Test_vector.props
|
||||
]
|
||||
|
||||
let _ =
|
||||
|
|
|
|||
25
tests/test_BV.ml
Normal file
25
tests/test_BV.ml
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
|
||||
open QCheck
|
||||
|
||||
let check_create_cardinal =
|
||||
let gen = Arbitrary.small_int in
|
||||
let prop n = BV.cardinal (BV.create ~size:n true) = n in
|
||||
let name = "bv_create_cardinal" in
|
||||
mk_test ~name ~pp:string_of_int gen prop
|
||||
|
||||
let pp bv = PP.(list string) (List.map string_of_int (BV.to_list bv))
|
||||
|
||||
let check_iter_true =
|
||||
let gen = Arbitrary.(lift BV.of_list (list small_int)) in
|
||||
let prop bv =
|
||||
let l' = Sequence.to_rev_list (BV.iter_true bv) in
|
||||
let bv' = BV.of_list l' in
|
||||
BV.cardinal bv = BV.cardinal bv'
|
||||
in
|
||||
let name = "bv_iter_true" in
|
||||
mk_test ~pp ~size:BV.cardinal ~name gen prop
|
||||
|
||||
let props =
|
||||
[ check_create_cardinal
|
||||
; check_iter_true
|
||||
]
|
||||
|
|
@ -44,3 +44,27 @@ let suite =
|
|||
"test2" >:: test2;
|
||||
"test3" >:: test3;
|
||||
]
|
||||
|
||||
open QCheck
|
||||
|
||||
let check_decode_encode =
|
||||
let gen = Arbitrary.(
|
||||
let base = choose
|
||||
[ lift (fun i -> B.I i) small_int
|
||||
; lift (fun s -> B.S s) string
|
||||
]
|
||||
in
|
||||
fix ~max:3 ~base (fun sub ->
|
||||
choose
|
||||
[ lift B.dict_of_list (list (pair string sub))
|
||||
; lift (fun l -> B.L l) (list sub)
|
||||
; sub
|
||||
]))
|
||||
in
|
||||
let prop b = B.eq (B.of_string (B.to_string b)) b in
|
||||
let name = "bencode_decode_encode_bij" in
|
||||
mk_test ~name gen prop
|
||||
|
||||
let props =
|
||||
[ check_decode_encode
|
||||
]
|
||||
|
|
|
|||
|
|
@ -43,3 +43,50 @@ let suite =
|
|||
"test_copy" >:: test_copy;
|
||||
"test_shrink" >:: test_shrink;
|
||||
]
|
||||
|
||||
open QCheck
|
||||
module V = Vector
|
||||
|
||||
let gen sub = Arbitrary.(lift V.from_list (list sub))
|
||||
let pp v = PP.(list string) (List.map string_of_int (V.to_list v))
|
||||
|
||||
let check_append =
|
||||
let gen = Arbitrary.(pair (gen small_int) (gen small_int)) in
|
||||
let prop (v1, v2) =
|
||||
let l1 = V.to_list v1 in
|
||||
V.append v1 v2;
|
||||
Sequence.to_list (V.to_seq v1) =
|
||||
Sequence.(to_list (append (of_list l1) (V.to_seq v2)))
|
||||
in
|
||||
let name = "vector_append" in
|
||||
mk_test ~name ~pp:PP.(pair pp pp) gen prop
|
||||
|
||||
let check_sort =
|
||||
let gen = Arbitrary.(gen small_int) in
|
||||
let prop v =
|
||||
let v' = V.copy v in
|
||||
V.sort v';
|
||||
let l = V.to_list v' in
|
||||
List.sort compare l = l
|
||||
in
|
||||
let name = "vector_sort" in
|
||||
mk_test ~name ~pp gen prop
|
||||
|
||||
let check_shrink =
|
||||
let gen = Arbitrary.(gen small_int) in
|
||||
let prop v =
|
||||
let n = V.size v / 2 in
|
||||
let l = V.to_list v in
|
||||
let h = Sequence.(to_list (take n (of_list l))) in
|
||||
let v' = V.copy v in
|
||||
V.shrink v' n;
|
||||
h = V.to_list v'
|
||||
in
|
||||
let name = "vector_shrink" in
|
||||
mk_test ~name ~pp gen prop
|
||||
|
||||
let props =
|
||||
[ check_append
|
||||
; check_sort
|
||||
; check_shrink
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue