Skip to content

Commit 2d38f0a

Browse files
iterate tests
1 parent 1e76fa4 commit 2d38f0a

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

tests/testthat/test-sortuse64.R

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
test_that("orderfin and orderpos work with partial order", {
1+
with_parameters_test_that("orderfin and orderpos work with partial order", method=1:3, {
22
# These were segfaulting due to length(order) < length(table)
33
table = as.integer64(c(10, 20, 30, 5, 15, 25))
44
order = c(4, 1, 5, 2, 6, 3) # order of table is 5, 10, 15, 20, 25, 30
@@ -10,17 +10,18 @@ test_that("orderfin and orderpos work with partial order", {
1010
# reference with full order
1111
full_fin = c(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE)
1212
full_pos = c(4L, 1L, 5L, 2L, 6L, 3L, NA_integer_)
13-
expect_identical(orderfin(table, order, x), full_fin)
14-
expect_identical(orderpos(table, order, x), full_pos)
13+
expect_identical(orderfin(table, order, x, method=method), full_fin)
14+
expect_identical(orderpos(table, order, x, method=method), full_pos)
1515

1616
# with partial order, we search in a subset
1717
partial_fin = c(TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE)
1818
partial_pos = c(4L, 1L, 5L, 2L, NA_integer_, NA_integer_, NA_integer_)
19-
expect_identical(orderfin(table, partial_order, x), partial_fin)
20-
expect_identical(orderpos(table, partial_order, x), partial_pos)
19+
expect_identical(orderfin(table, partial_order, x, method=method), partial_fin)
20+
expect_identical(orderpos(table, partial_order, x, method=method), partial_pos)
2121

22-
# user's example, table is not sorted ascending with order
23-
# just check for no error
24-
expect_identical(orderfin(as.integer64(10:1), 1:3, 8:11, method=1L), c(TRUE, TRUE, TRUE, FALSE))
25-
expect_identical(orderpos(as.integer64(10:1), 1:3, 8:11, method=1L), c(1L, 2L, 3L, NA_integer_))
22+
# user's example, where `table[order]` is not sorted ascending.
23+
# The C functions expect ascending order, so they will fail to find the values.
24+
# The test confirms the functions no longer segfault and return a consistent result.
25+
expect_identical(orderfin(as.integer64(10:1), 1:3, 8:11, method=method), rep(FALSE, 4L))
26+
expect_identical(orderpos(as.integer64(10:1), 1:3, 8:11, method=method), rep(NA_integer_, 4L))
2627
})

0 commit comments

Comments
 (0)