package preface

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

Source file arrow_choice.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
open QCheck2

module Suite
    (R : Model.PROFUNCTORIAL)
    (P : Preface_specs.ARROW_CHOICE with type ('a, 'b) t = ('a, 'b) R.t)
    (A : Model.T0)
    (B : Model.T0)
    (C : Model.T0)
    (D : Model.T0) =
struct
  module Arrow = Arrow.Suite (R) (P) (A) (B) (C) (D)
  module Laws = Preface_laws.Arrow_choice.For (P)

  let arrow_choice_1 count =
    let generator = fun1 A.observable B.generator
    and input = R.input (Util.gen_either A.generator C.generator) in
    Util.test ~count (Gen.tup2 generator input) Laws.arrow_choice_1
      (fun lhs rhs (f, x) ->
        let f = Fn.apply f in
        let left = lhs f
        and right = rhs f in
        R.run_equality x
          (R.equal (Util.equal_either B.equal C.equal))
          left right )
  ;;

  let arrow_choice_2 count =
    let generator =
      Gen.tup2
        (R.generator A.observable B.generator)
        (R.generator B.observable C.generator)
    and input = R.input (Util.gen_either A.generator D.generator) in
    Util.test ~count (Gen.tup2 generator input) Laws.arrow_choice_2
      (fun lhs rhs ((p1, p2), x) ->
        let pro1 = R.lift p1
        and pro2 = R.lift p2 in
        let left = lhs pro1 pro2
        and right = rhs pro1 pro2 in
        R.run_equality x
          (R.equal (Util.equal_either C.equal D.equal))
          left right )
  ;;

  let arrow_choice_3 count =
    let generator = R.generator A.observable B.generator
    and input = R.input A.generator in
    Util.test ~count (Gen.tup2 generator input) Laws.arrow_choice_3
      (fun lhs rhs (p, x) ->
        let pro = R.lift p in
        let left = lhs pro
        and right = rhs pro in
        R.run_equality x
          (R.equal (Util.equal_either B.equal C.equal))
          left right )
  ;;

  let arrow_choice_4 count =
    let generator =
      Gen.tup2
        (R.generator A.observable B.generator)
        (fun1 C.observable D.generator)
    and input = R.input (Util.gen_either A.generator C.generator) in
    Util.test ~count (Gen.tup2 generator input) Laws.arrow_choice_4
      (fun lhs rhs ((p, f), x) ->
        let pro = R.lift p
        and f = Fn.apply f in
        let left = lhs pro f
        and right = rhs pro f in
        R.run_equality x
          (R.equal (Util.equal_either B.equal D.equal))
          left right )
  ;;

  let arrow_choice_5 count =
    let generator = R.generator A.observable B.generator
    and input =
      R.input
        (Util.gen_either (Util.gen_either A.generator C.generator) D.generator)
    in
    Util.test ~count (Gen.tup2 generator input) Laws.arrow_choice_5
      (fun lhs rhs (p, x) ->
        let pro = R.lift p in
        let left = lhs pro
        and right = rhs pro in
        R.run_equality x
          (R.equal
             (Util.equal_either B.equal (Util.equal_either C.equal D.equal)) )
          left right )
  ;;

  let tests ~count =
    Arrow.tests ~count
    @ [
        arrow_choice_1 count
      ; arrow_choice_2 count
      ; arrow_choice_3 count
      ; arrow_choice_4 count
      ; arrow_choice_5 count
      ]
  ;;
end
OCaml

Innovation. Community. Security.