Skip to content

Commit cffcb6b

Browse files
authored
Merge pull request #181 from vch9/tups
Add tup2 to tup9 for Gen
2 parents 7787b6e + c830129 commit cffcb6b

File tree

9 files changed

+1218
-108
lines changed

9 files changed

+1218
-108
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changes
22

3+
## 0.19
4+
5+
- add tup2 to tup9 for generators
6+
37
## 0.18
48

59
This releases marks the addition of `QCheck2`, a module where generation

src/core/QCheck.ml

Lines changed: 351 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,28 @@ let _opt_map_4 ~f a b c d = match a, b, c, d with
4242
| Some x, Some y, Some z, Some w -> Some (f x y z w)
4343
| _ -> None
4444

45+
let _opt_map_5 ~f a b c d e = match a, b, c, d, e with
46+
| Some x, Some y, Some z, Some u, Some v -> Some (f x y z u v)
47+
| _ -> None
48+
49+
let _opt_map_6 ~f a b c d e g = match a, b, c, d, e, g with
50+
| Some a, Some b, Some c, Some d, Some e, Some g -> Some (f a b c d e g)
51+
| _ -> None
52+
53+
let _opt_map_7 ~f a b c d e g h = match a, b, c, d, e, g, h with
54+
| Some a, Some b, Some c, Some d, Some e, Some g, Some h -> Some (f a b c d e g h)
55+
| _ -> None
56+
57+
let _opt_map_8 ~f a b c d e g h i = match a, b, c, d, e, g, h, i with
58+
| Some a, Some b, Some c, Some d, Some e, Some g, Some h, Some i ->
59+
Some (f a b c d e g h i)
60+
| _ -> None
61+
62+
let _opt_map_9 ~f a b c d e g h i j = match a, b, c, d, e, g, h, i, j with
63+
| Some a, Some b, Some c, Some d, Some e, Some g, Some h, Some i, Some j ->
64+
Some (f a b c d e g h i j)
65+
| _ -> None
66+
4567
let _opt_sum a b = match a, b with
4668
| Some _, _ -> a
4769
| None, _ -> b
@@ -283,6 +305,27 @@ module Gen = struct
283305

284306
let char st = char_of_int (RS.int st 256)
285307

308+
let tup2 = pair
309+
310+
let tup3 = triple
311+
312+
let tup4 = quad
313+
314+
let tup5 (g1 : 'a t) (g2 : 'b t) (g3 : 'c t) (g4 : 'd t) (g5 : 'e t) : ('a * 'b * 'c * 'd * 'e) t =
315+
(fun a b c d e -> (a, b, c, d, e)) <$> g1 <*> g2 <*> g3 <*> g4 <*> g5
316+
317+
let tup6 (g1 : 'a t) (g2 : 'b t) (g3 : 'c t) (g4 : 'd t) (g5 : 'e t) (g6 : 'f t) : ('a * 'b * 'c * 'd * 'e * 'f) t =
318+
(fun a b c d e f -> (a, b, c, d, e, f)) <$> g1 <*> g2 <*> g3 <*> g4 <*> g5 <*> g6
319+
320+
let tup7 (g1 : 'a t) (g2 : 'b t) (g3 : 'c t) (g4 : 'd t) (g5 : 'e t) (g6 : 'f t) (g7 : 'g t) : ('a * 'b * 'c * 'd * 'e * 'f * 'g) t =
321+
(fun a b c d e f g -> (a, b, c, d, e, f, g)) <$> g1 <*> g2 <*> g3 <*> g4 <*> g5 <*> g6 <*> g7
322+
323+
let tup8 (g1 : 'a t) (g2 : 'b t) (g3 : 'c t) (g4 : 'd t) (g5 : 'e t) (g6 : 'f t) (g7 : 'g t) (g8 : 'h t) : ('a * 'b * 'c * 'd * 'e * 'f * 'g * 'h) t =
324+
(fun a b c d e f g h -> (a, b, c, d, e, f, g, h)) <$> g1 <*> g2 <*> g3 <*> g4 <*> g5 <*> g6 <*> g7 <*> g8
325+
326+
let tup9 (g1 : 'a t) (g2 : 'b t) (g3 : 'c t) (g4 : 'd t) (g5 : 'e t) (g6 : 'f t) (g7 : 'g t) (g8 : 'h t) (g9 : 'i t) : ('a * 'b * 'c * 'd * 'e * 'f * 'g * 'h * 'i) t =
327+
(fun a b c d e f g h i -> (a, b, c, d, e, f, g, h, i)) <$> g1 <*> g2 <*> g3 <*> g4 <*> g5 <*> g6 <*> g7 <*> g8 <*> g9
328+
286329
let printable_chars =
287330
let l = 126-32+1 in
288331
let s = Bytes.create l in
@@ -404,6 +447,121 @@ module Print = struct
404447
let quad a b c d (x,y,z,w) =
405448
Printf.sprintf "(%s, %s, %s, %s)" (a x) (b y) (c z) (d w)
406449

