summaryrefslogtreecommitdiff
path: root/tests/fstar/misc/Paper.fst
blob: 3566c5e24bde9887e0138b94d7fa730855f987a5 (plain)
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
(** THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS *)
(** [paper] *)
module Paper
open Primitives

#set-options "--z3rlimit 50 --fuel 1 --ifuel 1"

(** [paper::ref_incr]:
    Source: 'tests/src/paper.rs', lines 7:0-7:28 *)
let ref_incr (x : i32) : result i32 =
  i32_add x 1

(** [paper::test_incr]:
    Source: 'tests/src/paper.rs', lines 11:0-11:18 *)
let test_incr : result unit =
  let* x = ref_incr 0 in if x = 1 then Ok () else Fail Failure

(** Unit test for [paper::test_incr] *)
let _ = assert_norm (test_incr = Ok ())

(** [paper::choose]:
    Source: 'tests/src/paper.rs', lines 18:0-18:70 *)
let choose
  (t : Type0) (b : bool) (x : t) (y : t) : result (t & (t -> result (t & t))) =
  if b
  then let back = fun ret -> Ok (ret, y) in Ok (x, back)
  else let back = fun ret -> Ok (x, ret) in Ok (y, back)

(** [paper::test_choose]:
    Source: 'tests/src/paper.rs', lines 26:0-26:20 *)
let test_choose : result unit =
  let* (z, choose_back) = choose i32 true 0 0 in
  let* z1 = i32_add z 1 in
  if z1 = 1
  then
    let* (x, y) = choose_back z1 in
    if x = 1 then if y = 0 then Ok () else Fail Failure else Fail Failure
  else Fail Failure

(** Unit test for [paper::test_choose] *)
let _ = assert_norm (test_choose = Ok ())

(** [paper::List]
    Source: 'tests/src/paper.rs', lines 38:0-38:16 *)
type list_t (t : Type0) =
| List_Cons : t -> list_t t -> list_t t
| List_Nil : list_t t

(** [paper::list_nth_mut]:
    Source: 'tests/src/paper.rs', lines 45:0-45:67 *)
let rec list_nth_mut
  (t : Type0) (l : list_t t) (i : u32) :
  result (t & (t -> result (list_t t)))
  =
  begin match l with
  | List_Cons x tl ->
    if i = 0
    then let back = fun ret -> Ok (List_Cons ret tl) in Ok (x, back)
    else
      let* i1 = u32_sub i 1 in
      let* (x1, list_nth_mut_back) = list_nth_mut t tl i1 in
      let back =
        fun ret -> let* tl1 = list_nth_mut_back ret in Ok (List_Cons x tl1) in
      Ok (x1, back)
  | List_Nil -> Fail Failure
  end

(** [paper::sum]:
    Source: 'tests/src/paper.rs', lines 60:0-60:32 *)
let rec sum (l : list_t i32) : result i32 =
  begin match l with
  | List_Cons x tl -> let* i = sum tl in i32_add x i
  | List_Nil -> Ok 0
  end

(** [paper::test_nth]:
    Source: 'tests/src/paper.rs', lines 71:0-71:17 *)
let test_nth : result unit =
  let l = List_Cons 3 List_Nil in
  let l1 = List_Cons 2 l in
  let* (x, list_nth_mut_back) = list_nth_mut i32 (List_Cons 1 l1) 2 in
  let* x1 = i32_add x 1 in
  let* l2 = list_nth_mut_back x1 in
  let* i = sum l2 in
  if i = 7 then Ok () else Fail Failure

(** Unit test for [paper::test_nth] *)
let _ = assert_norm (test_nth = Ok ())

(** [paper::call_choose]:
    Source: 'tests/src/paper.rs', lines 79:0-79:44 *)
let call_choose (p : (u32 & u32)) : result u32 =
  let (px, py) = p in
  let* (pz, choose_back) = choose u32 true px py in
  let* pz1 = u32_add pz 1 in
  let* (px1, _) = choose_back pz1 in
  Ok px1