Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add some tests #74

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/testthat/test-indexing.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
context("roomba indexing tests")

test_that("", {
test_that("Test that dfs_idx() works as expected", {

twitter_data <- twitter_data
x <- dfs_idx(twitter_data, ~ .x$id_str == "998623997397876743")
Expand Down
28 changes: 28 additions & 0 deletions tests/testthat/test-roomba.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
context("roomba tests")

library(jsonlite)

test_that("Test that roomba() works as expected", {

some_json <- '{
"foo": [{"a": 1, "b": 2, "c": 3}],
"bar": [{"a": 4, "c": 6, "b": null}],
"baz": [],
"bing":[{"c": 12}]
}'

lst <- fromJSON(some_json)

expect_equal(roomba(lst, cols = c("a", "b", "c")),
data.frame(a = c(1, 4), b = c(2, NA), c = c(3, 6)))

expect_equal(roomba(lst, cols = c("a", "b", "c"), keep = any),
data.frame(a = c(1, 4, NA), b = c(2, NA, NA), c = c(3, 6, 12)))

expect_error(roomba(lst, cols = character()),
regexp = "Argument 1 must have names")

expect_error(roomba(lst),
regexp = "cols must be non-NULL.")

})
12 changes: 6 additions & 6 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ library(dplyr)
test_that("Test that replace_null() works as expected", {
# Test that replace_null() works as expected
lst <- list(c("a", "b"), x = NULL)
cleaned_lst <- roomba:::replace_null(lst, replacement = "foo")
cleaned_lst <- replace_null(lst, replacement = "foo")
expect_equal(cleaned_lst,
list(c("a", "b"), x = "foo"))
})
Expand Down Expand Up @@ -49,17 +49,17 @@ test_that("Test that replace_null() works with numbers", {
}', simplifyVector = FALSE)


cleaned_lst <- roomba:::replace_null(toy_data)
cleaned_lst <- replace_null(toy_data)

secret_power <- cleaned_lst %>% dfs_idx(~ .x$goodstuff == "here") %>%
purrr:::map_dfr(~ cleaned_lst[[.x]]) %>%
dplyr::pull(secret_power)
map_dfr(~ cleaned_lst[[.x]]) %>%
pull(secret_power)

expect_type(secret_power, "integer")

toy_names <- cleaned_lst %>% dfs_idx(~ .x$goodstuff == "here") %>%
purrr:::map_dfr(~ cleaned_lst[[.x]]) %>%
dplyr::pull(name)
map_dfr(~ cleaned_lst[[.x]]) %>%
pull(name)

expect_type(toy_names, "character")

Expand Down