tests/testthat/test-auto_extent.R

test_that("auto_extent() works on pseudo-data", {

  x <- c(200, 300, 400)
  y <- c(550, 610, 670, 730)

  expected <- raster::extent(c(
    xmin = 150,   # 50 less than min(X)
    xmax = 450,   # 50 more than max(X)
    ymin = 520,   # 30 less than min(Y)
    ymax = 760))  # 30 more than max(Y)

  actual <- auto_extent(x, y)
  expect_equal(actual, expected)

})

test_that("auto_extent works on real data", {

  x <- c(549666.33, 549766.33, 549866.33, 549966.33, 550066.33, 550166.33, 550266.33, 550366.33, 550466.33, 550566.33, 550666.33, 550766.33, 550866.33, 550966.33, 551066.33, 551166.33, 551266.33, 551366.33, 551466.33, 551566.33, 551666.33, 551766.33, 551866.33, 551966.33, 552066.33, 552166.33, 552266.33, 552366.33, 552466.33, 552566.33, 552666.33, 552766.33, 552866.33, 552966.33, 553066.33, 553166.33, 553266.33, 553366.33, 553466.33, 553566.33, 553666.33, 553766.33, 553866.33, 553966.33, 554066.33, 554166.33, 554266.33, 554366.33, 554466.33, 554566.33, 554666.33, 554766.33, 554866.33, 554966.33, 555066.33, 555166.33, 555266.33, 555366.33, 555466.33, 555566.33, 555666.33, 555766.33, 555866.33, 555966.33, 556066.33, 556166.33, 556266.33, 556366.33, 556466.33, 556566.33, 556666.33, 556766.33, 556866.33, 556966.33, 557066.33, 557166.33, 557266.33, 557366.33, 557466.33, 557566.33, 557666.33, 557766.33, 557866.33, 557966.33, 558066.33, 558166.33, 558266.33, 558366.33, 558466.33, 558566.33, 558666.33, 558766.33, 558866.33, 558966.33, 559066.33, 559166.33, 559266.33, 559366.33, 559466.33, 559566.33, 559666.33, 559766.33, 559866.33, 559966.33, 560066.33, 560166.33, 560266.33, 560366.33, 560466.33, 560566.33, 560666.33, 560766.33, 560866.33, 560966.33, 561066.33, 561166.33, 561266.33, 561366.33, 561466.33, 561566.33, 561666.33, 561766.33, 561866.33, 561966.33, 562066.33, 562166.33, 562266.33, 562366.33, 562466.33)
  y <- c(4193259.66, 4193359.66, 4193459.66, 4193559.66, 4193659.66, 4193759.66, 4193859.66, 4193959.66, 4194059.66, 4194159.66, 4194259.66, 4194359.66, 4194459.66, 4194559.66, 4194659.66, 4194759.66, 4194859.66, 4194959.66, 4195059.66, 4195159.66, 4195259.66, 4195359.66, 4195459.66, 4195559.66, 4195659.66, 4195759.66, 4195859.66, 4195959.66, 4196059.66, 4196159.66, 4196259.66, 4196359.66, 4196459.66, 4196559.66, 4196659.66, 4196759.66, 4196859.66, 4196959.66, 4197059.66, 4197159.66, 4197259.66, 4197359.66, 4197459.66, 4197559.66, 4197659.66, 4197759.66, 4197859.66, 4197959.66, 4198059.66, 4198159.66, 4198259.66, 4198359.66, 4198459.66, 4198559.66, 4198659.66, 4198759.66, 4198859.66, 4198959.66, 4199059.66, 4199159.66, 4199259.66, 4199359.66, 4199459.66, 4199559.66, 4199659.66, 4199759.66, 4199859.66, 4199959.66, 4200059.66, 4200159.66, 4200259.66, 4200359.66, 4200459.66, 4200559.66, 4200659.66, 4200759.66, 4200859.66, 4200959.66, 4201059.66, 4201159.66, 4201259.66, 4201359.66, 4201459.66, 4201559.66, 4201659.66, 4201759.66, 4201859.66, 4201959.66, 4202059.66, 4202159.66, 4202259.66, 4202359.66, 4202459.66, 4202559.66, 4202659.66, 4202759.66, 4202859.66, 4202959.66, 4203059.66, 4203159.66, 4203259.66, 4203359.66, 4203459.66, 4203559.66, 4203659.66, 4203759.66, 4203859.66, 4203959.66, 4204059.66, 4204159.66, 4204259.66, 4204359.66, 4204459.66, 4204559.66, 4204659.66, 4204759.66, 4204859.66, 4204959.66, 4205059.66, 4205159.66, 4205259.66, 4205359.66, 4205459.66, 4205559.66, 4205659.66, 4205759.66, 4205859.66, 4205959.66, 4206059.66, 4206159.66, 4206259.66, 4206359.66, 4206459.66, 4206559.66, 4206659.66, 4206759.66, 4206859.66, 4206959.66, 4207059.66, 4207159.66, 4207259.66, 4207359.66, 4207459.66, 4207559.66, 4207659.66, 4207759.66, 4207859.66, 4207959.66, 4208059.66)

  expected <- raster::extent(c(
    xmin = 549616.33,   # min(x) - 50
    xmax = 562516.33,   # max(x) + 50
    ymin = 4193209.66,  # min(y) - 50,
    ymax = 4208109.66)) # max(y) + 50

  actual <- auto_extent(x, y)
  expect_equal(actual, expected)

})
BAAQMD/aertools documentation built on June 30, 2022, 9:10 p.m.