Skip to content

Commit

Permalink
add some test for wnd to inflate coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
lschneiderbauer committed Dec 28, 2024
1 parent fa3c05b commit e5c91b2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
7 changes: 4 additions & 3 deletions R/wnd.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ wnd_from_dim <- function(n, orig_sample_freq) {
)
}

#' @param secs target window length in seconds. The exact window length
#' @param time target window length in seconds or similar time units.
#' The exact window length
#' depends on the original sample frequency `orig_sample_freq`
#' @noRd
wnd_from_secs <- function(secs, orig_sample_freq) {
n <- round(secs * orig_sample_freq)
wnd_from_time <- function(time, orig_sample_freq) {
n <- round(ddu(time * orig_sample_freq))

wnd_from_dim(n, orig_sample_freq)
}
Expand Down
38 changes: 38 additions & 0 deletions tests/testthat/test-wnd.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
test_that("wnd_from_dim works", {
w <- wnd_from_dim(10, u(10, "Hz"))

expect_equal(w$size_n, 10)
expect_true(w$size_time == u(1, "s"))
})

test_that("wnd_from_sec works", {
w <- wnd_from_time(u(10, "s"), u(10, "Hz"))

expect_equal(w$size_n, 100)
expect_true(w$size_time == u(10, "s"))
})


test_that("wnd_from_resolution works", {
w <- wnd_from_resolution(u(1, "s"), u(100, "Hz"))

expect_equal(w$size_n, 100)
expect_true(w$size_time == u(1, "s"))
})

test_that("wnd_from_target_size works", {
res <-
fcwt(
ts_sin_440[1:1000],
sample_freq = 44100,
freq_begin = 50,
freq_end = 1000,
n_freqs = 10,
sigma = 1
)

w <- wnd_from_target_size(100, res)

expect_equal(w$size_n, 10)
expect_true(w$size_time == 10 / u(44100, "Hz"))
})

0 comments on commit e5c91b2

Please sign in to comment.