-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathasserts.ml
18 lines (15 loc) · 888 Bytes
/
asserts.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
open OUnit
let assert_equal_float ?(epsabs = 1e-8) ?(epsrel = 1e-8) ?(msg = "") =
assert_equal ~msg:msg ~cmp:(cmp_float ~epsabs:epsabs ~epsrel:epsrel) ~printer:string_of_float
let assert_equal_float_array ?(epsabs = 1e-8) ?(epsrel = 1e-8) ?(msg = "assert_equal_float_array") x y =
let n = Array.length x in
assert_bool (Printf.sprintf "%s: array lengths differ" msg) (Array.length y = n);
for i = 0 to n - 1 do
assert_equal_float ~epsabs:epsabs ~epsrel:epsrel ~msg:msg x.(i) y.(i)
done
let assert_equal_float_matrix ?(epsabs = 1e-8) ?(epsrel = 1e-8) ?(msg = "assert_equal_float_matrix") x y =
let n = Array.length x in
assert_bool (Printf.sprintf "%s: sizes differ" msg) (Array.length y = n);
for i = 0 to n - 1 do
assert_equal_float_array ~epsabs:epsabs ~epsrel:epsrel ~msg:(Printf.sprintf "%s: matrix row differs" msg) x.(i) y.(i)
done