-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make tests easier to run interactively.
- Loading branch information
Showing
8 changed files
with
806 additions
and
971 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,48 @@ | ||
context('H3 custom functions') | ||
|
||
test_that( | ||
'cell_to_line returns correctly - vector', | ||
c(path <- c("8abe8d12adaffff", "8abe8d10536ffff", "8abe8d10526ffff", | ||
"8abe8d12a52ffff", "8abe8d12aceffff", "8abe8d12ac2ffff"), | ||
val1 <- cell_to_line(path), | ||
val2 <- cell_to_line(path, simple = FALSE), | ||
expect_is(val1, 'sfc_LINESTRING'), | ||
expect_length(val1, 1), | ||
expect_is(val2, 'sf'), | ||
expect_equal(ncol(val2), 2), | ||
expect_type(val2$input, 'list'), | ||
expect_is(val2$geometry, 'sfc_LINESTRING') | ||
) | ||
) | ||
test_that('cell_to_line returns correctly - vector', { | ||
path <- c("8abe8d12adaffff", "8abe8d10536ffff", "8abe8d10526ffff", | ||
"8abe8d12a52ffff", "8abe8d12aceffff", "8abe8d12ac2ffff") | ||
val1 <- cell_to_line(path) | ||
val2 <- cell_to_line(path, simple = FALSE) | ||
expect_is(val1, 'sfc_LINESTRING') | ||
expect_length(val1, 1) | ||
expect_is(val2, 'sf') | ||
expect_equal(ncol(val2), 2) | ||
expect_type(val2$input, 'list') | ||
expect_is(val2$geometry, 'sfc_LINESTRING') | ||
}) | ||
|
||
test_that( | ||
'cell_to_line returns correctly - list of vectors', | ||
c(path <- c("8abe8d12adaffff", "8abe8d10536ffff", "8abe8d10526ffff", | ||
"8abe8d12a52ffff", "8abe8d12aceffff", "8abe8d12ac2ffff"), | ||
paths <- list(path, path, path), | ||
val1 <- cell_to_line(paths), | ||
val2 <- cell_to_line(paths, simple = FALSE), | ||
expect_is(val1, 'sfc_LINESTRING'), | ||
expect_length(val1, 3), | ||
expect_is(val2, 'sf'), | ||
expect_equal(ncol(val2), 2), | ||
expect_equal(nrow(val2), 3), | ||
expect_type(val2$input, 'list'), | ||
expect_is(val2$geometry, 'sfc_LINESTRING') | ||
) | ||
) | ||
test_that('cell_to_line returns correctly - list of vectors', { | ||
path <- c("8abe8d12adaffff", "8abe8d10536ffff", "8abe8d10526ffff", | ||
"8abe8d12a52ffff", "8abe8d12aceffff", "8abe8d12ac2ffff") | ||
paths <- list(path, path, path) | ||
val1 <- cell_to_line(paths) | ||
val2 <- cell_to_line(paths, simple = FALSE) | ||
expect_is(val1, 'sfc_LINESTRING') | ||
expect_length(val1, 3) | ||
expect_is(val2, 'sf') | ||
expect_equal(ncol(val2), 2) | ||
expect_equal(nrow(val2), 3) | ||
expect_type(val2$input, 'list') | ||
expect_is(val2$geometry, 'sfc_LINESTRING') | ||
}) | ||
|
||
test_that( | ||
'cell_to_line returns correctly - data.frame with list-column', | ||
c(library(sf), | ||
brisbane_hex_10 <- cell_to_polygon(input = '8abe8d12acaffff'), | ||
hex_sample <- get_disk_list('8abe8d12acaffff', 4)[[1]][[4]][seq(1,18,3)], | ||
hex_sample_polys <- cell_to_polygon(hex_sample), | ||
paths <- grid_path(rep('8abe8d12acaffff', 6), hex_sample), | ||
paths_df <- data.frame('ID' = seq(6), 'paths' = I(paths)), | ||
val1 <- cell_to_line(paths_df), | ||
val2 <- cell_to_line(paths_df, simple = FALSE), | ||
expect_is(val1, 'sfc_LINESTRING'), | ||
expect_length(val1, 6), | ||
expect_is(val2, 'sf'), | ||
expect_equal(ncol(val2), 3), | ||
expect_equal(nrow(val2), 6), | ||
ins <- sf::st_set_geometry(val2, NULL), # wierd behav when lib() missing | ||
expect_identical(ins, paths_df), | ||
expect_is(val2$geometry, 'sfc_LINESTRING') | ||
) | ||
) | ||
test_that('cell_to_line returns correctly - data.frame with list-column', { | ||
library(sf) | ||
brisbane_hex_10 <- cell_to_polygon(input = '8abe8d12acaffff') | ||
hex_sample <- get_disk_list('8abe8d12acaffff', 4)[[1]][[4]][seq(1,18,3)] | ||
hex_sample_polys <- cell_to_polygon(hex_sample) | ||
paths <- grid_path(rep('8abe8d12acaffff', 6), hex_sample) | ||
paths_df <- data.frame('ID' = seq(6), 'paths' = I(paths)) | ||
val1 <- cell_to_line(paths_df) | ||
val2 <- cell_to_line(paths_df, simple = FALSE) | ||
expect_is(val1, 'sfc_LINESTRING') | ||
expect_length(val1, 6) | ||
expect_is(val2, 'sf') | ||
expect_equal(ncol(val2), 3) | ||
expect_equal(nrow(val2), 6) | ||
ins <- sf::st_set_geometry(val2, NULL) # wierd behav when lib() missing | ||
expect_identical(ins, paths_df) | ||
expect_is(val2$geometry, 'sfc_LINESTRING') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,72 @@ | ||
context('prep_for_x methods') | ||
|
||
test_that('prep_for_pt2cell.sf works', { | ||
library(sf) | ||
nc <- sf::st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE) | ||
nc1 <- nc[1, ] | ||
expect_error(h3jsr:::prep_for_pt2cell(nc1)) | ||
no_crs_point <- sf::st_sf('geometry' = sf::st_sfc(sf::st_point(c(153,-27)))) | ||
expect_message(h3jsr:::prep_for_pt2cell(no_crs_point)) | ||
v1 <- h3jsr:::prep_for_pt2cell(no_crs_point) | ||
expect_is(v1, 'matrix') | ||
}) | ||
|
||
test_that('prep_for_pt2cell.sf works', | ||
c(library(sf), | ||
nc <- sf::st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE), | ||
nc1 <- nc[1, ], | ||
expect_error(h3jsr:::prep_for_pt2cell(nc1)), | ||
no_crs_point <- sf::st_sf('geometry' = sf::st_sfc(sf::st_point(c(153,-27)))), | ||
expect_message(h3jsr:::prep_for_pt2cell(no_crs_point)), | ||
v1 <- h3jsr:::prep_for_pt2cell(no_crs_point), | ||
expect_is(v1, 'matrix') | ||
)) | ||
test_that('prep_for_pt2cell.sfc works', { | ||
library(sf) | ||
nc <- sf::st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE) | ||
nc1 <- sf::st_geometry(nc[1, ]) | ||
expect_error(h3jsr:::prep_for_pt2cell(nc1)) | ||
no_crs_point <- sf::st_sfc(sf::st_point(c(153,-27))) | ||
expect_message(h3jsr:::prep_for_pt2cell(no_crs_point)) | ||
v1 <- h3jsr:::prep_for_pt2cell(no_crs_point) | ||
expect_is(v1, 'matrix') | ||
}) | ||
|
||
|
||
test_that('prep_for_pt2cell.sfc works', | ||
c(library(sf), | ||
nc <- sf::st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE), | ||
nc1 <- sf::st_geometry(nc[1, ]), | ||
expect_error(h3jsr:::prep_for_pt2cell(nc1)), | ||
no_crs_point <- sf::st_sfc(sf::st_point(c(153,-27))), | ||
expect_message(h3jsr:::prep_for_pt2cell(no_crs_point)), | ||
v1 <- h3jsr:::prep_for_pt2cell(no_crs_point), | ||
expect_is(v1, 'matrix') | ||
)) | ||
test_that('prep_for_pt2cell.sfg works', { | ||
library(sf) | ||
nc <- sf::st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE) | ||
nc1 <- sf::st_geometry(nc[1, ])[[1]] | ||
expect_error(h3jsr:::prep_for_pt2cell(nc1)) | ||
}) | ||
|
||
test_that('prep_for_pt2cell.sfg works', | ||
c(library(sf), | ||
nc <- sf::st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE), | ||
nc1 <- sf::st_geometry(nc[1, ])[[1]], | ||
expect_error(h3jsr:::prep_for_pt2cell(nc1)) | ||
)) | ||
test_that('prep_for_polyfill.sf works', { | ||
library(sf) | ||
no_crs_poly <- | ||
sf::st_sf('geometry' = sf::st_sfc( | ||
sf::st_polygon(list(matrix(c(150, -30, | ||
151, -30, | ||
151, -35, | ||
150, -35, | ||
150, -30), ncol = 2, byrow = T))))) | ||
expect_message(h3jsr:::prep_for_polyfill(no_crs_poly)) | ||
v1 <- h3jsr:::prep_for_polyfill(no_crs_poly) | ||
expect_is(v1, 'geojson') | ||
}) | ||
|
||
test_that('prep_for_polyfill.sf works', | ||
c(library(sf), | ||
no_crs_poly <- | ||
sf::st_sf('geometry' = sf::st_sfc( | ||
sf::st_polygon(list(matrix(c(150, -30, | ||
151, -30, | ||
151, -35, | ||
150, -35, | ||
150, -30), ncol = 2, byrow = T))))), | ||
expect_message(h3jsr:::prep_for_polyfill(no_crs_poly)), | ||
v1 <- h3jsr:::prep_for_polyfill(no_crs_poly), | ||
expect_is(v1, 'geojson') | ||
)) | ||
test_that('prep_for_polyfill.sf works', { | ||
library(sf) | ||
no_crs_poly <- | ||
sf::st_sfc( | ||
sf::st_polygon(list(matrix(c(150, -30, | ||
151, -30, | ||
151, -35, | ||
150, -35, | ||
150, -30), ncol = 2, byrow = T)))) | ||
expect_message(h3jsr:::prep_for_polyfill(no_crs_poly)) | ||
v1 <- h3jsr:::prep_for_polyfill(no_crs_poly) | ||
expect_is(v1, 'geojson') | ||
}) | ||
|
||
test_that('prep_for_polyfill.sf works', | ||
c(library(sf), | ||
no_crs_poly <- | ||
sf::st_sfc( | ||
sf::st_polygon(list(matrix(c(150, -30, | ||
151, -30, | ||
151, -35, | ||
150, -35, | ||
150, -30), ncol = 2, byrow = T)))), | ||
expect_message(h3jsr:::prep_for_polyfill(no_crs_poly)), | ||
v1 <- h3jsr:::prep_for_polyfill(no_crs_poly), | ||
expect_is(v1, 'geojson') | ||
)) | ||
|
||
|
||
test_that( | ||
'prepped geojson returns correctly', | ||
c( | ||
nc <- sf::st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE), | ||
nc1 <- nc[1, ], | ||
val1 <- h3jsr:::prep_for_polyfill(nc1), | ||
val2 <- h3jsr:::prep_for_polyfill(sf::st_geometry(nc1)), | ||
nc1_84 <- sf::st_transform(nc1, 4326), | ||
val3 <- | ||
h3jsr:::prep_for_polyfill(sf::st_geometry(nc1_84)[[1]]), | ||
expect_is(val1, 'geojson'), | ||
expect_equal(val1, val2), | ||
expect_equal(val1, val3) | ||
) | ||
) | ||
test_that('prepped geojson returns correctly', { | ||
nc <- sf::st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE) | ||
nc1 <- nc[1, ] | ||
val1 <- h3jsr:::prep_for_polyfill(nc1) | ||
val2 <- h3jsr:::prep_for_polyfill(sf::st_geometry(nc1)) | ||
nc1_84 <- sf::st_transform(nc1, 4326) | ||
val3 <- | ||
h3jsr:::prep_for_polyfill(sf::st_geometry(nc1_84)[[1]]) | ||
expect_is(val1, 'geojson') | ||
expect_equal(val1, val2) | ||
expect_equal(val1, val3) | ||
}) |
Oops, something went wrong.