2020-12-27 16:36:25 +01:00
|
|
|
(* Tests header :noexport: *)
|
2020-09-26 12:02:53 +02:00
|
|
|
|
|
|
|
|
2020-12-26 01:47:55 +01:00
|
|
|
(* [[file:../bitstring.org::*Tests header][Tests header:1]] *)
|
|
|
|
open Common.Bitstring
|
2020-12-27 23:08:12 +01:00
|
|
|
let check_bool = Alcotest.(check bool)
|
|
|
|
let check msg x = check_bool msg true x
|
2020-12-26 01:47:55 +01:00
|
|
|
let test_all () =
|
2020-12-27 17:38:04 +01:00
|
|
|
let x = 8745687 in
|
|
|
|
let one_x = of_int x in
|
|
|
|
let z = Z.shift_left (Z.of_int x) 64 in
|
|
|
|
let many_x = of_z z in
|
2020-12-26 01:47:55 +01:00
|
|
|
(* Tests header:1 ends here *)
|
|
|
|
|
2020-12-27 23:08:12 +01:00
|
|
|
(* [[file:../bitstring.org::*General implementation][General implementation:3]] *)
|
|
|
|
check_bool "of_x" true (one_x = (of_int x));
|
|
|
|
(* General implementation:3 ends here *)
|
|
|
|
|
|
|
|
(* [[file:../bitstring.org::*General implementation][General implementation:5]] *)
|
|
|
|
check_bool "of_z" true (one_x = (of_z (Z.of_int x)));
|
|
|
|
(* General implementation:5 ends here *)
|
|
|
|
|
|
|
|
(* [[file:../bitstring.org::*General implementation][General implementation:11]] *)
|
|
|
|
check_bool "shift_left1" true (of_int (x lsl 3) = shift_left one_x 3);
|
|
|
|
check_bool "shift_left2" true (of_z (Z.shift_left z 3) = shift_left many_x 3);
|
|
|
|
check_bool "shift_left3" true (of_z (Z.shift_left z 100) = shift_left many_x 100);
|
|
|
|
(* General implementation:11 ends here *)
|
|
|
|
|
|
|
|
(* [[file:../bitstring.org::*General implementation][General implementation:13]] *)
|
|
|
|
check_bool "shift_right1" true (of_int (x lsr 3) = shift_right one_x 3);
|
|
|
|
check_bool "shift_right2" true (of_z (Z.shift_right z 3) = shift_right many_x 3);
|
|
|
|
(* General implementation:13 ends here *)
|
|
|
|
|
|
|
|
(* [[file:../bitstring.org::*General implementation][General implementation:15]] *)
|
|
|
|
check_bool "shift_left_one1" true (of_int (1 lsl 3) = shift_left_one 4 3);
|
|
|
|
check_bool "shift_left_one2" true (of_z (Z.shift_left Z.one 200) = shift_left_one 300 200);
|
|
|
|
(* General implementation:15 ends here *)
|
|
|
|
|
|
|
|
(* [[file:../bitstring.org::*General implementation][General implementation:17]] *)
|
|
|
|
check_bool "testbit1" true (testbit (of_int 8) 3);
|
|
|
|
check_bool "testbit2" false (testbit (of_int 8) 2);
|
|
|
|
check_bool "testbit3" false (testbit (of_int 8) 4);
|
|
|
|
check_bool "testbit4" true (testbit (of_z (Z.of_int 8)) 3);
|
|
|
|
check_bool "testbit5" false (testbit (of_z (Z.of_int 8)) 2);
|
|
|
|
check_bool "testbit6" false (testbit (of_z (Z.of_int 8)) 4);
|
|
|
|
(* General implementation:17 ends here *)
|
|
|
|
|
|
|
|
(* [[file:../bitstring.org::*General implementation][General implementation:19]] *)
|
|
|
|
check_bool "logor1" true (of_int (1 lor 2) = logor (of_int 1) (of_int 2));
|
|
|
|
check_bool "logor2" true (of_z (Z.of_int (1 lor 2)) = logor (of_z Z.one) (of_z (Z.of_int 2)));
|
|
|
|
(* General implementation:19 ends here *)
|
|
|
|
|
|
|
|
(* [[file:../bitstring.org::*General implementation][General implementation:21]] *)
|
|
|
|
check_bool "logxor1" true (of_int (1 lxor 2) = logxor (of_int 1) (of_int 2));
|
|
|
|
check_bool "logxor2" true (of_z (Z.of_int (1 lxor 2)) = logxor (of_z Z.one) (of_z (Z.of_int 2)));
|
|
|
|
(* General implementation:21 ends here *)
|
|
|
|
|
|
|
|
(* [[file:../bitstring.org::*General implementation][General implementation:23]] *)
|
|
|
|
check_bool "logand1" true (of_int (1 land 3) = logand (of_int 1) (of_int 3));
|
|
|
|
check_bool "logand2" true (of_z (Z.of_int (1 land 3)) = logand (of_z Z.one) (of_z (Z.of_int 3)));
|
|
|
|
(* General implementation:23 ends here *)
|
|
|
|
|
|
|
|
(* [[file:../bitstring.org::*General implementation][General implementation:31]] *)
|
|
|
|
check_bool "to_list" true ([ 1 ; 3 ; 4 ; 6 ] = (to_list (of_int 45)));
|
|
|
|
(* General implementation:31 ends here *)
|
|
|
|
|
|
|
|
(* [[file:../bitstring.org::*General implementation][General implementation:33]] *)
|
2020-12-26 01:47:55 +01:00
|
|
|
check "permutations"
|
2020-12-26 01:54:39 +01:00
|
|
|
(permutations 2 4 = List.map of_int
|
2020-12-26 01:47:55 +01:00
|
|
|
[ 3 ; 5 ; 6 ; 9 ; 10 ; 12 ]);
|
2020-12-27 23:08:12 +01:00
|
|
|
(* General implementation:33 ends here *)
|
2020-12-26 01:47:55 +01:00
|
|
|
|
2020-12-27 16:36:25 +01:00
|
|
|
(* Tests :noexport: *)
|
2020-12-26 01:47:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
(* [[file:../bitstring.org::*Tests][Tests:1]] *)
|
2020-12-27 17:38:04 +01:00
|
|
|
()
|
2020-12-27 16:36:25 +01:00
|
|
|
|
2020-09-26 12:02:53 +02:00
|
|
|
let tests = [
|
2020-12-27 17:38:04 +01:00
|
|
|
"all", `Quick, test_all;
|
|
|
|
]
|
2020-12-26 01:47:55 +01:00
|
|
|
(* Tests:1 ends here *)
|