Skip to content

Commit f5105c0

Browse files
Gemini: extend shellsortorder testing (#361)
1 parent d9e8688 commit f5105c0

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

tests/testthat/test-sort64.R

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ with_parameters_test_that(
103103

104104
na_entries = rep(NA_integer64_, n_missing)
105105
y = sample(c(x, if (duplicates) x[1L], na_entries))
106+
y_orig = bit::clone(y)
106107
i = seq_along(y)
107108
expect_identical(sortorder_function(y, i, decreasing=decreasing, na.last=na.last), n_missing)
108109
expected_value = c(
@@ -112,13 +113,12 @@ with_parameters_test_that(
112113
if (duplicates && decreasing) x[1L],
113114
if (na.last) na_entries else integer64()
114115
)
115-
# TODO(#159): Also add expectations for the update to i
116-
expect_identical(y, expected_value,
117-
info=sprintf(
118-
"(na.last, decreasing, duplicates, n_missing)=(%s, %s, %s, %d)",
119-
na.last, decreasing, duplicates, n_missing
120-
)
116+
info = sprintf(
117+
"(na.last, decreasing, duplicates, n_missing)=(%s, %s, %s, %d)",
118+
na.last, decreasing, duplicates, n_missing
121119
)
120+
expect_identical(y, expected_value, info=info)
121+
expect_identical(y_orig[i], expected_value, info=info)
122122
},
123123
.cases = expand.grid(
124124
sortorder_function = list(
@@ -163,6 +163,7 @@ test_that("Explicit algorithm dispatch hits C-level fallbacks and edge cases", {
163163
i = seq_along(x)
164164
bit::mergesortorder(x, i, decreasing=TRUE)
165165
expect_identical(x, as.integer64(sort(as.integer(x_base), decreasing=TRUE)))
166+
expect_identical(x_base[i], as.integer64(sort(as.integer(x_base), decreasing=TRUE)))
166167

167168
x = bit::clone(x_base)
168169
i = seq_along(x)
@@ -222,6 +223,7 @@ test_that("Specific sortorder/order variants for Quicksort coverage", {
222223
i = seq_along(x)
223224
bit::quicksortorder(x, i, decreasing=TRUE)
224225
expect_identical(x, as.integer64(sort(as.integer(x_base), decreasing=TRUE)))
226+
expect_identical(x_base[i], as.integer64(sort(as.integer(x_base), decreasing=TRUE)))
225227

226228
# quickorder descending (modifies i, not x)
227229
x = bit::clone(x_base)
@@ -243,6 +245,18 @@ test_that("Shellsort direct invocation", {
243245
i = seq_along(x)
244246
bit::shellorder(x, i, decreasing=FALSE)
245247
expect_identical(x[i], as.integer64(sort(as.integer(x_base))))
248+
249+
x = bit::clone(x_base)
250+
i = seq_along(x)
251+
bit::shellsortorder(x, i, decreasing=FALSE)
252+
expect_identical(x, as.integer64(sort(as.integer(x_base))))
253+
expect_identical(x_base[i], as.integer64(sort(as.integer(x_base))))
254+
255+
x = bit::clone(x_base)
256+
i = seq_along(x)
257+
bit::shellsortorder(x, i, decreasing=TRUE)
258+
expect_identical(x, as.integer64(sort(as.integer(x_base), decreasing=TRUE)))
259+
expect_identical(x_base[i], as.integer64(sort(as.integer(x_base), decreasing=TRUE)))
246260
})
247261

248262
test_that("Corner cases for partitioning logic", {

0 commit comments

Comments
 (0)