tests/testthat/test-ifn.R

context("test-ifn.R")

test_that("IFN Placette", {
  skip_on_os("windows")
  donnees <- system.file("extdata/IFN", package = "gftools")
  pla_ifn <- gftools::getFich_IFN(obj = c("Pla"), Peup = FALSE, Morts = FALSE, Doc = TRUE, ans = 2016, doss = donnees)
  t1 <- pla_ifn$Doc$`2016`[1, ] %>%
    dplyr::mutate_all(as.character)
  t1$code <- as.character(t1$code)
  t2 <- pla_ifn$Pla$`2016`[1, ] %>%
    dplyr::mutate_all(as.character)
  df1 <- data.frame("ABOND", "1", "0 à 5 % (présence faible)") %>%
    dplyr::mutate_all(as.character)
  colnames(df1) <- names(t1)
  df2 <- data.frame(1100003, 765785, 6666116, 58, "G23", 1, 0, 0, "", 6, 2, 4, 1, 0, 3, "", "P", NA, NA, 0, 0, 0, 2, 0, NA) %>%
    dplyr::mutate_all(as.character)
  colnames(df2) <- names(t2)
  rownames(t1) <- NULL
  rownames(df1) <- NULL
  rownames(t2) <- NULL
  rownames(df2) <- NULL
  expect_equal(t1$code, df1$code)
  expect_equal(t1$donnee, df1$donnee)
  expect_equal(t2, df2)
  # expect_equal(2*2, 4)
})

test_that("IFN Arbre", {
  skip_on_os("windows")
  donnees <- system.file("extdata/IFN", package = "gftools")
  arb_ifn <- gftools::getFich_IFN(obj = c("Arb"), Peup = FALSE, Morts = FALSE, Doc = TRUE, ans = 2016, doss = donnees)
  t1 <- arb_ifn$Doc$`2016`[1, ] %>%
    dplyr::mutate_all(as.character)
  t1$code <- as.character(t1$code)
  t2 <- arb_ifn$Arb$`2016`[1, ] %>%
    dplyr::mutate_all(as.character)
  df1 <- data.frame("ABOND", "1", "0 à 5 % (présence faible)") %>%
    dplyr::mutate_all(as.character)
  colnames(df1) <- names(t1)
  df2 <- data.frame(1100003, 1, 0, 0, 0, 62, 1, 2, 0, 0, 0, NA, 0, 104, 9, 27.5, 24.4, 0, "S1", 0, NA, NA, 1.071, 39.28) %>%
    dplyr::mutate_all(as.character)
  colnames(df2) <- names(t2)
  rownames(t1) <- NULL
  rownames(df1) <- NULL
  rownames(t2) <- NULL
  rownames(df2) <- NULL
  expect_equal(t1$code, df1$code)
  expect_equal(t1$donnee, df1$donnee)
  expect_equal(t2, df2)
  # expect_equal(2*2, 4)
})

test_that("IFN Ecologie", {
  skip_on_os("windows")
  donnees <- system.file("extdata/IFN", package = "gftools")
  eco_ifn <- gftools::getFich_IFN(obj = c("Eco"), Peup = FALSE, Morts = FALSE, Doc = TRUE, ans = 2016, doss = donnees)
  t1 <- eco_ifn$Doc$`2016`[1, ] %>%
    dplyr::mutate_all(as.character)
  t1$code <- as.character(t1$code)
  t2 <- eco_ifn$Eco$`2016`[1, ] %>%
    dplyr::mutate_all(as.character)
  df1 <- data.frame("ABOND", "1", "0 à 5 % (présence faible)") %>%
    dplyr::mutate_all(as.character)
  colnames(df1) <- names(t1)
  df2 <- data.frame(1100003, "12/04/2016", NA, 4, NA, 17, 385, 0, 21, "", 102, NA, 0, 0, 0, 0, 5, 0, 6, NA, 2, NA, NA, NA, NA, NA, NA, 35, 1, 8, 8, NA, 1, 1, 2, 2, 0, 7) %>%
    dplyr::mutate_all(as.character)
  colnames(df2) <- names(t2)
  rownames(t1) <- NULL
  rownames(df1) <- NULL
  rownames(t2) <- NULL
  rownames(df2) <- NULL
  expect_equal(t1$code, df1$code)
  expect_equal(t1$donnee, df1$donnee)
  expect_equal(t2, df2)
  # expect_equal(2*2, 4)
})

