File: test-std_center_scale_args.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 (47 lines) | stat: -rw-r--r-- 1,967 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
38
39
40
41
42
43
44
45
46
47
d <- data.frame(a = 1:5, b = 21:25, c = 41:45)

test_that("standardize", {
  x <- standardize(d)
  expect_equal(as.vector(x$a), as.vector(scale(d$a)), tolerance = 0.001)
})

test_that("standardize", {
  x <- standardize(d, center = 5, scale = 2)
  expect_equal(as.vector(x$a), c(-2, -1.5, -1, -0.5, 0), tolerance = 0.001)
})

test_that("standardize", {
  x <- standardize(d, center = c(5, 25, 45), scale = c(3, 3, 3))
  expect_equal(as.vector(x$a), c(-1.33333, -1, -0.66667, -0.33333, 0), tolerance = 0.001)
  expect_equal(as.vector(x$b), c(-1.33333, -1, -0.66667, -0.33333, 0), tolerance = 0.001)
})

test_that("standardize", {
  x <- standardize(d, center = c(c = 45, a = 5, b = 25), scale = c(3, 3, 3))
  expect_equal(as.vector(x$a), c(-1.33333, -1, -0.66667, -0.33333, 0), tolerance = 0.001)
  expect_equal(as.vector(x$b), c(-1.33333, -1, -0.66667, -0.33333, 0), tolerance = 0.001)
})

test_that("standardize", {
  x <- standardize(d, center = c(c = 45, a = 5, b = 25), scale = c(1, 2, 3))
  expect_equal(as.vector(x$a), c(-4, -3, -2, -1, 0), tolerance = 0.001)
  expect_equal(as.vector(x$b), c(-2, -1.5, -1, -0.5, 0), tolerance = 0.001)
})

test_that("standardize", {
  x <- standardize(d, center = c(c = 45, a = 5, b = 25), scale = c(a = 1, b = 2, c = 3))
  expect_equal(as.vector(x$a), c(-4, -3, -2, -1, 0), tolerance = 0.001)
  expect_equal(as.vector(x$b), c(-2, -1.5, -1, -0.5, 0), tolerance = 0.001)
})

test_that("standardize", {
  x <- standardize(d, center = c(c = 45, a = 5, b = 25), scale = c(c = 3, b = 2, a = 1))
  expect_equal(as.vector(x$a), c(-4, -3, -2, -1, 0), tolerance = 0.001)
  expect_equal(as.vector(x$b), c(-2, -1.5, -1, -0.5, 0), tolerance = 0.001)
})

test_that("standardize", {
  x <- standardize(d, center = c(c = 45, a = 5, b = 25), scale = c(c = 1, b = 2, a = 3))
  expect_equal(as.vector(x$a), c(-1.33333, -1, -0.66667, -0.33333, 0), tolerance = 0.001)
  expect_equal(as.vector(x$b), c(-2, -1.5, -1, -0.5, 0), tolerance = 0.001)
})