tests/testthat/test-btb_ptsToGrid.R

test_that("btb_ptsToGrid works", {

  pts1 <- data.frame(x_centro = c(100, 100, 300, 300, 500), y_centro = c(100, 300, 100, 300, 100))
  sfpts1 <- sf::st_as_sf(pts1,coords=c("x_centro","y_centro"),crs=2154)
  
  result0 <- btb::btb_ptsToGrid(pts = pts1, iCellSize = 200)
  result1 <- btb_ptsToGrid(pts = pts1, sEPSG = "2154", iCellSize = 200)
  result2 <- btb_ptsToGrid(pts = sfpts1, iCellSize = 200)
  
  # The result is an sf object
  testthat::expect_equal(class(result1),c("sf","data.frame"))
  
  # Not working if no iCellSize
  testthat::expect_error(btb_ptsToGrid(pts = pts1, sEPSG = "2154"))
  
  # Same result with df and sf 
  testthat::expect_identical(result1,result2)
  
  # Take into account epsg of sf object
  testthat::expect_false(identical(result0,result2))
})

Try the btb package in your browser

Any scripts or data that you put into this service are public.

btb documentation built on Oct. 24, 2022, 5:10 p.m.