|
| 1 | +open QCheck |
| 2 | +open Helpers |
| 3 | + |
| 4 | +(** {1. Test primitives derivation} *) |
| 5 | + |
| 6 | +(** {2. Tests} *) |
| 7 | + |
| 8 | +type int' = int [@@deriving qcheck] |
| 9 | + |
| 10 | +let test_int () = |
| 11 | + test_compare ~msg:"Gen.int <=> deriving int" ~eq:Alcotest.int Gen.int gen_int' |
| 12 | + |
| 13 | +type unit' = unit [@@deriving qcheck] |
| 14 | + |
| 15 | +(* Pretty useless though, but, meh *) |
| 16 | +let test_unit () = |
| 17 | + test_compare ~msg:"Gen.unit <=> deriving unit" ~eq:Alcotest.unit Gen.unit gen_unit' |
| 18 | + |
| 19 | +type string' = string [@@deriving qcheck] |
| 20 | + |
| 21 | +let test_string () = |
| 22 | + test_compare ~msg:"Gen.string <=> deriving string" ~eq:Alcotest.string Gen.string gen_string' |
| 23 | + |
| 24 | +type char' = char [@@deriving qcheck] |
| 25 | + |
| 26 | +let test_char () = |
| 27 | + test_compare ~msg:"Gen.char <=> deriving char" ~eq:Alcotest.char Gen.char gen_char' |
| 28 | + |
| 29 | +type bool' = bool [@@deriving qcheck] |
| 30 | + |
| 31 | +let test_bool () = |
| 32 | + test_compare ~msg:"Gen.bool <=> deriving bool" ~eq:Alcotest.bool Gen.bool gen_bool' |
| 33 | + |
| 34 | +type float' = float [@@deriving qcheck] |
| 35 | + |
| 36 | +let test_float () = |
| 37 | + test_compare ~msg:"Gen.float <=> deriving float" ~eq:(Alcotest.float 0.) Gen.float gen_float' |
| 38 | + |
| 39 | +type int32' = int32 [@@deriving qcheck] |
| 40 | + |
| 41 | +let test_int32 () = |
| 42 | + test_compare ~msg:"Gen.int32 <=> deriving int32" ~eq:Alcotest.int32 Gen.ui32 gen_int32' |
| 43 | + |
| 44 | +type int64' = int64 [@@deriving qcheck] |
| 45 | + |
| 46 | +let test_int64 () = |
| 47 | + test_compare ~msg:"Gen.int64 <=> deriving int64" ~eq:Alcotest.int64 Gen.ui64 gen_int64' |
| 48 | + |
| 49 | +type 'a option' = 'a option [@@deriving qcheck] |
| 50 | + |
| 51 | +let test_option () = |
| 52 | + let zero = Gen.pure 0 in |
| 53 | + test_compare ~msg:"Gen.opt <=> deriving opt" |
| 54 | + ~eq:Alcotest.(option int) |
| 55 | + (Gen.opt zero) (gen_option' zero) |
| 56 | + |
| 57 | +type 'a array' = 'a array [@@deriving qcheck] |
| 58 | + |
| 59 | +let test_array () = |
| 60 | + let zero = Gen.pure 0 in |
| 61 | + test_compare ~msg:"Gen.array <=> deriving array" |
| 62 | + ~eq:Alcotest.(array int) |
| 63 | + (Gen.array zero) (gen_array' zero) |
| 64 | + |
| 65 | +type 'a list' = 'a list [@@deriving qcheck] |
| 66 | + |
| 67 | +let test_list () = |
| 68 | + let zero = Gen.pure 0 in |
| 69 | + test_compare ~msg:"Gen.list <=> deriving list" |
| 70 | + ~eq:Alcotest.(list int) |
| 71 | + (Gen.list zero) (gen_list' zero) |
| 72 | + |
| 73 | +(** {2. Execute tests} *) |
| 74 | + |
| 75 | +let () = Alcotest.run "Test_Primitives" |
| 76 | + [("Primitives", |
| 77 | + Alcotest.[ |
| 78 | + test_case "test_int" `Quick test_int; |
| 79 | + test_case "test_unit" `Quick test_unit; |
| 80 | + test_case "test_string" `Quick test_string; |
| 81 | + test_case "test_char" `Quick test_char; |
| 82 | + test_case "test_bool" `Quick test_bool; |
| 83 | + test_case "test_float" `Quick test_float; |
| 84 | + test_case "test_int32" `Quick test_int32; |
| 85 | + test_case "test_int64" `Quick test_int64; |
| 86 | + test_case "test_option" `Quick test_option; |
| 87 | + test_case "test_array" `Quick test_array; |
| 88 | + test_case "test_list" `Quick test_list; |
| 89 | + ])] |
0 commit comments