Skip to content

Commit ea193ab

Browse files
committed
Add complement test
1 parent 7952f11 commit ea193ab

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tests/testthat/test-filter.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,20 @@ test_that("`filter()` doesn't allow data frames with missing or empty names (#67
780780
})
781781
})
782782

783+
test_that("`filter()` and `filter_out()` are complements", {
784+
df <- tibble(
785+
x = c(TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, NA, NA, NA),
786+
y = c(TRUE, FALSE, NA, TRUE, FALSE, NA, TRUE, FALSE, NA)
787+
)
788+
789+
# Important invariant is that these are equivalent up to row ordering
790+
# `union(filter(df, ...), filter_out(df, ...)) ~= df`
791+
expect_identical(
792+
union(filter(df, x, y), filter_out(df, x, y)) |> arrange(x, y),
793+
df |> arrange(x, y)
794+
)
795+
})
796+
783797
# .by -------------------------------------------------------------------------
784798

785799
test_that("can group transiently using `.by`", {

0 commit comments

Comments
 (0)