tests/testthat/test-detection.R

# Generated by fusen: do not edit by hand

library(testthat)
library(dplyr)


test_that("detection works", {
  expect_true(inherits(detection, "function")) 
})


test_that("test conformite detection", {

data(dataset_dist)
  
set.seed(2022)

test_1 <- dataset_dist %>%
  detection(key = "unif",
            g_zero = 0.8,
            truncation_m = 250) %>%
  slice(1:5)

test_2 <- dataset_dist %>%
  detection(key = "hn",
            esw_km = 0.16,
            g_zero = 1,
            truncation_m = 400) %>%
  slice(1:5)

exp_1 <- structure(list(distance_m = c(592.451095485624, 34.2171939374429, 
142.21559151234, 881.075391800576, 388.090137094113), Sample.Label = c("8-1", 
"14-10", "14-4", "16-11", "17-2"), size = c(1, 1, 1, 1, 1), distance_km = c(0.592451095485624, 
0.0342171939374429, 0.14221559151234, 0.881075391800576, 0.388090137094113
), x = c(-142269.524360142, -159212.578236191, -148643.452974568, 
-168285.730494252, -169143.988133009), y = c(6260733.72869475, 
6253182.64985506, 6247794.33171267, 6253187.6413422, 6251608.74650909
), object = 1:5, proba = c(0, 0.8, 0.8, 0, 0), detected = c(0, 
1, 1, 0, 0)), row.names = c(NA, -5L), class = "data.frame")

exp_2 <- structure(list(distance_m = c(592.451095485624, 34.2171939374429, 
142.21559151234, 881.075391800576, 388.090137094113), Sample.Label = c("8-1", 
"14-10", "14-4", "16-11", "17-2"), size = c(1, 1, 1, 1, 1), distance_km = c(0.592451095485624, 
0.0342171939374429, 0.14221559151234, 0.881075391800576, 0.388090137094113
), x = c(-142269.524360142, -159212.578236191, -148643.452974568, 
-168285.730494252, -169143.988133009), y = c(6260733.72869475, 
6253182.64985506, 6247794.33171267, 6253187.6413422, 6251608.74650909
), object = 1:5, proba = c(0, 0.964717278634771, 0.537673570466889, 
0, 0.00984513108491106), detected = c(0, 1, 0, 0, 0)), row.names = c(NA, 
-5L), class = "data.frame")

expect_equal(object = test_1,
             expected = exp_1)

expect_equal(object = test_2,
             expected = exp_2)

expect_is(test_1, "data.frame")
expect_is(test_2, "data.frame")

})

test_that("test erreur detection", {
  
  data(iris)
  data(dataset_dist)

  expect_error(object = detection(dist_obj = iris,
                                  key = "hn",
                                  esw_km = 0.16,
                                  g_zero = 1,
                                  truncation_m = 400))
  
  expect_error(object = detection(dist_obj = dataset_dist,
                                  key = "hoho",
                                  esw_km = 0.16,
                                  g_zero = 1,
                                  truncation_m = 400))
  
  expect_error(object = detection(dist_obj = dataset_dist,
                                  key = "hn",
                                  esw_km = "haha",
                                  g_zero = 1,
                                  truncation_m = 400))
  
  expect_error(object = detection(dist_obj = dataset_dist,
                                  key = "hn",
                                  esw_km = 0.16,
                                  g_zero = 1,
                                  truncation_m = "hihi"))
  
  expect_error(object = detection(dist_obj = dataset_dist,
                                  key = "unif",
                                  g_zero = "hehe",
                                  truncation_m = 400))
  
})
maudqueroue/intercali documentation built on Oct. 8, 2022, 2:09 p.m.