File: test-make-splits.R

package info (click to toggle)
r-cran-rsample 1.1.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,872 kB
  • sloc: sh: 13; makefile: 2
file content (58 lines) | stat: -rw-r--r-- 1,687 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
test_that("can create a split with an empty assessment set (#188)", {
  df <- data.frame(x = c(1, 2, 3, 4))
  indices <- list(analysis = 1:4, assessment = integer())

  split <- make_splits(indices, df)

  expect_identical(split$out_id, integer())
  expect_identical(assessment(split), df[0, , drop = FALSE])
})

test_that("cannot create a split with an empty analysis set", {
  df <- data.frame(x = c(1, 2, 3, 4))
  indices <- list(analysis = integer(), assessment = 1:4)

  expect_error(make_splits(indices, df), "At least one row")
})

test_that("create a split from training and testing dataframes", {
  training <- tibble(x = c(1, 2, 3, 4))
  testing <- tibble(x = c(5, 6))

  split <- make_splits(training, testing)
  expect_identical(analysis(split), training)
  expect_identical(assessment(split), testing)
})

test_that("can create a split from empty testing dataframe", {
  training <- tibble(x = c(1, 2, 3, 4))
  testing <- tibble()

  split <- make_splits(training, testing)
  expect_identical(split$out_id, integer())
  expect_identical(analysis(split), training)
})

test_that("cannot create a split from empty training dataframe", {
  training <- tibble()
  testing <- tibble(x = c(5, 6))

  expect_error(
    make_splits(training, testing),
    "The analysis set must contain at least one row."
  )
})

test_that("cannot create a split from dataframes with different columns", {
  training <- tibble(x = c(1, 2, 3, 4))
  testing <- tibble(y = c(5, 6))

  expect_error(
    make_splits(training, testing),
    "The analysis and assessment sets must have"
  )
})

test_that("improper argument", {
  expect_error(make_splits("potato"), "There is no method available to")
})