Skip to content
This repository has been archived by the owner on May 10, 2022. It is now read-only.

Commit

Permalink
fix tests for new v8, #78
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed Jan 31, 2019
1 parent 7b04c12 commit 319855c
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 22 deletions.
14 changes: 9 additions & 5 deletions tests/testthat/test-count.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ test_that("lawn_count works", {
expect_is(a$features, "data.frame")
expect_named(a$features$properties, c("values", "count"))

expect_equal(sum(lawn_count(lawn_data$polygons_average, lawn_data$points_average, "population")$features$properties$count), 5)
expect_equal(sum(
lawn_count(lawn_data$polygons_average,
lawn_data$points_average, "population")$features$properties$count), 5)
})

test_that("count fails correctly", {
expect_error(lawn_count(), "argument \"polygons\" is missing, with no default")
expect_error(lawn_count(),
"argument \"polygons\" is missing, with no default")
expect_error(lawn_count(polygons = ply, points = 4, "population"),
"Cannot call method 'map' of undefined")
expect_error(lawn_count(polygons = ply, points = 4, "population", lint = TRUE),
"Polygons and MultiPolygons should follow the right-hand rule")
"Cannot read property 'map' of undefined")
expect_error(
lawn_count(polygons = ply, points = 4, "population", lint = TRUE),
"Polygons and MultiPolygons should follow the right-hand rule")
})
2 changes: 1 addition & 1 deletion tests/testthat/test-intersect.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ test_that("fails correctly", {
expect_error(lawn_intersect(),
"argument \"poly1\" is missing, with no default")
expect_error(lawn_intersect(lawn_data$points_average, lawn_data$points_count),
"has no method 'intersection'")
"a.intersection is not a function")
expect_error(lawn_intersect(poly1, sub("Polygon", "polygon", poly2)),
"Unknown Geometry Type")
expect_error(lawn_intersect(poly1, sub("Feature", "feature", poly2)),
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/test-max.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ test_that("lawn_max fails correctly", {
# wrong in_field param leads to no ouput for max
expect_null(lawn_max(poly, pt, 'population2')$features$properties$max)
# can't pass in a character string to cellWidth
expect_error(lawn_max(poly, "{}", 'population', 'max'), "Cannot call method")
expect_error(lawn_max(poly, "{}", 'population', 'max'),
"Cannot read property")
# can't pass in a character string to cellWidth
expect_error(lawn_max(poly, "{}", 'population', 'max', lint = TRUE),
'Line 1 - "type" member required')
Expand Down
24 changes: 17 additions & 7 deletions tests/testthat/test-median.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,27 @@ test_that("lawn_median returns correct classes", {

test_that("in_field and out_field parameter works as expected", {
expect_equal(
length(na.omit(lawn_median(poly, pt, 'population2', 'median')$features$properties$median)),
0)
expect_named(lawn_median(poly, pt, 'population', 'bears')$features$properties,
c('values', 'bears'))
length(
na.omit(
lawn_median(
poly, pt, 'population2', 'median')$features$properties$median)),
0
)
expect_named(
lawn_median(poly, pt, 'population', 'bears')$features$properties,
c('values', 'bears'))
})

test_that("lawn_median fails correctly", {
# missing arguments
expect_error(lawn_median(), "argument \"in_field\" is missing, with no default")
expect_error(lawn_median(),
"argument \"in_field\" is missing, with no default")
# wrong in_field param leads to no ouput for median
expect_equal(
length(na.omit(lawn_median(poly, pt, 'population2', 'median')$features$properties$median)), 0)
expect_error(lawn_median(poly, "{}", 'population', 'median'), "Cannot call method")
length(
na.omit(
lawn_median(poly, pt,
'population2', 'median')$features$properties$median)), 0)
expect_error(lawn_median(poly, "{}", 'population', 'median'),
"Cannot read property")
})
18 changes: 13 additions & 5 deletions tests/testthat/test-sum.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,22 @@ test_that("lawn_sum returns correct classes", {
})

test_that("in_field and out_field parameters works as expected", {
expect_named(lawn_sum(poly, pt, 'population')$features$properties, c('values', "sum"))
expect_named(lawn_sum(poly, pt, 'population', 'stuff')$features$properties, c('values', "stuff"))
expect_true(is.na(lawn_sum(poly, pt, 'population2', 'sum')$features$properties$sum[1]))
expect_named(
lawn_sum(poly, pt, 'population')$features$properties, c('values', "sum"))
expect_named(
lawn_sum(
poly, pt, 'population', 'stuff')$features$properties,
c('values', "stuff"))
expect_true(
is.na(
lawn_sum(poly, pt, 'population2', 'sum')$features$properties$sum[1]))
})

test_that("lawn_sum fails correctly", {
# missing arguments
expect_error(lawn_sum(), "argument \"in_field\" is missing, with no default")
expect_error(lawn_sum(),
"argument \"in_field\" is missing, with no default")
# can't pass in a character string to cellWidth
expect_error(lawn_sum(poly, "{}", 'population', 'sum'), "Cannot call method")
expect_error(lawn_sum(poly, "{}", 'population', 'sum'),
"Cannot read property")
})
6 changes: 4 additions & 2 deletions tests/testthat/test-tag.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ test_that("lawn_tag returns correct classes", {
})

test_that("polyId, out_field parameters works as expected", {
expect_named(lawn_tag(pts, polys, 'fill', 'stuff')$features$properties, "stuff")
expect_named(lawn_tag(pts, polys, 'fill', 'stuff')$features$properties,
"stuff")
})

test_that("lawn_tag fails correctly", {
# missing arguments
expect_error(lawn_tag(), "argument \"points\" is missing, with no default")
# wrong geojson input
expect_error(lawn_tag(pts, "{}", 'fill', 'marker-color'), "Cannot call method")
expect_error(lawn_tag(pts, "{}", 'fill', 'marker-color'),
"Cannot read property")
})
3 changes: 2 additions & 1 deletion tests/testthat/test-variance.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ test_that("lawn_variance fails correctly", {
0
)
# can't pass in a character string to cellWidth
expect_error(lawn_variance(poly, "{}", 'population', 'max'), "Cannot call method")
expect_error(lawn_variance(poly, "{}", 'population', 'max'),
"Cannot read property")
# can't pass in a character string to cellWidth
expect_error(lawn_variance(poly, "{}", 'population', 'max', lint = TRUE),
'Line 1 - "type" member required')
Expand Down

0 comments on commit 319855c

Please sign in to comment.