450+
let default = fun _ -> "<no printer>"
451+
452+
let tup2 p_a p_b (a, b) =
453+
Printf.sprintf "(%s, %s)" (p_a a) (p_b b)
454+
455+
let tup2_opt p_a p_b (a, b) =
456+
let p_a = Option.value ~default p_a in
457+
let p_b = Option.value ~default p_b in
458+
tup2 p_a p_b (a, b)
459+
460+
let tup3 p_a p_b (p_c) (a, b, c) =
461+
Printf.sprintf "(%s, %s, %s)" (p_a a) (p_b b) (p_c c)
462+
463+
let tup3_opt p_a p_b p_c (a, b, c) =
464+
let p_a = Option.value ~default p_a in
465+
let p_b = Option.value ~default p_b in
466+
let p_c = Option.value ~default p_c in
467+
tup3 p_a p_b p_c (a, b, c)
468+
469+
let tup4 p_a p_b p_c p_d (a, b, c, d) =
470+
Printf.sprintf "(%s, %s, %s, %s)"
471+
(p_a a) (p_b b)
472+
(p_c c) (p_d d)
473+
474+
let tup4_opt p_a p_b p_c p_d (a, b, c, d) =
475+
let p_a = Option.value ~default p_a in
476+
let p_b = Option.value ~default p_b in
477+
let p_c = Option.value ~default p_c in
478+
let p_d = Option.value ~default p_d in
479+
tup4 p_a p_b p_c p_d (a, b, c, d)
480+
481+
let tup5 p_a p_b p_c p_d p_e (a, b, c, d, e) =
482+
Printf.sprintf "(%s, %s, %s, %s, %s)"
483+
(p_a a) (p_b b)
484+
(p_c c) (p_d d)
485+
(p_e e)
486+
487+
let tup5_opt p_a p_b p_c p_d p_e (a, b, c, d, e) =
488+
let p_a = Option.value ~default p_a in
489+
let p_b = Option.value ~default p_b in
490+
let p_c = Option.value ~default p_c in
491+
let p_d = Option.value ~default p_d in
492+
let p_e = Option.value ~default p_e in
493+
tup5 p_a p_b p_c p_d p_e (a, b, c, d, e)
494+
495+
let tup6 p_a p_b p_c p_d p_e p_f (a, b, c, d, e, f) =
496+
Printf.sprintf "(%s, %s, %s, %s, %s, %s)"
497+
(p_a a) (p_b b)
498+
(p_c c) (p_d d)
499+
(p_e e) (p_f f)
500+
501+
let tup6_opt p_a p_b p_c p_d p_e p_f (a, b, c, d, e, f) =
502+
let p_a = Option.value ~default p_a in
503+
let p_b = Option.value ~default p_b in
504+
let p_c = Option.value ~default p_c in
505+
let p_d = Option.value ~default p_d in
506+
let p_e = Option.value ~default p_e in
507+
let p_f = Option.value ~default p_f in
508+
tup6 p_a p_b p_c p_d p_e p_f (a, b, c, d, e, f)
509+
510+
let tup7 p_a p_b p_c p_d p_e p_f p_g (a, b, c, d, e, f, g) =
511+
Printf.sprintf "(%s, %s, %s, %s, %s, %s, %s)"
512+
(p_a a) (p_b b)
513+
(p_c c) (p_d d)
514+
(p_e e) (p_f f)
515+
(p_g g)
516+
517+
let tup7_opt p_a p_b p_c p_d p_e p_f p_g (a, b, c, d, e, f, g) =
518+
let p_a = Option.value ~default p_a in
519+
let p_b = Option.value ~default p_b in
520+
let p_c = Option.value ~default p_c in
521+
let p_d = Option.value ~default p_d in
522+
let p_e = Option.value ~default p_e in
523+
let p_f = Option.value ~default p_f in
524+
let p_g = Option.value ~default p_g in
525+
tup7 p_a p_b p_c p_d p_e p_f p_g (a, b, c, d, e, f, g)
526+
527+
let tup8 p_a p_b p_c p_d p_e p_f p_g p_h (a, b, c, d, e, f, g, h) =
528+
Printf.sprintf "(%s, %s, %s, %s, %s, %s, %s, %s)"
529+
(p_a a) (p_b b)
530+
(p_c c) (p_d d)
531+
(p_e e) (p_f f)
532+
(p_g g) (p_h h)
533+
534+
let tup8_opt p_a p_b p_c p_d p_e p_f p_g p_h (a, b, c, d, e, f, g, h) =
535+
let p_a = Option.value ~default p_a in
536+
let p_b = Option.value ~default p_b in
537+
let p_c = Option.value ~default p_c in
538+
let p_d = Option.value ~default p_d in
539+
let p_e = Option.value ~default p_e in
540+
let p_f = Option.value ~default p_f in
541+
let p_g = Option.value ~default p_g in
542+
let p_h = Option.value ~default p_h in
543+
tup8 p_a p_b p_c p_d p_e p_f p_g p_h (a, b, c, d, e, f, g, h)
544+
545+
let tup9 p_a p_b p_c p_d p_e p_f p_g p_h p_i (a, b, c, d, e, f, g, h, i) =
546+
Printf.sprintf "(%s, %s, %s, %s, %s, %s, %s, %s, %s)"
547+
(p_a a) (p_b b)
548+
(p_c c) (p_d d)
549+
(p_e e) (p_f f)
550+
(p_g g) (p_h h)
551+
(p_i i)
552+
553+
let tup9_opt p_a p_b p_c p_d p_e p_f p_g p_h p_i (a, b, c, d, e, f, g, h, i) =
554+
let p_a = Option.value ~default p_a in
555+
let p_b = Option.value ~default p_b in
556+
let p_c = Option.value ~default p_c in
557+
let p_d = Option.value ~default p_d in
558+
let p_e = Option.value ~default p_e in
559+
let p_f = Option.value ~default p_f in
560+
let p_g = Option.value ~default p_g in
561+
let p_h = Option.value ~default p_h in
562+
let p_i = Option.value ~default p_i in
563+
tup9 p_a p_b p_c p_d p_e p_f p_g p_h p_i (a, b, c, d, e, f, g, h, i)
564+
407565
let list pp l =
408566
let b = Buffer.create 25 in
409567
Buffer.add_char b '[';
@@ -613,6 +771,127 @@ module Shrink = struct
613771
b y (fun y' -> yield (x,y',z,w));
614772
c z (fun z' -> yield (x,y,z',w));
615773
d w (fun w' -> yield (x,y,z,w'))
774+
775+
let default = nil
776+
777+
let tup2 = pair
778+
779+
let tup2_opt a b =
780+
let a = Option.value ~default a in
781+
let b = Option.value ~default b in
782+
tup2 a b
783+
784+
let tup3 = triple
785+
786+
let tup3_opt a b c =
787+
let a = Option.value ~default a in
788+
let b = Option.value ~default b in
789+
let c = Option.value ~default c in
790+
tup3 a b c
791+
792+
let tup4 = quad
793+
794+
let tup4_opt a b c d =
795+
let a = Option.value ~default a in
796+
let b = Option.value ~default b in
797+
let c = Option.value ~default c in
798+
let d = Option.value ~default d in
799+
tup4 a b c d
800+
801+
let tup5 a b c d e (a', b', c', d', e') yield =
802+
a a' (fun x -> yield (x,b',c',d',e'));
803+
b b' (fun x -> yield (a',x,c',d',e'));
804+
c c' (fun x -> yield (a',b',x,d',e'));
805+
d d' (fun x -> yield (a',b',c',x,e'));
806+
e e' (fun x -> yield (a',b',c',d',x))
807+
808+
let tup5_opt a b c d e =
809+
let a = Option.value ~default a in
810+
let b = Option.value ~default b in
811+
let c = Option.value ~default c in
812+
let d = Option.value ~default d in
813+
let e = Option.value ~default e in
814+
tup5 a b c d e
815+
816+
let tup6 a b c d e f (a', b', c', d', e', f') yield =
817+
a a' (fun x -> yield (x,b',c',d',e',f'));
818+
b b' (fun x -> yield (a',x,c',d',e',f'));
819+
c c' (fun x -> yield (a',b',x,d',e',f'));
820+
d d' (fun x -> yield (a',b',c',x,e',f'));
821+
e e' (fun x -> yield (a',b',c',d',x,f'));
822+
f f' (fun x -> yield (a',b',c',d',e',x))
823+
824+
let tup6_opt a b c d e f =
825+
let a = Option.value ~default a in
826+
let b = Option.value ~default b in
827+
let c = Option.value ~default c in
828+
let d = Option.value ~default d in
829+
let e = Option.value ~default e in
830+
let f = Option.value ~default f in
831+
tup6 a b c d e f
832+
833+
let tup7 a b c d e f g (a', b', c', d', e', f', g') yield =
834+
a a' (fun x -> yield (x,b',c',d',e',f',g'));
835+
b b' (fun x -> yield (a',x,c',d',e',f',g'));
836+
c c' (fun x -> yield (a',b',x,d',e',f',g'));
837+
d d' (fun x -> yield (a',b',c',x,e',f',g'));
838+
e e' (fun x -> yield (a',b',c',d',x,f',g'));
839+
f f' (fun x -> yield (a',b',c',d',e',x,g'));
840+
g g' (fun x -> yield (a',b',c',d',e',f',x))
841+
842+
let tup7_opt a b c d e f g =
843+
let a = Option.value ~default a in
844+
let b = Option.value ~default b in
845+
let c = Option.value ~default c in
846+
let d = Option.value ~default d in
847+
let e = Option.value ~default e in
848+
let f = Option.value ~default f in
849+
let g = Option.value ~default g in
850+
tup7 a b c d e f g
851+
852+
let tup8 a b c d e f g h (a', b', c', d', e', f', g', h') yield =
853+
a a' (fun x -> yield (x,b',c',d',e',f',g',h'));
854+
b b' (fun x -> yield (a',x,c',d',e',f',g',h'));
855+
c c' (fun x -> yield (a',b',x,d',e',f',g',h'));
856+
d d' (fun x -> yield (a',b',c',x,e',f',g',h'));
857+
e e' (fun x -> yield (a',b',c',d',x,f',g',h'));
858+
f f' (fun x -> yield (a',b',c',d',e',x,g',h'));
859+
g g' (fun x -> yield (a',b',c',d',e',f',x,h'));
860+
h h' (fun x -> yield (a',b',c',d',e',f',g',x))
861+
862+
let tup8_opt a b c d e f g h =
863+
let a = Option.value ~default a in
864+
let b = Option.value ~default b in
865+
let c = Option.value ~default c in
866+
let d = Option.value ~default d in
867+
let e = Option.value ~default e in
868+
let f = Option.value ~default f in
869+
let g = Option.value ~default g in
870+
let h = Option.value ~default h in
871+
tup8 a b c d e f g h
872+
873+
let tup9 a b c d e f g h i (a', b', c', d', e', f', g', h', i') yield =
874+
a a' (fun x -> yield (x,b',c',d',e',f',g',h',i'));
875+
b b' (fun x -> yield (a',x,c',d',e',f',g',h',i'));
876+
c c' (fun x -> yield (a',b',x,d',e',f',g',h',i'));
877+
d d' (fun x -> yield (a',b',c',x,e',f',g',h',i'));
878+
e e' (fun x -> yield (a',b',c',d',x,f',g',h',i'));
879+
f f' (fun x -> yield (a',b',c',d',e',x,g',h',i'));
880+
g g' (fun x -> yield (a',b',c',d',e',f',x,h',i'));
881+
h h' (fun x -> yield (a',b',c',d',e',f',g',x,i'));
882+
i i' (fun x -> yield (a',b',c',d',e',f',g',h',x))
883+
884+
let tup9_opt a b c d e f g h i =
885+
let a = Option.value ~default a in
886+
let b = Option.value ~default b in
887+
let c = Option.value ~default c in
888+
let d = Option.value ~default d in
889+
let e = Option.value ~default e in
890+
let f = Option.value ~default f in
891+
let g = Option.value ~default g in
892+
let h = Option.value ~default h in
893+
let i = Option.value ~default i in
894+
tup9 a b c d e f g h i
616895
end
617896

618897
(** {2 Observe Values} *)
@@ -876,6 +1155,78 @@ let quad a b c d =
8761155
(_opt_or d.shrink Shrink.nil))
8771156
(Gen.quad a.gen b.gen c.gen d.gen)
8781157

