tests/testthat/test_bbox.R

# expected errors

testthat::expect_null(eo_bbox())

testthat::expect_error(eo_bbox(c(1)))

testthat::expect_error(eo_bbox(c(1,2)))

testthat::expect_error(eo_bbox(c(1,2,3)))

testthat::expect_error(eo_bbox(c(1,2,3,4,4)))

testthat::expect_error(eo_bbox(eo_bbox(c(1,2,3,4))))

testthat::expect_error(eo_bbox("abc"))

# bbox spatial operations

b1 <- eo_bbox(c(1,1,4,4))
b2 <- eo_bbox(c(0,0,1,1))
b3 <- eo_bbox(c(1,1,2,2))
b4 <- eo_bbox(c(2,2,3,3))
b5 <- eo_bbox(3,3,4,4)
b6 <- eo_bbox(4,4,5,5)
b7 <- eo_bbox(5,5,6,6)
b8 <- eo_bbox(0,0,5,5)
b9 <- eo_bbox(4,0,6,2)

# intersection
testthat::expect_true(.intersects(b1, b1))
testthat::expect_true(.intersects(b1, b2))
testthat::expect_true(.intersects(b1, b3))
testthat::expect_true(.intersects(b1, b4))
testthat::expect_true(.intersects(b1, b5))
testthat::expect_true(.intersects(b1, b6))
testthat::expect_false(.intersects(b1, b7))
testthat::expect_true(.intersects(b1, b8))
testthat::expect_true(.intersects(b1, b9))

# touching
testthat::expect_false(.touches(b1, b1))
testthat::expect_true(.touches(b1, b2))
testthat::expect_false(.touches(b1, b3))
testthat::expect_false(.touches(b1, b4))
testthat::expect_false(.touches(b1, b5))
testthat::expect_true(.touches(b1, b6))
testthat::expect_false(.touches(b1, b7))
testthat::expect_false(.touches(b1, b8))
testthat::expect_true(.touches(b1, b9))

# as.character
testthat::expect_equal(as.character(b1), "1,1,4,4")
testthat::expect_equal(as.character(b1), "1,1,4,4")
testthat::expect_equal(as.character(b2), "0,0,1,1")
testthat::expect_equal(as.character(b3), "1,1,2,2")
testthat::expect_equal(as.character(b4), "2,2,3,3")
testthat::expect_equal(as.character(b5), "3,3,4,4")
testthat::expect_equal(as.character(b6), "4,4,5,5")
testthat::expect_equal(as.character(b7), "5,5,6,6")
testthat::expect_equal(as.character(b8), "0,0,5,5")
testthat::expect_equal(as.character(b9), "4,0,6,2")
brazil-data-cube/eocubes.R documentation built on April 24, 2020, 9:34 a.m.