Skip to content

Commit 88ccf15

Browse files
committed
refactor pair_gen generator
1 parent 4d7900e commit 88ccf15

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

src/sys/stm_tests.ml

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,35 +47,36 @@ struct
4747
| Directory d ->
4848
(match Map_names.bindings d.fs_map with
4949
| [] -> Gen.return None
50-
| bindings -> Gen.(oneofl bindings >>= fun (n, sub_fs) ->
51-
Gen.oneof [
52-
Gen.return (Some ([],n));
53-
Gen.map (function None -> Some ([],n)
54-
| Some (path,name) -> Some (n::path,name)) (gen_existing_pair sub_fs)]
55-
)
50+
| bindings ->
51+
Gen.(oneofl bindings >>= fun (n, sub_fs) ->
52+
oneof [
53+
return (Some ([],n));
54+
map (function None -> Some ([],n)
55+
| Some (path,name) -> Some (n::path,name)) (gen_existing_pair sub_fs)]
56+
)
5657
)
5758

58-
let arb_cmd s =
59-
let name_gen = Gen.(oneofl ["aaa" ; "bbb" ; "ccc" ; "ddd" ; "eee"]) in
60-
let path_gen = Gen.oneof [gen_existing_path s; Gen.list_size (Gen.int_bound 5) name_gen] in (* can be empty *)
59+
let name_gen = Gen.oneofl ["aaa" ; "bbb" ; "ccc" ; "ddd" ; "eee"]
60+
let path_gen s = Gen.(oneof [gen_existing_path s; list_size (int_bound 5) name_gen]) (* can be empty *)
61+
let pair_gen s =
6162
let fresh_pair_gen = Gen.(pair (list_size (int_bound 5) name_gen)) name_gen in
62-
let pair_gen =
63-
Gen.(oneof [
64-
fresh_pair_gen;
65-
(gen_existing_pair s >>= function None -> fresh_pair_gen
66-
| Some (p,_) -> map (fun n -> (p,n)) name_gen);
67-
(gen_existing_pair s >>= function None -> fresh_pair_gen
68-
| Some (p,n) -> return (p,n));
69-
]) in
63+
Gen.(oneof [
64+
fresh_pair_gen;
65+
(gen_existing_pair s >>= function None -> fresh_pair_gen
66+
| Some (p,_) -> map (fun n -> (p,n)) name_gen);
67+
(gen_existing_pair s >>= function None -> fresh_pair_gen
68+
| Some (p,n) -> return (p,n));
69+
])
70+
71+
let arb_cmd s =
7072
QCheck.make ~print:show_cmd
71-
Gen.(oneof
72-
[
73-
map (fun path -> File_exists path) path_gen ;
74-
map (fun (path,new_dir_name) -> Mkdir (path, new_dir_name)) pair_gen;
75-
map (fun (path,delete_dir_name) -> Rmdir (path, delete_dir_name)) pair_gen;
76-
map (fun path -> Readdir path) path_gen;
77-
map (fun (path,new_file_name) -> Mkfile (path, new_file_name)) pair_gen;
78-
])
73+
Gen.(oneof [
74+
map (fun path -> File_exists path) (path_gen s);
75+
map (fun (path,new_dir_name) -> Mkdir (path, new_dir_name)) (pair_gen s);
76+
map (fun (path,delete_dir_name) -> Rmdir (path, delete_dir_name)) (pair_gen s);
77+
map (fun path -> Readdir path) (path_gen s);
78+
map (fun (path,new_file_name) -> Mkfile (path, new_file_name)) (pair_gen s);
79+
])
7980

8081
let sandbox_root = "_sandbox"
8182

0 commit comments

Comments
 (0)