1158+
let tup2 a b=
1159+
make
1160+
?small:(_opt_map_2 ~f:(fun a b (a', b') -> a a'+b b') a.small b.small)
1161+
~print:(Print.tup2_opt a.print b.print)
1162+
~shrink:(Shrink.pair (_opt_or a.shrink Shrink.nil) (_opt_or b.shrink Shrink.nil))
1163+
(Gen.tup2 a.gen b.gen)
1164+
1165+
let tup3 a b c =
1166+
make
1167+
?small:(_opt_map_3 ~f:(fun a b c (a', b', c') ->
1168+
a a'+b b'+c c') a.small b.small c.small)
1169+
~print:(Print.tup3_opt a.print b.print c.print)
1170+
~shrink:(Shrink.tup3_opt a.shrink b.shrink c.shrink)
1171+
(Gen.tup3 a.gen b.gen c.gen)
1172+
1173+
let tup4 a b c d =
1174+
make
1175+
?small:(_opt_map_4 ~f:(fun a b c d (a', b', c', d') ->
1176+
a a'+b b'+c c'+d d') a.small b.small c.small d.small)
1177+
~print:(Print.tup4_opt a.print b.print c.print d.print)
1178+
~shrink:(Shrink.tup4_opt a.shrink b.shrink c.shrink d.shrink)
1179+
(Gen.tup4 a.gen b.gen c.gen d.gen)
1180+
1181+
let tup5 a b c d e =
1182+
make
1183+
?small:(_opt_map_5 ~f:(fun a b c d e (a', b', c', d', e') ->
1184+
a a'+b b'+c c'+d d'+e e') a.small b.small c.small d.small e.small)
1185+
~print:(Print.tup5_opt a.print b.print c.print d.print e.print)
1186+
~shrink:(Shrink.tup5_opt a.shrink b.shrink c.shrink d.shrink e.shrink)
1187+
(Gen.tup5 a.gen b.gen c.gen d.gen e.gen)
1188+
1189+
let tup6 a b c d e f =
1190+
make
1191+
?small:(_opt_map_6 ~f:(fun a b c d e f (a', b', c', d', e', f') ->
1192+
a a'+b b'+c c'+d d'+e e'+f f') a.small b.small c.small d.small e.small f.small)
1193+
~print:(Print.tup6_opt a.print b.print c.print d.print e.print f.print)
1194+
~shrink:(Shrink.tup6_opt a.shrink b.shrink c.shrink d.shrink e.shrink f.shrink)
1195+
(Gen.tup6 a.gen b.gen c.gen d.gen e.gen f.gen)
1196+
1197+
let tup7 a b c d e f g =
1198+
make
1199+
?small:(_opt_map_7 ~f:(fun a b c d e f g (a', b', c', d', e', f', g') ->
1200+
a a'+b b'+c c'+d d'+e e'+f f'+g g')
1201+
a.small b.small c.small d.small e.small f.small g.small)
1202+
~print:(Print.tup7_opt
1203+
a.print b.print c.print d.print e.print f.print g.print)
1204+
~shrink:(Shrink.tup7_opt
1205+
a.shrink b.shrink c.shrink d.shrink e.shrink f.shrink g.shrink)
1206+
(Gen.tup7 a.gen b.gen c.gen d.gen e.gen f.gen g.gen)
1207+
1208+
let tup8 a b c d e f g h =
1209+
make
1210+
?small:(_opt_map_8 ~f:(fun a b c d e f g h (a', b', c', d', e', f', g', h') ->
1211+
a a'+b b'+c c'+d d'+e e'+f f'+g g'+h h')
1212+
a.small b.small c.small d.small e.small f.small g.small h.small)
1213+
~print:(Print.tup8_opt
1214+
a.print b.print c.print d.print e.print f.print g.print h.print)
1215+
~shrink:(Shrink.tup8_opt
1216+
a.shrink b.shrink c.shrink d.shrink e.shrink f.shrink g.shrink h.shrink)
1217+
(Gen.tup8 a.gen b.gen c.gen d.gen e.gen f.gen g.gen h.gen)
1218+
1219+
let tup9 a b c d e f g h i =
1220+
make
1221+
?small:(_opt_map_9 ~f:(fun a b c d e f g h i (a', b', c', d', e', f', g', h', i') ->
1222+
a a'+b b'+c c'+d d'+e e'+f f'+g g'+h h'+i i')
1223+
a.small b.small c.small d.small e.small f.small g.small h.small i.small)
1224+
~print:(Print.tup9_opt
1225+
a.print b.print c.print d.print e.print f.print g.print h.print i.print)
1226+
~shrink:(Shrink.tup9_opt
1227+
a.shrink b.shrink c.shrink d.shrink e.shrink f.shrink g.shrink h.shrink i.shrink)
1228+
(Gen.tup9 a.gen b.gen c.gen d.gen e.gen f.gen g.gen h.gen i.gen)
1229+
8791230
let option ?ratio a =
8801231
let g = Gen.opt ?ratio a.gen
8811232
and shrink = _opt_map a.shrink ~f:Shrink.option

0 commit comments

Comments
 (0)