File: test-normalise.R

package info (click to toggle)
r-cran-eaf 2.5.2-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,016 kB
  • sloc: ansic: 7,281; perl: 848; makefile: 73; sh: 43; python: 27
file content (21 lines) | stat: -rw-r--r-- 682 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
source("helper-common.R")

test_that("normalise", {
  #skip_on_cran()
  my.2d.matrix <- function(...) matrix(c(...), ncol = 2, byrow=FALSE)
  x = my.2d.matrix(0, 0.5, 1, 0, 0.5, 1)

  expect_equal(normalise(x), my.2d.matrix(1, 1.5, 2, 1, 1.5, 2))

  expect_equal(normalise(x, maximise = c(FALSE,TRUE)),
               my.2d.matrix(1, 1.5, 2, 2, 1.5, 1))

  expect_equal(normalise(x, to_range = c(0, 1), maximise = c(FALSE,TRUE)),
               my.2d.matrix(0, 0.5, 1, 1, 0.5, 0))

  expect_equal(normalise(my.2d.matrix(1,1,2,2)), my.2d.matrix(1,1,1,1))

  df <- as.data.frame(x)
  expect_equal(normalise(df),
               as.matrix(data.frame(V1=c(1,1.5,2), V2=c(1,1.5,2)))) 
})