File: test-coef_var.R

package info (click to toggle)
r-cran-datawizard 1.0.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,300 kB
  • sloc: sh: 13; makefile: 2
file content (37 lines) | stat: -rw-r--r-- 1,088 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
test_that("coefficient of variation works", {
  expect_equal(coef_var(1:10), 0.5504818826)
  expect_equal(coef_var(1:10, method = "unbiased"), 0.5552700246)
  expect_equal(coef_var(c(1:10, 100), method = "median_mad"), 0.7413)
  expect_equal(coef_var(c(1:10, 100), method = "qcd"), 0.4166666667)
  expect_identical(coef_var(mu = 10, sigma = 20), 2)
  expect_equal(coef_var(mu = 10, sigma = 20, method = "unbiased", n = 30), 2.250614348)
  expect_equal(distribution_coef_var(1:10), 0.5504818826)
})


test_that("coef_var returns NULL if can't compute", {
  expect_warning(
    {
      x <- coef_var(as.Date("2022-10-31"))
    },
    "Can't compute"
  )
  expect_null(x)
})


test_that("coef_var: argument 'remove_na' works", {
  expect_identical(coef_var(c(1:10, NA)), NA_real_)

  expect_identical(
    coef_var(1:10),
    coef_var(c(1:10, NA), remove_na = TRUE)
  )
})

test_that("coef_var: method 'unbiased' needs argument 'n' when sigma and mu are provided", {
  expect_error(
    coef_var(1:10, method = "unbiased", mu = 10, sigma = 20),
    "A value for `n` must be provided"
  )
})