@@ -16,11 +16,11 @@ type cmd =
1616 | Find_all of data
1717 | Count
1818 | Stats
19- and data = int64
19+ and data = string
2020
2121let pp_cmd par fmt x =
2222 let open Util.Pp in
23- let pp_data = pp_int64 in
23+ let pp_data = pp_string in
2424 match x with
2525 | Clear -> cst0 " Clear" fmt
2626 | Merge x -> cst1 pp_data " Merge" par fmt x
@@ -37,19 +37,10 @@ let show_cmd = Util.Pp.to_show pp_cmd
3737
3838type state = data list
3939
40- module Int64 =
41- struct
42- [@@@ warning " -unused-value-declaration" ]
43- (* support Int64.hash added in 5.1, without triggering an 'unused hash' error *)
44- external seeded_hash_param :
45- int -> int -> int -> 'a -> int = " caml_hash" [@@ noalloc]
46- let hash x = seeded_hash_param 10 100 0 x
47- include Stdlib. Int64
48- end
49- module WHS = Weak. Make (Int64 )
40+ module WHS = Weak. Make (String )
5041type sut = WHS .t
5142
52- let shrink_data d = Shrink. int64 d
43+ let shrink_data d = Shrink. string ~shrink: Shrink. nil d
5344
5445let _shrink_cmd c = match c with
5546 | Clear -> Iter. empty
@@ -64,14 +55,15 @@ let _shrink_cmd c = match c with
6455 | Stats -> Iter. empty
6556
6657let arb_cmd s =
58+ let string_gen = Gen. (string_small_of printable) in
6759 let data_gen = match s with
68- | [] -> Gen. (map Int64. of_int small_int)
69- | _ ::_ -> Gen. (oneof [oneofl s; map Int64. of_int small_int ]) in
60+ | [] -> string_gen
61+ | _ ::_ -> Gen. (oneof [oneofl s; string_gen ]) in
7062 QCheck. make ~print: show_cmd (* ~shrink:shrink_cmd*)
7163 Gen. (frequency
7264 [ 1 ,return Clear ;
73- 1 ,map (fun d -> Merge d) data_gen;
74- 1 ,map (fun d -> Add d) data_gen;
65+ 2 ,map (fun d -> Merge d) data_gen;
66+ 2 ,map (fun d -> Add d) data_gen;
7567 1 ,map (fun d -> Remove d) data_gen;
7668 1 ,map (fun d -> Find d) data_gen;
7769 1 ,map (fun d -> Find_opt d) data_gen;
@@ -104,8 +96,7 @@ let weak_size = 16
10496let init_sut () = Gc. minor () ; WHS. create weak_size
10597let cleanup _ = ()
10698
107- let precond c _s = match c with
108- | _ -> true
99+ let precond _c _s = true
109100
110101type _ ty + = Tup6 : 'a ty * 'b ty * 'c ty * 'd ty * 'e ty * 'f ty -> ('a * 'b * 'c * 'd * 'e * 'f ) ty
111102
@@ -121,39 +112,35 @@ let tup6 spec_a spec_b spec_c spec_d spec_e spec_f =
121112
122113let run c hs = match c with
123114 | Clear -> Res (unit , WHS. clear hs)
124- | Merge d -> Res (result int64 exn , protect (WHS. merge hs) d )
125- | Add d -> Res (result unit exn , protect (WHS. add hs) d )
126- | Remove d -> Res (result unit exn , protect (WHS. remove hs) d )
127- | Find d -> Res (result int64 exn , protect (WHS. find hs) d )
128- | Find_opt d -> Res (result (option int64 ) exn , protect (WHS. find_opt hs) d )
129- | Find_all d -> Res (result (list int64 ) exn , protect (WHS. find_all hs) d )
130- | Mem d -> Res (result bool exn , protect (WHS. mem hs) d )
115+ | Merge d -> Res (result string exn , protect (fun () -> WHS. merge hs d) () )
116+ | Add d -> Res (result unit exn , protect (fun () -> WHS. add hs d) () )
117+ | Remove d -> Res (result unit exn , protect (fun () -> WHS. remove hs d) () )
118+ | Find d -> Res (result string exn , protect (fun () -> WHS. find hs d) () )
119+ | Find_opt d -> Res (result (option string ) exn , protect (fun () -> WHS. find_opt hs d) () )
120+ | Find_all d -> Res (result (list string ) exn , protect (fun () -> WHS. find_all hs d) () )
121+ | Mem d -> Res (result bool exn , protect (fun () -> WHS. mem hs d) () )
131122 | Count -> Res (int , WHS. count hs)
132123 | Stats -> Res (tup6 int int int int int int , WHS. stats hs)
133124
134125let postcond c (s :data list ) res = match c, res with
135126 | Clear , Res ((Unit,_ ),() ) -> true
136- | Merge d , Res ((Result (Int64 ,Exn),_ ),r ) ->
127+ | Merge d , Res ((Result (String ,Exn),_ ),r ) ->
137128 (match r with
138- | Error e -> e = Invalid_argument " index out of bounds "
129+ | Error _ -> false
139130 | Ok r -> if List. mem d s then r = d else r == d)
140131 | Add _ , Res ((Result (Unit,Exn),_ ),r ) ->
141- r = Error ( Invalid_argument " index out of bounds " ) || r = Ok ()
132+ r = Ok ()
142133 | Remove _ , Res ((Result (Unit,Exn),_ ),r ) ->
143- r = Error (Invalid_argument " index out of bounds" ) || r = Ok ()
144- | Find d , Res ((Result (Int64,Exn),_ ),r ) ->
145- r = Error (Invalid_argument " index out of bounds" ) ||
146- r = Error Not_found ||
147- (List. mem d s && r = Ok d)
148- | Find_opt d , Res ((Result (Option Int64,Exn),_ ),r ) ->
149- r = Error (Invalid_argument " index out of bounds" ) ||
150- r = Ok None || r = Ok (Some d)
151- | Find_all d , Res ((Result (List Int64,Exn),_ ),r ) ->
134+ r = Ok ()
135+ | Find d , Res ((Result (String,Exn),_ ),r ) ->
136+ r = Error Not_found || (List. mem d s && r = Ok d)
137+ | Find_opt d , Res ((Result (Option String,Exn),_ ),r ) ->
138+ r = Ok None || (List. mem d s && r = Ok (Some d))
139+ | Find_all d , Res ((Result (List String,Exn),_ ),r ) ->
152140 (match r with
153- | Error e -> e = Invalid_argument " index out of bounds "
141+ | Error _ -> false
154142 | Ok r -> List. for_all (fun d' -> d' = d) r)
155143 | Mem d , Res ((Result (Bool,Exn),_ ),r ) ->
156- r = Error (Invalid_argument " index out of bounds" ) ||
157144 r = Ok (List. mem d s) || r = Ok false
158145 | Count , Res ((Int,_ ),r ) ->
159146 r < = List. length s
0 commit comments