package preface

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file indexed_foldable.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
open QCheck2

module Suite
    (R : Model.COVARIANT_2)
    (F : Preface_specs.INDEXED_FOLDABLE
           with type ('a, 'index) t = ('a, 'index) R.t)
    (A : Model.T0)
    (B : Model.T0)
    (M : Preface_specs.MONOID with type t = A.t)
    (Index : Model.T0) =
struct
  module Laws = Preface_laws.Indexed_foldable.For (F)

  let print pp = Format.asprintf "%a" (R.pp pp Index.pp)

  let foldable_1 count =
    let generator =
      Gen.tup3
        (fun2 B.observable A.observable A.generator)
        A.generator
        (R.generator B.generator Index.generator)
    in
    let print (_, x, y) =
      Print.tup2 (Format.asprintf "%a" A.pp) (print B.pp) (x, y)
    in
    Util.test ~count ~print generator Laws.foldable_1 (fun lhs rhs (ff, x, y) ->
        let f = Fn.apply ff in
        let left = lhs (module A) f x y
        and right = rhs (module A) f x y in
        A.equal left right )
  ;;

  let foldable_2 count =
    let generator =
      Gen.tup3
        (fun2 A.observable B.observable A.generator)
        A.generator
        (R.generator B.generator Index.generator)
    in
    let print (_, x, y) =
      Print.tup2 (Format.asprintf "%a" A.pp) (print B.pp) (x, y)
    in
    Util.test ~count ~print generator Laws.foldable_2 (fun lhs rhs (ff, x, y) ->
        let f = Fn.apply ff in
        let left = lhs (module A) f x y
        and right = rhs (module A) f x y in
        A.equal left right )
  ;;

  let foldable_3 count =
    let generator = R.generator A.generator Index.generator in
    let print = print A.pp in
    Util.test ~count ~print generator Laws.foldable_3 (fun lhs rhs x ->
        let left = lhs (module M) x
        and right = rhs (module M) x in
        A.equal left right )
  ;;

  let tests ~count = [ foldable_1 count; foldable_2 count; foldable_3 count ]
end
OCaml

Innovation. Community. Security.