10
1
mirror of https://gitlab.com/scemama/QCaml.git synced 2024-11-06 22:23:42 +01:00
QCaml/common/test/bitstring.ml
2020-12-27 16:36:25 +01:00

82 lines
3.5 KiB
Standard ML

(* Tests header :noexport: *)
(* [[file:../bitstring.org::*Tests header][Tests header:1]] *)
open Common.Bitstring
let check msg x = Alcotest.(check bool) msg true x
let test_all () =
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
(* Tests header:1 ends here *)
(* [[file:../bitstring.org::*~of_int~][~of_int~:3]] *)
Alcotest.(check bool) "of_x" true (one_x = (of_int x));
(* ~of_int~:3 ends here *)
(* [[file:../bitstring.org::*~of_z~][~of_z~:3]] *)
Alcotest.(check bool) "of_z" true (one_x = (of_z (Z.of_int x)));
(* ~of_z~:3 ends here *)
(* [[file:../bitstring.org::*~shift_left~][~shift_left~:3]] *)
Alcotest.(check bool) "shift_left1" true (of_int (x lsl 3) = shift_left one_x 3);
Alcotest.(check bool) "shift_left2" true (of_z (Z.shift_left z 3) = shift_left many_x 3);
Alcotest.(check bool) "shift_left3" true (of_z (Z.shift_left z 100) = shift_left many_x 100);
(* ~shift_left~:3 ends here *)
(* [[file:../bitstring.org::*~shift_right~][~shift_right~:3]] *)
Alcotest.(check bool) "shift_right1" true (of_int (x lsr 3) = shift_right one_x 3);
Alcotest.(check bool) "shift_right2" true (of_z (Z.shift_right z 3) = shift_right many_x 3);
(* ~shift_right~:3 ends here *)
(* [[file:../bitstring.org::*~shift_left_one~][~shift_left_one~:3]] *)
Alcotest.(check bool) "shift_left_one1" true (of_int (1 lsl 3) = shift_left_one 4 3);
Alcotest.(check bool) "shift_left_one2" true (of_z (Z.shift_left Z.one 200) = shift_left_one 300 200);
(* ~shift_left_one~:3 ends here *)
(* [[file:../bitstring.org::*~testbit~][~testbit~:3]] *)
Alcotest.(check bool) "testbit1" true (testbit (of_int 8) 3);
Alcotest.(check bool) "testbit2" false (testbit (of_int 8) 2);
Alcotest.(check bool) "testbit3" false (testbit (of_int 8) 4);
Alcotest.(check bool) "testbit4" true (testbit (of_z (Z.of_int 8)) 3);
Alcotest.(check bool) "testbit5" false (testbit (of_z (Z.of_int 8)) 2);
Alcotest.(check bool) "testbit6" false (testbit (of_z (Z.of_int 8)) 4);
(* ~testbit~:3 ends here *)
(* [[file:../bitstring.org::*~logor~][~logor~:3]] *)
Alcotest.(check bool) "logor1" true (of_int (1 lor 2) = logor (of_int 1) (of_int 2));
Alcotest.(check bool) "logor2" true (of_z (Z.of_int (1 lor 2)) = logor (of_z Z.one) (of_z (Z.of_int 2)));
(* ~logor~:3 ends here *)
(* [[file:../bitstring.org::*~logxor~][~logxor~:3]] *)
Alcotest.(check bool) "logxor1" true (of_int (1 lxor 2) = logxor (of_int 1) (of_int 2));
Alcotest.(check bool) "logxor2" true (of_z (Z.of_int (1 lxor 2)) = logxor (of_z Z.one) (of_z (Z.of_int 2)));
(* ~logxor~:3 ends here *)
(* [[file:../bitstring.org::*~logand~][~logand~:3]] *)
Alcotest.(check bool) "logand1" true (of_int (1 land 3) = logand (of_int 1) (of_int 3));
Alcotest.(check bool) "logand2" true (of_z (Z.of_int (1 land 3)) = logand (of_z Z.one) (of_z (Z.of_int 3)));
(* ~logand~:3 ends here *)
(* [[file:../bitstring.org::*~to_list~][~to_list~:3]] *)
Alcotest.(check bool) "to_list" true ([ 1 ; 3 ; 4 ; 6 ] = (to_list (of_int 45)));
(* ~to_list~:3 ends here *)
(* [[file:../bitstring.org::*~permutations~][~permutations~:3]] *)
check "permutations"
(permutations 2 4 = List.map of_int
[ 3 ; 5 ; 6 ; 9 ; 10 ; 12 ]);
(* ~permutations~:3 ends here *)
(* Tests :noexport: *)
(* [[file:../bitstring.org::*Tests][Tests:1]] *)
()
let tests = [
"all", `Quick, test_all;
]
(* Tests:1 ends here *)