tests/testthat/testthat.R

library(readxl)
#library(lib5af)
context("electio")
# GenData$`M proc`
# GenData$`C proc`
# GenData$`FP proc`
# GenData$`KD proc`
# GenData$`S proc`
# GenData$`V proc`
# GenData$`MP proc`
# GenData$`SD proc`
# GenData$`FI proc`


test_that("class is correct", {
  test_exempel <- electio("2014_landstingsval_per_kommun.xls")
  expect_true(class(test_exempel)[1] == "electio")
})


test_that("electio does not work with wrong input", {
  expect_error(electio("this_path_doesnot_exist.xls"))
  expect_error(electio())
  expect_error(electio(FALSE))
})


test_that("class is correct", {
  test_exempel <- electio("2014_landstingsval_per_kommun.xls")
  expect_true(class(test_exempel)[1] == "electio")
})


test_that("calc_mean() gives a correct result", {
  test_exempel <- electio("2014_landstingsval_per_kommun.xls")
  expect_equal(test_exempel$calc_mean_mproc(), round(18.3498,3))
  expect_equal(test_exempel$calc_mean_cproc(), round(8.935917,3))
  expect_equal(test_exempel$calc_mean_fpproc(), round(5.042837,3))
  expect_equal(test_exempel$calc_mean_kdproc(), round(5.384498,3))
  expect_equal(test_exempel$calc_mean_sproc(), round(35.96512,3))
})


test_that("get_dim() gives a correct result", {
  test_exempel <- electio("2014_landstingsval_per_kommun.xls")
  expect_equal(test_exempel$get_dim(), c(289,120))
})


test_that("get_nrow() gives a correct result", {
  test_exempel <- electio("2014_landstingsval_per_kommun.xls")
  expect_equal(test_exempel$get_nrow(), 289)
})


test_that("ncol() gives a correct result", {
  test_exempel <- electio("2014_landstingsval_per_kommun.xls")
  expect_equal(test_exempel$get_ncol(), 120)
})


test_that("get_dim() gives an error if the input is wrong", {
  test_exempel <- electio("2014_landstingsval_per_kommun.xls")
  expect_error(test_exempel$get_dim(558))
})


test_that("calc_mean_mproc() gives an error if the input is wrong", {
  test_exempel <- electio("2014_landstingsval_per_kommun.xls")
  expect_error(test_exempel$calc_mean_mproc(333))
})
afuergut/lib5af documentation built on May 31, 2019, 8:40 a.m.