tests/testthat/test-estimate.en_lr.R

context("Tests for estimate.en_lr function")
library(binclass)

# Create example data
n = 900
K = 4
K_sig = 2
param = c( .25, .75 )
sim = bc_simulate( n, K, K_sig, param = param )
# Set up cross-validation
index = c( rep( 1, 600 ), rep( 2, 300 ) )
dat = train_test( 2, index, sim$y, sim$X )

# For debugging purposes
# control = list()

fit = bc_estimate( 'glmnet', dat )
test_that( "bc_estimate class works", {
  expect_true( is.bc_estimate( fit ) )
})

val = coef( fit )
tst = coef( fit$fit, s = fit$best_lambda )
rownames( tst ) = c( 'Intercept', rownames(tst)[-1] )
tst = tst[,1]
test_that( "coefficients are extracted correctly", {
  expect_equal( val, tst[-1] )
  expect_equal( coef( fit, int = T ), tst )
  expect_length( coef( fit, sig = F ), length( coef( sim ) ) + 1 )
})

test_that( "bc_estimate print method works", {
  expect_output( print( fit ) )
})

test_that( "features are extracted correctly", {
  expect_equal( features( fit ), names( val ) )
})

test_that( "bc_estimate levels method works correctly", {
  expect_equal( levels( fit ), levels( dat ) )
})
rettopnivek/binclass documentation built on May 13, 2019, 4:46 p.m.