Test axes set on summarise step only

This commit is contained in:
Sharla Gelfand 2021-05-10 09:43:44 -04:00
Родитель 132161c51b
Коммит 94bb5533c7
4 изменённых файлов: 21 добавлений и 1 удалений

Просмотреть файл

@ -1,4 +1,4 @@
# Test that for a specific value of meta.parse
# Test for a specific value of meta.parse
expect_meta_parse_value <- function(specs, parse_value) {
meta_parse <- specs %>%
purrr::map(jsonlite::fromJSON) %>%
@ -11,6 +11,19 @@ expect_meta_parse_value <- function(specs, parse_value) {
expect_true(identical(unique(meta_parse), parse_value))
}
# Test that meta.axes is true or false
expect_meta_axes <- function(specs, axes_value) {
meta_axes <- specs %>%
purrr::map(jsonlite::fromJSON) %>%
purrr::transpose() %>%
purrr::pluck("meta") %>%
purrr::transpose() %>%
purrr::pluck("axes") %>%
unlist()
expect_true(identical(unique(meta_axes), axes_value))
}
# Test that the data.values are the same as the passed data frame
expect_data_values <- function(single_spec, df) {
df <- df %>%

Просмотреть файл

@ -4,6 +4,7 @@ test_that("prep_specs_data returns a vega lite spec of length 1, with one data v
expect_data_values(specs[[1]], mtcars %>% dplyr::count())
expect_meta_parse_value(specs, "grid")
expect_meta_axes(specs, NULL) # Axes are not shown
expect_no_grouping(specs)
expect_mark_encoding_top_level(specs)
})

Просмотреть файл

@ -8,6 +8,7 @@ test_that("prep_specs_group_by returns a list, with one element for each groupin
expect_data_values(specs[[1]], dplyr::count(palmerpenguins::penguins, species)) # one data value for each group combination, containing group levels and n
expect_spec_contains_mark_encoding(specs) # mark and encoding within spec
expect_meta_parse_value(specs, "grid") # meta.parse specifies grid
expect_meta_axes(specs, NULL) # Axes are not shown
expect_grouping_order(specs) # order of grouping is column, row, colour
# two groups ----
@ -19,6 +20,7 @@ test_that("prep_specs_group_by returns a list, with one element for each groupin
expect_data_values(specs[[2]], dplyr::count(palmerpenguins::penguins, species, island))
expect_spec_contains_mark_encoding(specs) # mark and encoding within spec
expect_meta_parse_value(specs, "grid") # meta.parse specifies grid
expect_meta_axes(specs, NULL) # Axes are not shown
expect_grouping_order(specs) # order of grouping is column, row, colour
# three groups
@ -31,6 +33,7 @@ test_that("prep_specs_group_by returns a list, with one element for each groupin
expect_data_values(specs[[3]], dplyr::count(palmerpenguins::penguins, species, island, sex))
expect_spec_contains_mark_encoding(specs) # mark and encoding within spec
expect_meta_parse_value(specs, "grid") # meta.parse specifies grid
expect_meta_axes(specs, NULL) # Axes are not shown
expect_grouping_order(specs) # order of grouping is column, row, colour
})

Просмотреть файл

@ -8,6 +8,7 @@ test_that("prep_specs_summarize returns a list with two elements - one for the j
expect_length(specs, 2) # Returns a list with two elements
expect_meta_parse_value(specs[1], "jitter") # First element meta.parse is jitter
expect_meta_parse_value(specs[2], NULL) # Second element meta is empty
expect_meta_axes(specs, TRUE) # Axes are set to TRUE to be shown
expect_data_values(specs[[1]], palmerpenguins::penguins %>%
dplyr::arrange(species) %>%
dplyr::mutate(x = 1, gemini_id = dplyr::row_number()) %>%
@ -32,6 +33,7 @@ test_that("prep_specs_summarize returns a list with two elements - one for the j
expect_length(specs, 2) # Returns a list with two elements
expect_meta_parse_value(specs[1], "jitter") # First element meta.parse is jitter
expect_meta_parse_value(specs[2], NULL) # Second element meta is empty
expect_meta_axes(specs, TRUE) # Axes are set to TRUE to be shown
expect_data_values(specs[[1]], palmerpenguins::penguins %>%
dplyr::arrange(species, island, sex) %>%
dplyr::mutate(
@ -64,6 +66,7 @@ test_that("prep_specs_summarize returns a list with two elements - one for the j
expect_length(specs, 2) # Returns a list with two elements
expect_meta_parse_value(specs[1], "jitter") # First element meta.parse is jitter
expect_meta_parse_value(specs[2], NULL) # Second element meta is empty
expect_meta_axes(specs, TRUE) # Axes are set to TRUE to be shown
expect_data_values(specs[[1]], palmerpenguins::penguins %>%
dplyr::mutate(x = 1, gemini_id = dplyr::row_number()) %>%
dplyr::select(gemini_id, y = bill_length_mm, x)) # One data value for each row in the input data frame, containing grouping variables - x value depending on the grouping - x = 1 if n_groups != 3