test_that("IFN Flore", {
  skip_on_os("windows")
  donnees <- system.file("extdata/IFN", package = "gftools")
  flo_ifn <- gftools::getFich_IFN(obj = c("Flore"), Peup = FALSE, Morts = FALSE, Doc = TRUE, ans = 2016, doss = donnees)
  t1 <- flo_ifn$Doc$`2016`[1, ] %>%
    dplyr::mutate_all(as.character)
  t1$code <- as.character(t1$code)
  t2 <- flo_ifn$Flo$`2016`[1, ] %>%
    dplyr::mutate_all(as.character)
  df1 <- data.frame("ABOND", "1", "0 à 5 % (présence faible)") %>%
    dplyr::mutate_all(as.character)
  colnames(df1) <- names(t1)
  df2 <- data.frame(1100003, 5426, 2) %>%
    dplyr::mutate_all(as.character)
  colnames(df2) <- names(t2)
  rownames(t1) <- NULL
  rownames(df1) <- NULL
  rownames(t2) <- NULL
  rownames(df2) <- NULL
  expect_equal(t1$code, df1$code)
  expect_equal(t1$donnee, df1$donnee)
  expect_equal(t2, df2)
  # expect_equal(2*2, 4)
})

test_that("IFN Couv", {
  skip_on_os("windows")
  donnees <- system.file("extdata/IFN", package = "gftools")
  cou_ifn <- gftools::getFich_IFN(obj = c("Couv"), Peup = TRUE, Morts = TRUE, Doc = TRUE, ans = 2016, doss = donnees)
  t1 <- cou_ifn$Doc$`2016`[1, ] %>%
    dplyr::mutate_all(as.character)
  t1$code <- as.character(t1$code)
  t2 <- cou_ifn$Cou$`2016`[1, ] %>%
    dplyr::mutate_all(as.character)
  df1 <- data.frame("ABOND", "1", "0 à 5 % (présence faible)") %>%
    dplyr::mutate_all(as.character)
  colnames(df1) <- names(t1)
  df2 <- data.frame(1100003, "03", 0, 0) %>%
    dplyr::mutate_all(as.character)
  colnames(df2) <- names(t2)
  rownames(t1) <- NULL
  rownames(df1) <- NULL
  rownames(t2) <- NULL
  rownames(df2) <- NULL
  expect_equal(t1$code, df1$code)
  expect_equal(t1$donnee, df1$donnee)
  expect_equal(t2, df2)
  # expect_equal(2*2, 4)
})

test_that("IFN Liste des fichiers zip (IFN)", {
  skip_on_os("windows")
  donnees <- system.file("extdata/IFN", package = "gftools")
  test <- basename(gftools::getListFich_IFN(donnees)$Zip)
  df <- c(
    "2005-8.zip", "2006-8.zip", "2007-8.zip", "2008-9.zip", "2009-7.zip", "2010-6.zip",
    "2011-5.zip", "2012-4.zip", "2013-3.zip", "2014-2.zip", "2015-4.zip", "2016-8.zip"
  )
  expect_identical(test, df)
  # expect_equal(2*2, 4)
})

test_that("Peup = TRUE", {
  skip_on_appveyor()
  skip_on_travis()
  pp <- gftools::getFich_IFN(obj = c("Pla"), Peup = TRUE, Morts = FALSE, Doc = TRUE, ans = 2016, doss = system.file("extdata/IFN", package = "gftools"))
  expect_equal(length(pp), 3)
})

test_that("Pas acces dossier", {
  expect_error(gftools::getListFich_IFN(doss = ""))
})

test_that("Pas de zip dans dossier", {
  expect_error(gftools::getListFich_IFN(doss = "/tmp/"))
})

test_that("Mauvais argument", {
  expect_error(gftools::getFich_IFN(obj = c("Bad"), Peup = FALSE, Morts = FALSE, Doc = TRUE, ans = 2016, doss = system.file("extdata/IFN", package = "gftools")))
})

test_that("'ans' doit être numeric", {
  expect_error(gftools::getFich_IFN(obj = c("Flore"), Peup = FALSE, Morts = FALSE, Doc = TRUE, ans = "2016", doss = system.file("extdata/IFN", package = "gftools")))
})

test_that("Pas de data pour l'année", {
  expect_error(gftools::getFich_IFN(obj = c("Flore"), Peup = FALSE, Morts = FALSE, Doc = TRUE, ans = 2004, doss = system.file("extdata/IFN", package = "gftools")))
})

test_that("Objet indisponible pour l'année", {
  skip_on_os("windows")
  expect_message(
    gftools::getFich_IFN(obj = c("Flore"), Peup = FALSE, Morts = FALSE, Doc = TRUE, ans = 2015, doss = system.file("extdata/IFN", package = "gftools")),
    "Year 2015 not available"
  )
  # expect_equal(2*2, 4)
})
pobsteta/gftools documentation built on March 28, 2020, 8:25 p.m.