Debian Codegraph @

tests/testthat/test-sets.R

raw
1 test_that("`sel_union()` matches named elements", {
2 expect_identical(sel_union(1L, c(foo = 1L)), c(foo = 1L))
3 expect_identical(sel_union(named(1L), c(foo = 1L)), c(foo = 1L))
4 expect_identical(sel_union(c(foo = 1L), 1L), c(foo = 1L))
5 expect_identical(sel_union(c(foo = 1L), named(1L)), c(foo = 1L))
6
7 expect_identical(sel_union(named(c(1L, 2L, 1L)), c(foo = 1L, 1L)), c(foo = 1L, 2L))
8 })
9
10 test_that("`sel_diff()` matches named elements", {
11 expect_identical(sel_diff(named(1L), named(1L)), named(int()))
12 expect_identical(sel_diff(named(1L), c(foo = 1L)), named(int()))
13 expect_identical(sel_diff(named(1L), c(foo = 1L, bar = 1L)), named(int()))
14
15 expect_identical(sel_diff(c(foo = 1L), named(1L)), named(int()))
16 expect_identical(sel_diff(c(foo = 1L), c(foo = 1L)), named(int()))
17 expect_identical(sel_diff(c(foo = 1L), c(bar = 1L)), c(foo = 1L))
18
19 expect_identical(sel_diff(c(foo = 1L), c(bar = 1L)), c(foo = 1L))
20 })
21
22 test_that("sel_intersect() matches named elements", {
23 expect_identical(sel_intersect(1L, c(foo = 1L)), c(foo = 1L))
24 expect_identical(sel_intersect(c(foo = 1L), 1L), c(foo = 1L))
25 expect_identical(sel_intersect(c(foo = 1L), c(bar = 1L)), named(int()))
26 })
27
28 test_that("sel_unique() returns unique elements", {
29 expect_identical(sel_unique(c(1L, foo = 1L, bar = 1L)), c(foo = 1L, bar = 1L))
30 })
31
32 test_that("unique elements are returned", {
33 expect_identical(sel_union(c(1L, 1L), 2L), c(1L, 2L))
34 expect_identical(sel_diff(c(1L, 1L), 2L), 1L)
35 expect_identical(sel_intersect(c(foo = 1L), c(foo = 1L, foo = 1L)), c(foo = 1L))
36 })
37
38 test_that("order is preserved", {
39 expect_identical(sel_union(c(1L, bar = 1L), c(1L, foo = 1L)), c(bar = 1L, foo = 1L))
40 expect_identical(sel_union(c(1L, foo = 1L), c(1L, bar = 1L)), c(foo = 1L, bar = 1L))
41 expect_identical(sel_union(c(1L, foo = 1L), c(1L, foo = 1L)), c(foo = 1L))
42
43 expect_identical(sel_intersect(c(1L, foo = 1L, bar = 1L), c(1L, bar = 1L, foo = 1L)), c(foo = 1L, bar = 1L))
44 expect_identical(sel_intersect(c(1L, bar = 1L, foo = 1L), c(1L, foo = 1L, bar = 1L)), c(bar = 1L, foo = 1L))
45
46 expect_identical(sel_diff(c(1L, foo = 1L, bar = 1L), c(1L, bar = 1L)), c(foo = 1L))
47 expect_identical(sel_diff(c(1L, bar = 1L, foo = 1L), c(1L, foo = 1L)), c(bar = 1L))
48 })