WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit d2dc2bf

Browse files
committed
Add some epix_slide output col dedupe tests
1 parent 4f8e8d5 commit d2dc2bf

File tree

1 file changed

+64
-5
lines changed

1 file changed

+64
-5
lines changed

tests/testthat/test-epix_slide.R

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -772,10 +772,69 @@ test_that("`epix_slide` works with .before = Inf", {
772772
})
773773

774774
test_that("`epix_slide` de-dupes labeling & value columns", {
775-
expect_identical(
776-
xx %>% epix_slide(version = .version),
777-
xx$DT %>% as.data.frame() %>% as_tibble() %>% distinct(version) %>% arrange(version)
775+
# Deduping `version`:
776+
# When comp is formula -> unpacked tibble:
777+
forecasts1a <- xx %>% epix_slide(~ tibble(
778+
version = .version,
779+
geo_value = "not a group label, can be anything",
780+
time_value = .version + c(0, 7),
781+
value = 42
782+
))
783+
# When comp is data-masking:
784+
forecasts1b <- xx %>% epix_slide(
785+
version = .version,
786+
geo_value = "not a group label, can be anything",
787+
time_value = .version + c(0, 7),
788+
value = 42
789+
)
790+
# Expected value:
791+
forecasts1ref <- tibble(
792+
version = rep(test_date + 4:7, each = 2L),
793+
geo_value = "not a group label, can be anything",
794+
time_value = version + c(0, 7),
795+
value = 42
796+
)
797+
expect_equal(forecasts1a, forecasts1ref)
798+
expect_equal(forecasts1b, forecasts1ref)
799+
# Mismatch not accepted:
800+
expect_error(xx %>% epix_slide(
801+
version = .version - 1,
802+
time_value = version + c(0, 7),
803+
value = 42
804+
))
805+
# Solely parroting back values without any new columns seems likely to be
806+
# nonsense (though this example would sort of act like a `distinct`
807+
# operation if we accepted it):
808+
expect_error(xx %>% epix_slide(~ .version, .new_col_name = "version"))
809+
810+
# Deduping group label:
811+
# When comp is formula -> unpacked tibble:
812+
forecasts2a <- xx %>% group_by(geo_value) %>% epix_slide(~ tibble(
813+
geo_value = .group_key$geo_value,
814+
version = .version,
815+
time_value = .version + c(0, 7),
816+
value = 42
817+
))
818+
# When comp is data-masking:
819+
forecasts2b <- xx %>% group_by(geo_value) %>% epix_slide(
820+
geo_value = .group_key$geo_value,
821+
version = .version,
822+
time_value = .version + c(0, 7),
823+
value = 42
778824
)
779-
expect_error(xx %>% epix_slide(version = .version + 1))
780-
# FIXME more tests
825+
# Expected value:
826+
forecasts2ref <- tibble(
827+
geo_value = "ak",
828+
version = rep(test_date + 4:7, each = 2L),
829+
time_value = version + c(0, 7),
830+
value = 42
831+
) %>% group_by(geo_value)
832+
expect_equal(forecasts2a, forecasts2ref)
833+
expect_equal(forecasts2b, forecasts2ref)
834+
# Mismatch not accepted:
835+
expect_error(xx %>% group_by(geo_value) %>% epix_slide(geo_value = "bogus"))
836+
# Solely parroting back values without any new columns seems likely to be
837+
# nonsense (though this example would sort of act like a `distinct`
838+
# operation if we accepted it):
839+
expect_error(xx %>% group_by(geo_value) %>% epix_slide(~ .group_key$geo_value, .new_col_name = "geo_value"))
781840
})

0 commit comments

Comments
 (0)