Skip to content

Commit

Permalink
tests - close #77
Browse files Browse the repository at this point in the history
  • Loading branch information
dcooley committed Apr 16, 2020
1 parent 430fe13 commit 4ce2bf8
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/testthat/test-sf_boxes.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
context("boxes")

## issue 77
test_that("boxes created",{

df <- data.frame(
id1 = c(1,1,1,1,1,1,1,1,2,2,2,2)
, id2 = c(1,1,1,1,2,2,2,2,1,1,1,1)
, x = c(0,0,1,1,1,1,2,2,3,4,4,3)
, y = c(0,1,1,0,1,2,2,1,3,3,4,4)
)

sf_line <- sfheaders::sf_linestring(
obj = df
, x = "x"
, y = "y"
, linestring_id = "id1"
)

sf <- sf_boxes( sf_line )
sfc <- sf_boxes( sf_line$geometry )
bbox <- sf_bbox( df, x = "x", y = "y" )

expect_equal(
sf$geometry
, sfc
)

expect_equal(
attr( sfc, "bbox" )
, bbox
)

expect_equal(
sf_bbox( sfc[1] )
, sf_bbox( df[ df$id1 == 1, ], x = "x", y = "y" )
)

expect_equal(
sf_bbox( sfc[2] )
, sf_bbox( df[ df$id1 == 2, ], x = "x", y = "y" )
)

})

0 comments on commit 4ce2bf8

Please sign in to comment.