Debian Codegraph @

test-suite/ltac2/int.v

raw
1 Require Import Ltac2.Ltac2.
2 Require Ltac2.Int.
3 Require Ltac2.Bool.
4
5 (* Int comparison functions which throw an exception on unequal *)
6
7 Ltac2 Type exn ::= [ Regression_Test_Failure ].
8
9 Ltac2 check_eq_int a b :=
10 if Int.equal a b then () else Control.throw Regression_Test_Failure .
11
12 Ltac2 check_eq_bool a b :=
13 if Bool.equal a b then () else Control.throw Regression_Test_Failure .
14
15 Goal True.
16 (* Test failure *)
17 Fail check_eq_int 2 3.
18 Fail check_eq_bool true false.
19
20 check_eq_bool (Int.equal 2 2) true.
21 check_eq_bool (Int.equal 2 3) false.
22
23 check_eq_int (Int.add 5 7) 12.
24 check_eq_int (Int.sub 5 7) -2.
25 check_eq_int (Int.mul 5 7) 35.
26 check_eq_int (Int.div 7 5) 1.
27 check_eq_int (Int.div 7 -5) -1.
28 check_eq_int (Int.div -7 5) -1.
29 check_eq_int (Int.div -7 -5) 1.
30 Fail Ltac2 Eval Int.div 1 0.
31 check_eq_int (Int.mod 7 5) 2.
32 check_eq_int (Int.mod 7 -5) 2.
33 check_eq_int (Int.mod -7 5) -2.
34 check_eq_int (Int.mod -7 -5) -2.
35 Fail Ltac2 Eval Int.mod 1 0.
36 check_eq_int (Int.neg 5) -5.
37 check_eq_int (Int.abs -5) 5.
38
39 check_eq_int (Int.asr 16 2) 4.
40 check_eq_int (Int.asr -16 2) -4.
41 check_eq_int (Int.lsl 16 2) 64.
42 check_eq_int (Int.lsl -16 2) -64.
43 check_eq_int (Int.lsr 16 2) 4.
44 check_eq_int (Int.compare (Int.lsr -16 2) 0) 1.
45 check_eq_int (Int.land 7 12) 4.
46 check_eq_int (Int.lor 7 12) 15.
47 check_eq_int (Int.lxor 7 12) 11.
48 check_eq_int (Int.lnot -1) 0.
49
50 exact I.
51 Qed.