File: test-data_restoretype.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 (34 lines) | stat: -rw-r--r-- 920 bytes parent folder | download | duplicates (2)
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
test_that("data_restoretype works with reference", {
  data <- data.frame(
    Sepal.Length = c("1", "3", "2"),
    Species = c("setosa", "versicolor", "setosa"),
    New = c("1", "3", "4"),
    stringsAsFactors = FALSE
  )

  fixed <- data_restoretype(data, reference = iris)

  expect_equal(typeof(fixed$Species), typeof(iris$Species))
  expect_equal(typeof(fixed$Sepal.Length), typeof(iris$Sepal.Length))
  expect_equal(typeof(fixed$New), "character")
})


test_that("data_restoretype works without reference", {
  data <- data.frame(
    Sepal.Length = c("1", "3", "2"),
    Species = c("setosa", "versicolor", "setosa"),
    New = c("1", "3", "4"),
    stringsAsFactors = FALSE
  )

  expect_equal(
    data_restoretype(data, reference = NULL),
    data.frame(
      Sepal.Length = c(1, 3, 2),
      Species = c("setosa", "versicolor", "setosa"),
      New = c(1, 3, 4),
      stringsAsFactors = FALSE
    )
  )
})