Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shellorder, shellsortorder tests, and tests of ties #158

Merged
merged 3 commits into from
Feb 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
233 changes: 158 additions & 75 deletions tests/testthat/test-sort64.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,26 @@ test_that("ramsort method for integer64 works", {

for (na.last in c(FALSE, TRUE)) {
for (decreasing in c(FALSE, TRUE)) {
for (n_missing in 0:2) {
na_entries = rep(NA_integer64_, n_missing)
y = sample(c(x, na_entries))
expect_identical(ramsort(y, decreasing=decreasing, na.last=na.last), n_missing)
# TODO(#154): Drop explicit 'else' branches
expected_value = c(
if (na.last) integer64() else na_entries,
if (decreasing) rev(x) else x,
if (na.last) na_entries else integer64()
)
expect_identical(y, expected_value,
info=sprintf(
"(na.last, decreasing, n_missing)=(%s, %s, %d)",
na.last, decreasing, n_missing
for (duplicates in c(FALSE, TRUE)) {
for (n_missing in 0:2) {
na_entries = rep(NA_integer64_, n_missing)
y = sample(c(x, if (duplicates) x[1L], na_entries))
expect_identical(ramsort(y, decreasing=decreasing, na.last=na.last), n_missing)
# TODO(#154): Drop explicit 'else' branches
expected_value = c(
if (na.last) integer64() else na_entries,
if (duplicates && !decreasing) x[1L],
if (decreasing) rev(x) else x,
if (duplicates && decreasing) x[1L],
if (na.last) na_entries else integer64()
)
)
expect_identical(y, expected_value,
info=sprintf(
"(na.last, decreasing, duplicates, n_missing)=(%s, %s, %s, %d)",
na.last, decreasing, duplicates, n_missing
)
)
}
}
}
}
Expand All @@ -62,22 +66,26 @@ test_that("shellsort method for integer64 works", {

for (na.last in c(FALSE, TRUE)) {
for (decreasing in c(FALSE, TRUE)) {
for (n_missing in 0:2) {
na_entries = rep(NA_integer64_, n_missing)
y = sample(c(x, na_entries))
expect_identical(shellsort(y, decreasing=decreasing, na.last=na.last), n_missing)
# TODO(#154): Drop explicit 'else' branches
expected_value = c(
if (na.last) integer64() else na_entries,
if (decreasing) rev(x) else x,
if (na.last) na_entries else integer64()
)
expect_identical(y, expected_value,
info=sprintf(
"(na.last, decreasing, n_missing)=(%s, %s, %d)",
na.last, decreasing, n_missing
for (duplicates in c(FALSE, TRUE)) {
for (n_missing in 0:2) {
na_entries = rep(NA_integer64_, n_missing)
y = sample(c(x, if (duplicates) x[1L], na_entries))
expect_identical(shellsort(y, decreasing=decreasing, na.last=na.last), n_missing)
# TODO(#154): Drop explicit 'else' branches
expected_value = c(
if (na.last) integer64() else na_entries,
if (duplicates && !decreasing) x[1L],
if (decreasing) rev(x) else x,
if (duplicates && decreasing) x[1L],
if (na.last) na_entries else integer64()
)
expect_identical(y, expected_value,
info=sprintf(
"(na.last, decreasing, duplicates, n_missing)=(%s, %s, %s, %d)",
na.last, decreasing, duplicates, n_missing
)
)
)
}
}
}
}
Expand All @@ -88,22 +96,26 @@ test_that("mergesort method for integer64 works", {

for (na.last in c(FALSE, TRUE)) {
for (decreasing in c(FALSE, TRUE)) {
for (n_missing in 0:2) {
na_entries = rep(NA_integer64_, n_missing)
y = sample(c(x, na_entries))
expect_identical(mergesort(y, decreasing=decreasing, na.last=na.last), n_missing)
# TODO(#154): Drop explicit 'else' branches
expected_value = c(
if (na.last) integer64() else na_entries,
if (decreasing) rev(x) else x,
if (na.last) na_entries else integer64()
)
expect_identical(y, expected_value,
info=sprintf(
"(na.last, decreasing, n_missing)=(%s, %s, %d)",
na.last, decreasing, n_missing
for (duplicates in c(FALSE, TRUE)) {
for (n_missing in 0:2) {
na_entries = rep(NA_integer64_, n_missing)
y = sample(c(x, if (duplicates) x[1L], na_entries))
expect_identical(mergesort(y, decreasing=decreasing, na.last=na.last), n_missing)
# TODO(#154): Drop explicit 'else' branches
expected_value = c(
if (na.last) integer64() else na_entries,
if (duplicates && !decreasing) x[1L],
if (decreasing) rev(x) else x,
if (duplicates && decreasing) x[1L],
if (na.last) na_entries else integer64()
)
expect_identical(y, expected_value,
info=sprintf(
"(na.last, decreasing, duplicates, n_missing)=(%s, %s, %s, %d)",
na.last, decreasing, duplicates, n_missing
)
)
)
}
}
}
}
Expand All @@ -114,22 +126,26 @@ test_that("radixsort method for integer64 works", {

for (na.last in c(FALSE, TRUE)) {
for (decreasing in c(FALSE, TRUE)) {
for (n_missing in 0:2) {
na_entries = rep(NA_integer64_, n_missing)
y = sample(c(x, na_entries))
expect_identical(radixsort(y, decreasing=decreasing, na.last=na.last), n_missing)
# TODO(#154): Drop explicit 'else' branches
expected_value = c(
if (na.last) integer64() else na_entries,
if (decreasing) rev(x) else x,
if (na.last) na_entries else integer64()
)
expect_identical(y, expected_value,
info=sprintf(
"(na.last, decreasing, n_missing)=(%s, %s, %d)",
na.last, decreasing, n_missing
for (duplicates in c(FALSE, TRUE)) {
for (n_missing in 0:2) {
na_entries = rep(NA_integer64_, n_missing)
y = sample(c(x, if (duplicates) x[1L], na_entries))
expect_identical(radixsort(y, decreasing=decreasing, na.last=na.last), n_missing)
# TODO(#154): Drop explicit 'else' branches
expected_value = c(
if (na.last) integer64() else na_entries,
if (duplicates && !decreasing) x[1L],
if (decreasing) rev(x) else x,
if (duplicates && decreasing) x[1L],
if (na.last) na_entries else integer64()
)
expect_identical(y, expected_value,
info=sprintf(
"(na.last, decreasing, duplicates, n_missing)=(%s, %s, %s, %d)",
na.last, decreasing, duplicates, n_missing
)
)
)
}
}
}
}
Expand All @@ -140,22 +156,89 @@ test_that("quicksort method for integer64 works", {

for (na.last in c(FALSE, TRUE)) {
for (decreasing in c(FALSE, TRUE)) {
for (n_missing in 0:2) {
na_entries = rep(NA_integer64_, n_missing)
y = sample(c(x, na_entries))
expect_identical(quicksort(y, decreasing=decreasing, na.last=na.last), n_missing)
# TODO(#154): Drop explicit 'else' branches
expected_value = c(
if (na.last) integer64() else na_entries,
if (decreasing) rev(x) else x,
if (na.last) na_entries else integer64()
)
expect_identical(y, expected_value,
info=sprintf(
"(na.last, decreasing, n_missing)=(%s, %s, %d)",
na.last, decreasing, n_missing
for (duplicates in c(FALSE, TRUE)) {
for (n_missing in 0:2) {
na_entries = rep(NA_integer64_, n_missing)
y = sample(c(x, if (duplicates) x[1L], na_entries))
expect_identical(quicksort(y, decreasing=decreasing, na.last=na.last), n_missing)
# TODO(#154): Drop explicit 'else' branches
expected_value = c(
if (na.last) integer64() else na_entries,
if (duplicates && !decreasing) x[1L],
if (decreasing) rev(x) else x,
if (duplicates && decreasing) x[1L],
if (na.last) na_entries else integer64()
)
expect_identical(y, expected_value,
info=sprintf(
"(na.last, decreasing, duplicates, n_missing)=(%s, %s, %s, %d)",
na.last, decreasing, duplicates, n_missing
)
)
}
}
}
}
})

test_that("shellorder method for integer64 works", {
x = as.integer64(1:10)

for (na.last in c(FALSE, TRUE)) {
for (decreasing in c(FALSE, TRUE)) {
for (duplicates in c(FALSE, TRUE)) {
for (n_missing in 0:2) {
na_entries = rep(NA_integer64_, n_missing)
y = sample(c(x, if (duplicates) x[1L], na_entries))
i = seq_along(y)
expect_identical(shellorder(y, i, decreasing=decreasing, na.last=na.last), n_missing)
# TODO(#154): Drop explicit 'else' branches
expected_value = c(
if (na.last) integer64() else na_entries,
if (duplicates && !decreasing) x[1L],
if (decreasing) rev(x) else x,
if (duplicates && decreasing) x[1L],
if (na.last) na_entries else integer64()
)
)
expect_identical(y[i], expected_value,
info=sprintf(
"(na.last, decreasing, duplicates, n_missing)=(%s, %s, %s, %d)",
na.last, decreasing, duplicates, n_missing
)
)
}
}
}
}
})

test_that("shellsortorder method for integer64 works", {
x = as.integer64(1:10)

for (na.last in c(FALSE, TRUE)) {
for (decreasing in c(FALSE, TRUE)) {
for (duplicates in c(FALSE, TRUE)) {
for (n_missing in 0:2) {
na_entries = rep(NA_integer64_, n_missing)
y = sample(c(x, if (duplicates) x[1L], na_entries))
i = seq_along(y)
expect_identical(shellsortorder(y, i, decreasing=decreasing, na.last=na.last), n_missing)
# TODO(#154): Drop explicit 'else' branches
expected_value = c(
if (na.last) integer64() else na_entries,
if (duplicates && !decreasing) x[1L],
if (decreasing) rev(x) else x,
if (duplicates && decreasing) x[1L],
if (na.last) na_entries else integer64()
)
# TODO(#159): Also add expectations for the update to i
expect_identical(y, expected_value,
info=sprintf(
"(na.last, decreasing, duplicates, n_missing)=(%s, %s, %s, %d)",
na.last, decreasing, duplicates, n_missing
)
)
}
}
}
}
Expand Down
Loading