Created
January 25, 2017 12:50
-
-
Save dungpa/857fad41f4eeb25ef0242dc8efb20fa7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Sc_util | |
open OUnit | |
open Mlfi_check | |
let test_count = 100 | |
module UtilTests = struct | |
let gen_function ~(gen_input: 'a gen) ~(map_output: 'a -> 'b): ('a * ('a -> 'b)) gen = | |
let f a = return (a, (fun (_: 'a) -> map_output a)) in | |
gen_input >>= f | |
let test_option_or_else_argument_order () = | |
test test_count | |
~name:"Sc_option.or_else favours the last argument" | |
~generator:(of_type ~t: (ttype_of: int option * int option)) | |
(fun (alt, main) -> Sc_option.or_else alt main = (if Sc_util.Sc_option.is_some main then main else alt)) | |
let test_result_of_option_to_option_identity () = | |
test test_count | |
~name:"Sc_result.to_option is inverse of Sc_result.of_option" | |
~generator:(of_type ~t: (ttype_of: int option)) | |
(fun x -> Sc_result.to_option (Sc_result.of_option x) = x) | |
let test_result_exists_forall_consistency () = | |
let map_x x = if x mod 2 = 0 then Sc_result.ok x else Sc_result.error () in | |
let map_output x = x mod 2 = 0 in | |
let generator = | |
gen_function ~gen_input: int ~map_output | |
|> map (fun (x, y) -> (map_x x), y) in | |
test test_count | |
~name:"Sc_result.exists and Sc_result.for_all are consistent" | |
~generator | |
(fun ((x: (int, unit) result), (f: int -> bool)) -> Sc_result.exists f x = not (Sc_result.for_all (not @@ f) x)) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment