From 4ce2bf81afbcd9ce8b8ba57e79ae2f62fc0862a0 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 16 Apr 2020 19:34:52 +1000 Subject: [PATCH] tests - close #77 --- tests/testthat/test-sf_boxes.R | 44 ++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/testthat/test-sf_boxes.R diff --git a/tests/testthat/test-sf_boxes.R b/tests/testthat/test-sf_boxes.R new file mode 100644 index 0000000..338b228 --- /dev/null +++ b/tests/testthat/test-sf_boxes.R @@ -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" ) + ) + +})