Skip to content
Permalink
Browse files

changes to tests for issue #116

Most are related to tidyverse/dplyr#2751
  • Loading branch information...
Max Kuhn
Max Kuhn committed Jan 10, 2018
1 parent 6ef0720 commit c39586a4228552114f58730d236b73d1ff3c454a
Showing with 26 additions and 7 deletions.
  1. +7 −3 tests/testthat/test_center_scale.R
  2. +12 −2 tests/testthat/test_classdist.R
  3. +7 −2 tests/testthat/test_pca.R
@@ -1,6 +1,6 @@
library(testthat)
context("Testing center and scale")

library(rlang)
library(recipes)

means <- vapply(biomass[, 3:7], mean, c(mean = 0))
@@ -9,6 +9,9 @@ sds <- vapply(biomass[, 3:7], sd, c(sd = 0))
rec <- recipe(HHV ~ carbon + hydrogen + oxygen + nitrogen + sulfur,
data = biomass)

# Note: some tests convert to data frame prior to testing
# https://github.com/tidyverse/dplyr/issues/2751

test_that('correct means and std devs', {
standardized <- rec %>%
step_center(carbon, hydrogen, oxygen, nitrogen, sulfur) %>%
@@ -19,7 +22,7 @@ test_that('correct means and std devs', {
value = rep(na_dbl, 5))

expect_equal(tidy(standardized, 1), cent_tibble_un)
expect_equal(tidy(standardized, 2), cent_tibble_un)
expect_equal(as.data.frame(tidy(standardized, 2)), as.data.frame(cent_tibble_un))

standardized_trained <- prep(standardized, training = biomass, verbose = FALSE)

@@ -31,7 +34,8 @@ test_that('correct means and std devs', {
value = sds)

expect_equal(tidy(standardized_trained, 1), cent_tibble_tr)
expect_equal(tidy(standardized_trained, 2), scal_tibble_tr)
expect_equal(as.data.frame(tidy(standardized_trained, 2)), as.data.frame(scal_tibble_tr))


expect_equal(standardized_trained$steps[[1]]$means, means)
expect_equal(standardized_trained$steps[[2]]$sds, sds)
@@ -1,6 +1,13 @@
library(testthat)
library(recipes)

# Note: some tests convert to data frame prior to testing
# https://github.com/tidyverse/dplyr/issues/2751

eps <- if (capabilities("long.double"))
sqrt(.Machine$double.eps) else
0.1

test_that("defaults", {
rec <- recipe(Species ~ ., data = iris) %>%
step_classdist(all_predictors(), class = "Species", log = FALSE)
@@ -33,8 +40,11 @@ test_that("defaults", {
value = unname(means),
class = rep(names(split_up), each = 4)
)
expect_equal(tidy_exp_tr, tidy(trained, number = 1))

expect_equal(
as.data.frame(tidy_exp_tr),
as.data.frame(tidy(trained, number = 1)),
tolerance = eps
)
})

test_that("alt args", {
@@ -8,6 +8,9 @@ biomass_te <- biomass[biomass$dataset == "Testing",]
rec <- recipe(HHV ~ carbon + hydrogen + oxygen + nitrogen + sulfur,
data = biomass_tr)

# Note: some tests convert to data frame prior to testing
# https://github.com/tidyverse/dplyr/issues/2751

test_that('correct PCA values', {
pca_extract <- rec %>%
step_center(carbon, hydrogen, oxygen ,nitrogen, sulfur) %>%
@@ -46,8 +49,10 @@ test_that('correct PCA values', {
value = pca_obj$values,
component = as.character(pca_obj$ind)
)
expect_equal(tidy_exp_tr, tidy(pca_extract_trained, number = 3))

expect_equal(
as.data.frame(tidy_exp_tr),
as.data.frame(tidy(pca_extract_trained, number = 3))
)
})

test_that('correct PCA values with threshold', {

0 comments on commit c39586a

Please sign in to comment.
You can’t perform that action at this time.