open Qcaml_common.Bitstring let check msg x = Alcotest.(check bool) msg true x let test_one () = let x = 8745687 in let one_x = One x in Alcotest.(check bool) "of_x" true (one_x = (of_int x)); Alcotest.(check bool) "shift_left1" true (One (x lsl 3) = shift_left one_x 3); Alcotest.(check bool) "shift_right1" true (One (x lsr 3) = shift_right one_x 3); Alcotest.(check bool) "shift_left_one1" true (One (1 lsl 3) = shift_left_one 4 3); Alcotest.(check bool) "testbit1" true (testbit (One 8) 3); Alcotest.(check bool) "testbit2" false (testbit (One 8) 2); Alcotest.(check bool) "testbit3" false (testbit (One 8) 4); Alcotest.(check bool) "logor1" true (One (1 lor 2) = logor (One 1) (One 2)); Alcotest.(check bool) "logxor1" true (One (1 lxor 2) = logxor (One 1) (One 2)); Alcotest.(check bool) "logand1" true (One (1 land 2) = logand (One 1) (One 2)); Alcotest.(check bool) "to_list" true ([ 1 ; 3 ; 4 ; 6 ] = (to_list (One 45))) let test_many () = let x = 8745687 in let z = Z.of_int x in let one_x = One x in let many_x = Many z in Alcotest.(check bool) "of_z" true (one_x = (of_z z)); Alcotest.(check bool) "shift_left2" true (Many (Z.shift_left z 3) = shift_left many_x 3); Alcotest.(check bool) "shift_left3" true (Many (Z.shift_left z 100) = shift_left many_x 100); Alcotest.(check bool) "shift_right2" true (Many (Z.shift_right z 3) = shift_right many_x 3); Alcotest.(check bool) "shift_left_one2" true (Many (Z.shift_left Z.one 200) = shift_left_one 300 200); Alcotest.(check bool) "testbit4" true (testbit (Many (Z.of_int 8)) 3); Alcotest.(check bool) "testbit5" false (testbit (Many (Z.of_int 8)) 2); Alcotest.(check bool) "testbit6" false (testbit (Many (Z.of_int 8)) 4); Alcotest.(check bool) "logor2" true (Many (Z.of_int (1 lor 2)) = logor (Many Z.one) (Many (Z.of_int 2))); Alcotest.(check bool) "logxor2" true (Many (Z.of_int (1 lxor 2)) = logxor (Many Z.one) (Many (Z.of_int 2))); Alcotest.(check bool) "logand2" true (Many (Z.of_int (1 land 2)) = logand (Many Z.one) (Many (Z.of_int 2))) let test_permutations () = check "permutations" (permtutations 2 4 = List.map of_int [ 3 ; 5 ; 6 ; 9 ; 10 ; 12 ]) let tests = [ "One", `Quick, test_one; "Many", `Quick, test_many; "permutations", `Quick, test_permutations; ]