Skip to content

Commit

Permalink
Add test for signal functions
Browse files Browse the repository at this point in the history
  • Loading branch information
kumanna authored and ryanrhymes committed Apr 10, 2021
1 parent e73d797 commit 2bb945c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/test_runner.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ let () =
; "base: complex", Unit_base_complex.test_set
; "base: ndarray core", Unit_base_ndarray_core.test_set
; "base: linalg", Unit_linalg_solver.test_set
; "base: signal", Unit_signal.test_set
; ("algodiff matrix", Unit_algodiff_matrix.[ Reverse.test; Forward.test ]) ]
54 changes: 54 additions & 0 deletions test/unit_signal.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
(*Used unit_dense_ndarray test code as reference*)
open Bigarray
open Owl
open Owl_signal

module M = Owl_dense_ndarray_generic


let ndarray = Alcotest.testable (fun _p (_x : (float, float64_elt) M.t) -> ()) M.equal

let blackman_reference = M.zeros Float64 [|4|]
let hamming_reference = M.zeros Float64 [|4|]
let hann_reference = M.zeros Float64 [|4|]

let _ =
M.set blackman_reference [|0|] 0.;
M.set blackman_reference [|1|] 0.63;
M.set blackman_reference [|2|] 0.63;
M.set blackman_reference [|3|] 0.;
M.set hamming_reference [|0|] 0.08;
M.set hamming_reference [|1|] 0.77;
M.set hamming_reference [|2|] 0.77;
M.set hamming_reference [|3|] 0.08;
M.set hann_reference [|0|] 0.;
M.set hann_reference [|1|] 0.75;
M.set hann_reference [|2|] 0.75;
M.set hann_reference [|3|] 0.;

(*a module with functions to test*)
module To_test = struct
let blackman () =
let b = blackman 4 in
let max_err = (Arr.map2 (fun x y -> x -. y) blackman_reference b |> Arr.abs |> Arr.max |> Arr.get) [|0|] in
max_err < 1e-5

let hamming () =
let h = hamming 4 in
let max_err = (Arr.map2 (fun x y -> x -. y) hamming_reference h |> Arr.abs |> Arr.max |> Arr.get) [|0|] in
max_err < 1e-5

let hann () =
let h = hann 4 in
let max_err = (Arr.map2 (fun x y -> x -. y) hann_reference h |> Arr.abs |> Arr.max |> Arr.get) [|0|] in
max_err < 1e-5
end

let blackman () = Alcotest.(check bool) "blackman" true (To_test.blackman ())

let hamming () = Alcotest.(check bool) "hamming" true (To_test.hamming ())

let hann () = Alcotest.(check bool) "hann" true (To_test.hann ())

let test_set =
[ "blackman", `Slow, blackman; "hamming", `Slow, hamming; "hann", `Slow, hann ]

0 comments on commit 2bb945c

Please sign in to comment.