tests/testthat/test_label_encoder.R

## Set the context
   context("Check the label_encoder works properly")   

## Load Package & Data
   data(dataCar,package = 'insuranceData')
     
## Run the tests
   
   test_that(desc = 'the label encoder function works in general + conversions from data.frame',code = {
     
     lbl_encoded = label_encoder(df = dataCar,features = "veh_body")
     expect_equal(object = class(lbl_encoded$veh_body),'numeric')
     expect_equal(object = length(unique(dataCar$veh_body)),length(unique(lbl_encoded$veh_body)))
     
   })
   
   test_that(desc = 'the label encoder can handle data.tables',code = {
     
     lbl_encoded = label_encoder(df = as.data.table(dataCar),features = "veh_body")
     expect_equal(object = class(lbl_encoded$veh_body),'numeric')
     expect_equal(object = length(unique(dataCar$veh_body)),length(unique(lbl_encoded$veh_body)))
     
   })
   
   
   
   
gm209/gmtools documentation built on May 22, 2019, 2:39 p.m.