add more tests for "floats" in test_data_encoding ( +/- infinity, +/- 0., NaNs)

This commit is contained in:
OCamlPro-Iguernlala 2017-03-30 11:26:11 +02:00
parent 669a0249ca
commit ee554820c7
3 changed files with 20 additions and 4 deletions

View File

@ -128,3 +128,7 @@ let fail_msg fmt =
let fail expected given fmt = let fail expected given fmt =
Format.kasprintf (Assert.fail expected given) fmt Format.kasprintf (Assert.fail expected given) fmt
let equal_float ?eq ?prn ?msg f1 f2 =
match classify_float f1, classify_float f2 with
| FP_nan, FP_nan -> ()
| _ -> equal ?eq ?prn ?msg f1 f2

View File

@ -66,3 +66,7 @@ val test_fail :
(unit -> 'a) -> (unit -> 'a) ->
(exn -> bool) -> (exn -> bool) ->
unit unit
val equal_float:
?eq:(float -> float -> bool) ->
?prn:(float -> string) -> ?msg:string -> float -> float -> unit

View File

@ -18,7 +18,7 @@ let is_invalid_arg = function
| Invalid_argument _ -> true | Invalid_argument _ -> true
| _ -> false | _ -> false
let test_simple_json ?msg ?eq:(equal=Assert.equal) encoding value = let test_simple_json ?msg ?(equal=Assert.equal) encoding value =
let json = Json.construct encoding value in let json = Json.construct encoding value in
let result = Json.destruct encoding json in let result = Json.destruct encoding json in
equal ?msg value result equal ?msg value result
@ -42,9 +42,9 @@ let test_bin_exn ?msg encoding value fail =
Binary.of_bytes encoding bin in Binary.of_bytes encoding bin in
Assert.test_fail ?msg get_result fail Assert.test_fail ?msg get_result fail
let test_simple ~msg enc value = let test_simple ~msg ?(equal=Assert.equal) enc value =
test_simple_json ~msg:(msg ^ ": json") enc value ; test_simple_json ~msg:(msg ^ ": json") ~equal enc value ;
test_simple_bin ~msg:(msg ^ ": binary") enc value test_simple_bin ~msg:(msg ^ ": binary") ~equal enc value
let test_simple_exn ~msg enc value = let test_simple_exn ~msg enc value =
test_json_exn ~msg:(msg ^ ": json") enc value (fun _ -> true) ; test_json_exn ~msg:(msg ^ ": json") enc value (fun _ -> true) ;
@ -88,6 +88,14 @@ let test_simple_values _ =
test_simple ~msg:__LOC__ string "tutu"; test_simple ~msg:__LOC__ string "tutu";
test_simple ~msg:__LOC__ bytes (MBytes.of_string "titi"); test_simple ~msg:__LOC__ bytes (MBytes.of_string "titi");
test_simple ~msg:__LOC__ float 42.; test_simple ~msg:__LOC__ float 42.;
test_simple ~msg:__LOC__ float max_float;
test_simple ~msg:__LOC__ float min_float;
test_simple ~msg:__LOC__ float (-. 0.);
test_simple ~msg:__LOC__ float (+. 0.);
test_simple ~msg:__LOC__ float infinity;
test_simple ~msg:__LOC__ float neg_infinity;
test_simple ~msg:__LOC__ float epsilon_float;
test_simple ~msg:__LOC__ ~equal:Assert.equal_float float nan;
test_simple ~msg:__LOC__ (option string) (Some "thing"); test_simple ~msg:__LOC__ (option string) (Some "thing");
test_simple ~msg:__LOC__ (option string) None; test_simple ~msg:__LOC__ (option string) None;
let enum_enc = let enum_enc =